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 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 UserIdentityAuthenticatorTest method authenticate_new_user_with_groups.
@Test
public void authenticate_new_user_with_groups() throws Exception {
GroupDto group1 = db.users().insertGroup(db.getDefaultOrganization(), "group1");
GroupDto group2 = db.users().insertGroup(db.getDefaultOrganization(), "group2");
authenticate(USER_LOGIN, "group1", "group2", "group3");
Optional<UserDto> user = db.users().selectUserByLogin(USER_LOGIN);
assertThat(user).isPresent();
assertThat(user.get().isRoot()).isFalse();
assertThat(db.users().selectGroupIdsOfUser(user.get())).containsOnly(group1.getId(), group2.getId());
}
use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.
the class UserIdentityAuthenticatorTest method authenticate_existing_user_and_remove_groups.
@Test
public void authenticate_existing_user_and_remove_groups() throws Exception {
UserDto user = db.users().insertUser(newUserDto().setLogin(USER_LOGIN).setActive(true).setName("John"));
GroupDto group1 = db.users().insertGroup(db.getDefaultOrganization(), "group1");
GroupDto group2 = db.users().insertGroup(db.getDefaultOrganization(), "group2");
db.users().insertMember(group1, user);
db.users().insertMember(group2, user);
authenticate(USER_LOGIN, "group1");
assertThat(db.users().selectGroupIdsOfUser(user)).containsOnly(group1.getId());
}
use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.
the class UserIdentityAuthenticatorTest method authenticate_existing_user_and_remove_all_groups.
@Test
public void authenticate_existing_user_and_remove_all_groups() throws Exception {
UserDto user = db.users().insertUser();
GroupDto group1 = db.users().insertGroup(db.getDefaultOrganization(), "group1");
GroupDto group2 = db.users().insertGroup(db.getDefaultOrganization(), "group2");
db.users().insertMember(group1, user);
db.users().insertMember(group2, user);
authenticate(user.getLogin());
assertThat(db.users().selectGroupIdsOfUser(user)).isEmpty();
}
Aggregations