Search in sources :

Example 91 with GroupDto

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

the class SearchMyProjectsActionTest method admin_via_groups.

@Test
public void admin_via_groups() {
    OrganizationDto org = db.organizations().insert();
    ComponentDto jdk7 = insertJdk7(org);
    ComponentDto cLang = insertClang(org);
    GroupDto group = db.users().insertGroup(org);
    db.users().insertMember(group, user);
    db.users().insertProjectPermissionOnGroup(group, UserRole.ADMIN, jdk7);
    db.users().insertProjectPermissionOnGroup(group, UserRole.USER, cLang);
    SearchMyProjectsWsResponse result = call_ws();
    assertThat(result.getProjectsCount()).isEqualTo(1);
    assertThat(result.getProjects(0).getId()).isEqualTo(jdk7.uuid());
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) GroupDto(org.sonar.db.user.GroupDto) SearchMyProjectsWsResponse(org.sonarqube.ws.WsProjects.SearchMyProjectsWsResponse) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 92 with GroupDto

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

the class TemplateGroupsAction method findGroups.

private List<GroupDto> findGroups(DbSession dbSession, PermissionQuery dbQuery, PermissionTemplateDto template) {
    List<String> orderedNames = dbClient.permissionTemplateDao().selectGroupNamesByQueryAndTemplate(dbSession, dbQuery, template.getOrganizationUuid(), template.getId());
    List<GroupDto> groups = dbClient.groupDao().selectByNames(dbSession, template.getOrganizationUuid(), orderedNames);
    if (orderedNames.contains(DefaultGroups.ANYONE)) {
        groups.add(0, new GroupDto().setId(0).setName(DefaultGroups.ANYONE));
    }
    return Ordering.explicit(orderedNames).onResultOf(GroupDto::getName).immutableSortedCopy(groups);
}
Also used : PermissionTemplateGroupDto(org.sonar.db.permission.template.PermissionTemplateGroupDto) GroupDto(org.sonar.db.user.GroupDto)

Example 93 with GroupDto

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

the class TemplateGroupsAction method handle.

@Override
public void handle(Request wsRequest, Response wsResponse) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        WsTemplateRef templateRef = WsTemplateRef.fromRequest(wsRequest);
        PermissionTemplateDto template = support.findTemplate(dbSession, templateRef);
        checkGlobalAdmin(userSession, template.getOrganizationUuid());
        PermissionQuery query = buildPermissionQuery(wsRequest);
        int total = dbClient.permissionTemplateDao().countGroupNamesByQueryAndTemplate(dbSession, query, template.getOrganizationUuid(), template.getId());
        Paging paging = Paging.forPageIndex(wsRequest.mandatoryParamAsInt(PAGE)).withPageSize(wsRequest.mandatoryParamAsInt(PAGE_SIZE)).andTotal(total);
        List<GroupDto> groups = findGroups(dbSession, query, template);
        List<PermissionTemplateGroupDto> groupPermissions = findGroupPermissions(dbSession, groups, template);
        WsPermissions.WsGroupsResponse groupsResponse = buildResponse(groups, groupPermissions, paging);
        writeProtobuf(groupsResponse, wsRequest, wsResponse);
    }
}
Also used : DbSession(org.sonar.db.DbSession) PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) Paging(org.sonar.api.utils.Paging) PermissionTemplateGroupDto(org.sonar.db.permission.template.PermissionTemplateGroupDto) GroupDto(org.sonar.db.user.GroupDto) WsPermissions(org.sonarqube.ws.WsPermissions) PermissionTemplateGroupDto(org.sonar.db.permission.template.PermissionTemplateGroupDto) PermissionQuery(org.sonar.db.permission.PermissionQuery)

Example 94 with GroupDto

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

the class SearchAction method writeGroups.

private static void writeGroups(JsonWriter json, List<GroupDto> groups, Map<String, Integer> userCountByGroup, Set<String> fields) {
    json.name("groups").beginArray();
    for (GroupDto group : groups) {
        writeGroup(json, group, userCountByGroup.get(group.getName()), fields);
    }
    json.endArray();
}
Also used : GroupDto(org.sonar.db.user.GroupDto)

Example 95 with GroupDto

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

the class UserIdentityAuthenticatorTest method authenticate_existing_user_and_add_new_groups.

@Test
public void authenticate_existing_user_and_add_new_groups() throws Exception {
    UserDto user = db.users().insertUser(newUserDto().setLogin(USER_LOGIN).setActive(true).setName("John"));
    GroupDto group1 = db.users().insertGroup(db.getDefaultOrganization(), "group1");
    GroupDto group2 = db.users().insertGroup(db.getDefaultOrganization(), "group2");
    authenticate(USER_LOGIN, "group1", "group2", "group3");
    assertThat(db.users().selectGroupIdsOfUser(user)).containsOnly(group1.getId(), group2.getId());
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) 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