Search in sources :

Example 6 with GroupDto

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

the class RemoveUserActionTest method remove_user_by_group_name_in_specific_organization.

@Test
public void remove_user_by_group_name_in_specific_organization() throws Exception {
    OrganizationDto org = db.organizations().insert();
    GroupDto group = db.users().insertGroup(org, "a_group");
    UserDto user = db.users().insertUser("a_user");
    db.users().insertMember(group, user);
    // keep an administrator
    db.users().insertAdminByUserPermission(org);
    loginAsAdmin(org);
    newRequest().setParam(PARAM_ORGANIZATION_KEY, org.getKey()).setParam(PARAM_GROUP_NAME, group.getName()).setParam(PARAM_LOGIN, user.getLogin()).execute().assertNoContent();
    assertThat(db.users().selectGroupIdsOfUser(user)).isEmpty();
}
Also used : UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 7 with GroupDto

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

the class RemoveUserActionTest method remove_user_by_group_name_in_default_organization.

@Test
public void remove_user_by_group_name_in_default_organization() throws Exception {
    insertAnAdministratorInDefaultOrganization();
    GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "a_group");
    UserDto user = db.users().insertUser("a_user");
    db.users().insertMember(group, user);
    loginAsAdminOnDefaultOrganization();
    newRequest().setParam(PARAM_GROUP_NAME, group.getName()).setParam(PARAM_LOGIN, user.getLogin()).execute().assertNoContent();
    assertThat(db.users().selectGroupIdsOfUser(user)).isEmpty();
}
Also used : UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Example 8 with GroupDto

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

the class RemoveUserActionTest method throw_ForbiddenException_if_not_administrator_of_organization.

@Test
public void throw_ForbiddenException_if_not_administrator_of_organization() throws Exception {
    OrganizationDto org = db.organizations().insert();
    GroupDto group = db.users().insertGroup(org, "a-group");
    UserDto user = db.users().insertUser();
    db.users().insertMember(group, user);
    loginAsAdminOnDefaultOrganization();
    expectedException.expect(ForbiddenException.class);
    expectedException.expectMessage("Insufficient privileges");
    newRequest().setParam("id", group.getId().toString()).setParam("login", user.getLogin()).execute();
}
Also used : UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 9 with GroupDto

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

the class SearchActionTest method search_in_organization.

@Test
public void search_in_organization() throws Exception {
    OrganizationDto org = db.organizations().insert();
    GroupDto group = db.users().insertGroup(org, "users");
    // the group in default org is not returned
    db.users().insertGroup(db.getDefaultOrganization(), "users");
    loginAsDefaultOrgAdmin();
    userSession.addPermission(ADMINISTER, org);
    newRequest().setParam("organization", org.getKey()).execute().assertJson("{\"total\":1,\"p\":1,\"ps\":100," + "\"groups\":[{\"id\":\"" + group.getId() + "\",\"name\":\"users\"}]}\n");
}
Also used : GroupDto(org.sonar.db.user.GroupDto) GroupTesting.newGroupDto(org.sonar.db.user.GroupTesting.newGroupDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 10 with GroupDto

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

the class SearchActionTest method insertGroup.

private void insertGroup(OrganizationDto org, String name, int numberOfMembers) {
    GroupDto group = newGroupDto().setName(name).setDescription(capitalize(name)).setOrganizationUuid(org.getUuid());
    db.users().insertGroup(group);
    for (int i = 0; i < numberOfMembers; i++) {
        UserDto user = db.users().insertUser();
        db.users().insertMember(group, user);
    }
}
Also used : UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) GroupTesting.newGroupDto(org.sonar.db.user.GroupTesting.newGroupDto)

Aggregations

GroupDto (org.sonar.db.user.GroupDto)424 Test (org.junit.Test)387 UserDto (org.sonar.db.user.UserDto)148 ComponentDto (org.sonar.db.component.ComponentDto)127 GroupTesting.newGroupDto (org.sonar.db.user.GroupTesting.newGroupDto)70 OrganizationDto (org.sonar.db.organization.OrganizationDto)42 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)36 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)34 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)31 QualityGateDto (org.sonar.db.qualitygate.QualityGateDto)28 DbSession (org.sonar.db.DbSession)20 PermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateGroupDto)17 NotFoundException (org.sonar.server.exceptions.NotFoundException)14 PermissionTemplateTesting.newPermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto)13 UserGroupDto (org.sonar.db.user.UserGroupDto)12 BasePermissionWsTest (org.sonar.server.permission.ws.BasePermissionWsTest)12 TestResponse (org.sonar.server.ws.TestResponse)11 Qualitygates (org.sonarqube.ws.Qualitygates)10 PermissionTemplateTesting.newPermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateGroupDto)9 SearchGroupsResponse (org.sonarqube.ws.Qualityprofiles.SearchGroupsResponse)9