use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.
the class OrganizationCreationImpl method insertOwnersGroup.
/**
* Owners group has an hard coded name, a description based on the organization's name and has all global permissions.
*/
private GroupDto insertOwnersGroup(DbSession dbSession, OrganizationDto organization) {
GroupDto group = dbClient.groupDao().insert(dbSession, new GroupDto().setOrganizationUuid(organization.getUuid()).setName(OWNERS_GROUP_NAME).setDescription(format(OWNERS_GROUP_DESCRIPTION_PATTERN, organization.getName())));
OrganizationPermission.all().forEach(p -> addPermissionToGroup(dbSession, group, p));
return group;
}
use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.
the class OrganizationCreationImpl method create.
@Override
public OrganizationDto create(DbSession dbSession, int creatorUserId, NewOrganization newOrganization) throws KeyConflictException {
validate(newOrganization);
String key = newOrganization.getKey();
if (organizationKeyIsUsed(dbSession, key)) {
throw new KeyConflictException(format("Organization key '%s' is already used", key));
}
OrganizationDto organization = insertOrganization(dbSession, newOrganization, dto -> {
});
GroupDto group = insertOwnersGroup(dbSession, organization);
insertDefaultTemplate(dbSession, organization, group);
addCurrentUserToGroup(dbSession, group, creatorUserId);
dbSession.commit();
return organization;
}
use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.
the class UserUpdater method addDefaultGroup.
private void addDefaultGroup(DbSession dbSession, UserDto userDto) {
String defaultGroupName = settings.getString(CoreProperties.CORE_DEFAULT_GROUP);
if (defaultGroupName == null) {
return;
}
String defOrgUuid = defaultOrganizationProvider.get().getUuid();
List<GroupDto> userGroups = dbClient.groupDao().selectByUserLogin(dbSession, userDto.getLogin());
if (!userGroups.stream().anyMatch(g -> defOrgUuid.equals(g.getOrganizationUuid()) && g.getName().equals(defaultGroupName))) {
Optional<GroupDto> groupDto = dbClient.groupDao().selectByName(dbSession, defOrgUuid, defaultGroupName);
if (!groupDto.isPresent()) {
throw new ServerException(HttpURLConnection.HTTP_INTERNAL_ERROR, format("The default group '%s' for new users does not exist. Please update the general security settings to fix this issue.", defaultGroupName));
}
dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setUserId(userDto.getId()).setGroupId(groupDto.get().getId()));
}
}
use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.
the class GroupWsSupport method findGroup.
/**
* Finds a user group by its reference. If organization is not defined then group
* is searched in default organization.
*
* @return non-null group
* @throws NotFoundException if the requested group does not exist
* @throws NotFoundException if the requested group is Anyone
*/
public GroupId findGroup(DbSession dbSession, GroupWsRef ref) {
if (ref.hasId()) {
GroupDto group = dbClient.groupDao().selectById(dbSession, ref.getId());
checkFound(group, "No group with id '%s'", ref.getId());
return GroupId.from(group);
}
OrganizationDto org = findOrganizationByKey(dbSession, ref.getOrganizationKey());
Optional<GroupDto> group = dbClient.groupDao().selectByName(dbSession, org.getUuid(), ref.getName());
checkFoundWithOptional(group, "No group with name '%s' in organization '%s'", ref.getName(), org.getKey());
return GroupId.from(group.get());
}
use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.
the class GroupWsSupport method findGroupOrAnyone.
public GroupIdOrAnyone findGroupOrAnyone(DbSession dbSession, GroupWsRef ref) {
if (ref.hasId()) {
GroupDto group = dbClient.groupDao().selectById(dbSession, ref.getId());
checkFound(group, "No group with id '%s'", ref.getId());
return GroupIdOrAnyone.from(group);
}
OrganizationDto org = findOrganizationByKey(dbSession, ref.getOrganizationKey());
if (ref.isAnyone()) {
return GroupIdOrAnyone.forAnyone(org.getUuid());
}
Optional<GroupDto> group = dbClient.groupDao().selectByName(dbSession, org.getUuid(), ref.getName());
checkFoundWithOptional(group, "No group with name '%s' in organization '%s'", ref.getName(), org.getKey());
return GroupIdOrAnyone.from(group.get());
}
Aggregations