use of org.sonar.server.usergroups.ws.GroupIdOrAnyone in project sonarqube by SonarSource.
the class RemoveGroupAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
GroupIdOrAnyone group = support.findGroup(dbSession, request);
Optional<ProjectId> projectId = support.findProjectId(dbSession, request);
checkProjectAdmin(userSession, group.getOrganizationUuid(), projectId);
PermissionChange change = new GroupPermissionChange(PermissionChange.Operation.REMOVE, request.mandatoryParam(PARAM_PERMISSION), projectId.orElse(null), group);
permissionUpdater.apply(dbSession, asList(change));
}
response.noContent();
}
use of org.sonar.server.usergroups.ws.GroupIdOrAnyone in project sonarqube by SonarSource.
the class AddGroupToTemplateAction method handle.
@Override
public void handle(Request request, Response response) {
try (DbSession dbSession = dbClient.openSession(false)) {
String permission = request.mandatoryParam(PARAM_PERMISSION);
GroupIdOrAnyone groupId = support.findGroup(dbSession, request);
checkRequest(!SYSTEM_ADMIN.equals(permission) || !groupId.isAnyone(), format("It is not possible to add the '%s' permission to the group 'Anyone'.", permission));
PermissionTemplateDto template = support.findTemplate(dbSession, fromRequest(request));
checkGlobalAdmin(userSession, template.getOrganizationUuid());
if (!groupAlreadyAdded(dbSession, template.getId(), permission, groupId)) {
dbClient.permissionTemplateDao().insertGroupPermission(dbSession, template.getId(), groupId.getId(), permission);
dbSession.commit();
}
}
response.noContent();
}
use of org.sonar.server.usergroups.ws.GroupIdOrAnyone in project sonarqube by SonarSource.
the class GroupPermissionChangerTest method fail_to_remove_admin_permission_if_no_more_admins.
@Test
public void fail_to_remove_admin_permission_if_no_more_admins() {
GroupIdOrAnyone groupId = new GroupIdOrAnyone(group);
db.users().insertPermissionOnGroup(group, ADMINISTER);
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Last group with permission 'admin'. Permission cannot be removed.");
underTest.apply(db.getSession(), new GroupPermissionChange(PermissionChange.Operation.REMOVE, ADMINISTER.getKey(), null, groupId));
}
use of org.sonar.server.usergroups.ws.GroupIdOrAnyone in project sonarqube by SonarSource.
the class GroupPermissionChangerTest method do_nothing_when_adding_permission_that_already_exists.
@Test
public void do_nothing_when_adding_permission_that_already_exists() {
GroupIdOrAnyone groupId = new GroupIdOrAnyone(group);
db.users().insertPermissionOnGroup(group, ADMINISTER_QUALITY_GATES);
apply(new GroupPermissionChange(PermissionChange.Operation.ADD, ADMINISTER_QUALITY_GATES.getKey(), null, groupId));
assertThat(db.users().selectGroupPermissions(group, null)).containsOnly(ADMINISTER_QUALITY_GATES.getKey());
}
use of org.sonar.server.usergroups.ws.GroupIdOrAnyone in project sonarqube by SonarSource.
the class GroupPermissionChangerTest method remove_admin_group_if_still_other_admins.
@Test
public void remove_admin_group_if_still_other_admins() {
GroupIdOrAnyone groupId = new GroupIdOrAnyone(group);
db.users().insertPermissionOnGroup(group, ADMINISTER);
UserDto admin = db.users().insertUser();
db.users().insertPermissionOnUser(org, admin, ADMINISTER);
apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, ADMINISTER.getKey(), null, groupId));
assertThat(db.users().selectGroupPermissions(group, null)).isEmpty();
}
Aggregations