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();
}
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\"" + " }" + "}");
}
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();
}
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);
}
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();
}
Aggregations