Search in sources :

Example 1 with GroupIdOrAnyone

use of org.sonar.server.usergroups.ws.GroupIdOrAnyone in project sonarqube by SonarSource.

the class AddGroupAction 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.ADD, 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 2 with GroupIdOrAnyone

use of org.sonar.server.usergroups.ws.GroupIdOrAnyone in project sonarqube by SonarSource.

the class RemoveGroupFromTemplateAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        String permission = request.mandatoryParam(PARAM_PERMISSION);
        PermissionTemplateDto template = wsSupport.findTemplate(dbSession, WsTemplateRef.fromRequest(request));
        checkGlobalAdmin(userSession, template.getOrganizationUuid());
        GroupIdOrAnyone groupId = wsSupport.findGroup(dbSession, request);
        checkArgument(groupId.getOrganizationUuid().equals(template.getOrganizationUuid()), "Group and template are on different organizations");
        dbClient.permissionTemplateDao().deleteGroupPermission(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 3 with GroupIdOrAnyone

use of org.sonar.server.usergroups.ws.GroupIdOrAnyone in project sonarqube by SonarSource.

the class GroupPermissionChangerTest method do_not_fail_if_removing_a_permission_that_does_not_exist.

@Test
public void do_not_fail_if_removing_a_permission_that_does_not_exist() {
    GroupIdOrAnyone groupId = new GroupIdOrAnyone(group);
    apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.ISSUE_ADMIN, new ProjectId(project), groupId));
    assertThat(db.users().selectGroupPermissions(group, null)).isEmpty();
    assertThat(db.users().selectGroupPermissions(group, project)).isEmpty();
}
Also used : GroupIdOrAnyone(org.sonar.server.usergroups.ws.GroupIdOrAnyone) Test(org.junit.Test)

Example 4 with GroupIdOrAnyone

use of org.sonar.server.usergroups.ws.GroupIdOrAnyone in project sonarqube by SonarSource.

the class GroupPermissionChangerTest method add_permission_to_anyone.

@Test
public void add_permission_to_anyone() {
    OrganizationDto defaultOrganization = db.getDefaultOrganization();
    GroupIdOrAnyone groupId = new GroupIdOrAnyone(defaultOrganization.getUuid(), null);
    apply(new GroupPermissionChange(PermissionChange.Operation.ADD, GlobalPermissions.QUALITY_GATE_ADMIN, null, groupId));
    assertThat(db.users().selectGroupPermissions(group, null)).isEmpty();
    assertThat(db.users().selectAnyonePermissions(defaultOrganization, null)).containsOnly(GlobalPermissions.QUALITY_GATE_ADMIN);
}
Also used : GroupIdOrAnyone(org.sonar.server.usergroups.ws.GroupIdOrAnyone) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 5 with GroupIdOrAnyone

use of org.sonar.server.usergroups.ws.GroupIdOrAnyone in project sonarqube by SonarSource.

the class GroupPermissionChangerTest method add_permission_to_group.

@Test
public void add_permission_to_group() {
    GroupIdOrAnyone groupId = new GroupIdOrAnyone(group);
    apply(new GroupPermissionChange(PermissionChange.Operation.ADD, GlobalPermissions.QUALITY_GATE_ADMIN, null, groupId));
    assertThat(db.users().selectGroupPermissions(group, null)).containsOnly(GlobalPermissions.QUALITY_GATE_ADMIN);
}
Also used : 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