Search in sources :

Example 71 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class UserPermissionChangerTest method remove_admin_user_if_still_other_admins.

@Test
public void remove_admin_user_if_still_other_admins() {
    db.users().insertPermissionOnUser(org1, user1, ADMINISTER);
    GroupDto admins = db.users().insertGroup(org1, "admins");
    db.users().insertMember(admins, user2);
    db.users().insertPermissionOnGroup(admins, ADMINISTER);
    UserPermissionChange change = new UserPermissionChange(REMOVE, org1.getUuid(), ADMINISTER.getKey(), null, UserId.from(user1));
    underTest.apply(db.getSession(), change);
    assertThat(db.users().selectPermissionsOfUser(user1, org1)).isEmpty();
}
Also used : GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Example 72 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class AuthorizationTypeSupportTest method createQueryFilter_sets_filter_on_anyone_and_user_id_and_group_ids_if_user_is_logged_in_and_has_groups.

@Test
public void createQueryFilter_sets_filter_on_anyone_and_user_id_and_group_ids_if_user_is_logged_in_and_has_groups() {
    GroupDto group1 = GroupTesting.newGroupDto().setId(10);
    GroupDto group2 = GroupTesting.newGroupDto().setId(11);
    userSession.logIn().setUserId(1234).setGroups(group1, group2);
    HasParentQueryBuilder filter = (HasParentQueryBuilder) underTest.createQueryFilter();
    assertJson(filter.toString()).isSimilarTo("{" + "  \"has_parent\": {" + "    \"query\": {" + "      \"bool\": {" + "        \"filter\": {" + "          \"bool\": {" + "            \"should\": [" + "              {" + "                \"term\": {" + "                  \"allowAnyone\": true" + "                }" + "              }," + "              {" + "                \"term\": {" + "                  \"userIds\": 1234" + "                }" + "              }," + "              {" + "                \"term\": {" + "                  \"groupIds\": 10" + "                }" + "              }," + "              {" + "                \"term\": {" + "                  \"groupIds\": 11" + "                }" + "              }" + "            ]" + "          }" + "        }" + "      }" + "    }," + "    \"parent_type\": \"authorization\"" + "  }" + "}");
}
Also used : GroupDto(org.sonar.db.user.GroupDto) HasParentQueryBuilder(org.elasticsearch.index.query.HasParentQueryBuilder) Test(org.junit.Test)

Example 73 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class AddGroupActionTest method adding_project_permission_fails_if_not_administrator_of_project.

@Test
public void adding_project_permission_fails_if_not_administrator_of_project() throws Exception {
    GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
    ComponentDto project = db.components().insertProject();
    userSession.logIn();
    expectedException.expect(ForbiddenException.class);
    newRequest().setParam(PARAM_GROUP_NAME, group.getName()).setParam(PARAM_PERMISSION, PROVISIONING).setParam(PARAM_PROJECT_KEY, project.key()).execute();
}
Also used : GroupDto(org.sonar.db.user.GroupDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 74 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class AddGroupActionTest method add_permission_to_project_referenced_by_its_id.

@Test
public void add_permission_to_project_referenced_by_its_id() throws Exception {
    GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
    ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), A_PROJECT_UUID).setKey(A_PROJECT_KEY));
    loginAsAdmin(db.getDefaultOrganization());
    newRequest().setParam(PARAM_GROUP_NAME, group.getName()).setParam(PARAM_PROJECT_ID, A_PROJECT_UUID).setParam(PARAM_PERMISSION, SYSTEM_ADMIN).execute();
    assertThat(db.users().selectGroupPermissions(group, null)).isEmpty();
    assertThat(db.users().selectGroupPermissions(group, project)).containsOnly(SYSTEM_ADMIN);
}
Also used : GroupDto(org.sonar.db.user.GroupDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 75 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class AddGroupActionTest method fail_when_permission_is_missing.

@Test
public void fail_when_permission_is_missing() throws Exception {
    GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
    loginAsAdmin(db.getDefaultOrganization());
    expectedException.expect(IllegalArgumentException.class);
    newRequest().setParam(PARAM_GROUP_NAME, group.getName()).execute();
}
Also used : GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Aggregations

GroupDto (org.sonar.db.user.GroupDto)177 Test (org.junit.Test)158 OrganizationDto (org.sonar.db.organization.OrganizationDto)74 UserDto (org.sonar.db.user.UserDto)67 ComponentDto (org.sonar.db.component.ComponentDto)38 GroupTesting.newGroupDto (org.sonar.db.user.GroupTesting.newGroupDto)31 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)18 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)17 PermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateGroupDto)14 UserGroupDto (org.sonar.db.user.UserGroupDto)12 DbSession (org.sonar.db.DbSession)11 BasePermissionWsTest (org.sonar.server.permission.ws.BasePermissionWsTest)9 PermissionTemplateTesting.newPermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateGroupDto)8 WsGroupsResponse (org.sonarqube.ws.WsPermissions.WsGroupsResponse)7 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)3 System2 (org.sonar.api.utils.System2)3 DbClient (org.sonar.db.DbClient)3 PermissionTemplateTesting.newPermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto)3 Strings (com.google.common.base.Strings)2