Search in sources :

Example 6 with GroupIdOrAnyone

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();
}
Also used : DbSession(org.sonar.db.DbSession) PermissionChange(org.sonar.server.permission.PermissionChange) GroupPermissionChange(org.sonar.server.permission.GroupPermissionChange) ProjectId(org.sonar.server.permission.ProjectId) GroupIdOrAnyone(org.sonar.server.usergroups.ws.GroupIdOrAnyone) GroupPermissionChange(org.sonar.server.permission.GroupPermissionChange)

Example 7 with GroupIdOrAnyone

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();
}
Also used : DbSession(org.sonar.db.DbSession) PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) GroupIdOrAnyone(org.sonar.server.usergroups.ws.GroupIdOrAnyone)

Example 8 with GroupIdOrAnyone

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));
}
Also used : GroupIdOrAnyone(org.sonar.server.usergroups.ws.GroupIdOrAnyone) Test(org.junit.Test)

Example 9 with GroupIdOrAnyone

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());
}
Also used : GroupIdOrAnyone(org.sonar.server.usergroups.ws.GroupIdOrAnyone) Test(org.junit.Test)

Example 10 with GroupIdOrAnyone

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();
}
Also used : UserDto(org.sonar.db.user.UserDto) GroupIdOrAnyone(org.sonar.server.usergroups.ws.GroupIdOrAnyone) Test(org.junit.Test)

Aggregations

GroupIdOrAnyone (org.sonar.server.usergroups.ws.GroupIdOrAnyone)16 Test (org.junit.Test)12 DbSession (org.sonar.db.DbSession)4 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)2 GroupPermissionChange (org.sonar.server.permission.GroupPermissionChange)2 PermissionChange (org.sonar.server.permission.PermissionChange)2 ProjectId (org.sonar.server.permission.ProjectId)2 OrganizationDto (org.sonar.db.organization.OrganizationDto)1 UserDto (org.sonar.db.user.UserDto)1