Search in sources :

Example 1 with UserMembershipDto

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

the class UsersAction method writeMembers.

private static void writeMembers(JsonWriter json, List<UserMembershipDto> users) {
    json.name("users").beginArray();
    for (UserMembershipDto user : users) {
        json.beginObject().prop(FIELD_LOGIN, user.getLogin()).prop(FIELD_NAME, user.getName()).prop(FIELD_SELECTED, user.getGroupId() != null).endObject();
    }
    json.endArray();
}
Also used : UserMembershipDto(org.sonar.db.user.UserMembershipDto)

Example 2 with UserMembershipDto

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

the class UsersAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    int pageSize = request.mandatoryParamAsInt(Param.PAGE_SIZE);
    int page = request.mandatoryParamAsInt(Param.PAGE);
    String queryString = request.param(Param.TEXT_QUERY);
    String selected = request.mandatoryParam(Param.SELECTED);
    try (DbSession dbSession = dbClient.openSession(false)) {
        GroupId group = support.findGroup(dbSession, request);
        userSession.checkPermission(OrganizationPermission.ADMINISTER, group.getOrganizationUuid());
        UserMembershipQuery query = UserMembershipQuery.builder().groupId(group.getId()).memberSearch(queryString).membership(getMembership(selected)).pageIndex(page).pageSize(pageSize).build();
        int total = dbClient.groupMembershipDao().countMembers(dbSession, query);
        Paging paging = forPageIndex(page).withPageSize(pageSize).andTotal(total);
        List<UserMembershipDto> users = dbClient.groupMembershipDao().selectMembers(dbSession, query, paging.offset(), paging.pageSize());
        JsonWriter json = response.newJsonWriter().beginObject();
        writeMembers(json, users);
        writePaging(json, paging);
        json.endObject().close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) Paging(org.sonar.api.utils.Paging) UserMembershipQuery(org.sonar.db.user.UserMembershipQuery) UserMembershipDto(org.sonar.db.user.UserMembershipDto) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 3 with UserMembershipDto

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

the class CreateActionTest method request_creates_owners_group_with_all_permissions_for_new_organization_and_add_current_user_to_it.

@Test
public void request_creates_owners_group_with_all_permissions_for_new_organization_and_add_current_user_to_it() {
    mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
    UserDto user = dbTester.users().insertUser();
    userSession.logIn(user).setSystemAdministrator();
    executeRequest("orgFoo");
    DbSession dbSession = dbTester.getSession();
    OrganizationDto organization = dbClient.organizationDao().selectByKey(dbSession, "orgfoo").get();
    Optional<GroupDto> groupDtoOptional = dbClient.groupDao().selectByName(dbSession, organization.getUuid(), "Owners");
    assertThat(groupDtoOptional).isNotEmpty();
    GroupDto groupDto = groupDtoOptional.get();
    assertThat(groupDto.getDescription()).isEqualTo("Owners of organization orgFoo");
    assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, groupDto.getOrganizationUuid(), groupDto.getId())).containsOnly(GlobalPermissions.ALL.toArray(new String[GlobalPermissions.ALL.size()]));
    List<UserMembershipDto> members = dbClient.groupMembershipDao().selectMembers(dbSession, UserMembershipQuery.builder().groupId(groupDto.getId()).membership(UserMembershipQuery.IN).build(), 0, Integer.MAX_VALUE);
    assertThat(members).extracting(UserMembershipDto::getLogin).containsOnly(user.getLogin());
}
Also used : DbSession(org.sonar.db.DbSession) UserDto(org.sonar.db.user.UserDto) PermissionTemplateGroupDto(org.sonar.db.permission.template.PermissionTemplateGroupDto) GroupDto(org.sonar.db.user.GroupDto) UserMembershipDto(org.sonar.db.user.UserMembershipDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 4 with UserMembershipDto

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

the class OrganizationCreationImplTest method verifyGroupOwners.

private void verifyGroupOwners(UserDto user, String organizationKey, String organizationName) {
    OrganizationDto organization = dbClient.organizationDao().selectByKey(dbSession, organizationKey).get();
    List<GroupDto> groups = dbClient.groupDao().selectByOrganizationUuid(dbSession, organization.getUuid());
    assertThat(groups).extracting(GroupDto::getName).containsOnly("Owners");
    GroupDto groupDto = groups.iterator().next();
    assertThat(groupDto.getDescription()).isEqualTo("Owners of organization " + organizationName);
    assertThat(dbClient.groupPermissionDao().selectGlobalPermissionsOfGroup(dbSession, groupDto.getOrganizationUuid(), groupDto.getId())).containsOnly(GlobalPermissions.ALL.toArray(new String[GlobalPermissions.ALL.size()]));
    List<UserMembershipDto> members = dbClient.groupMembershipDao().selectMembers(dbSession, UserMembershipQuery.builder().groupId(groupDto.getId()).membership(UserMembershipQuery.IN).build(), 0, Integer.MAX_VALUE);
    assertThat(members).extracting(UserMembershipDto::getLogin).containsOnly(user.getLogin());
}
Also used : PermissionTemplateGroupDto(org.sonar.db.permission.template.PermissionTemplateGroupDto) GroupDto(org.sonar.db.user.GroupDto) UserMembershipDto(org.sonar.db.user.UserMembershipDto) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Aggregations

UserMembershipDto (org.sonar.db.user.UserMembershipDto)4 DbSession (org.sonar.db.DbSession)2 OrganizationDto (org.sonar.db.organization.OrganizationDto)2 PermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateGroupDto)2 GroupDto (org.sonar.db.user.GroupDto)2 Test (org.junit.Test)1 Paging (org.sonar.api.utils.Paging)1 JsonWriter (org.sonar.api.utils.text.JsonWriter)1 UserDto (org.sonar.db.user.UserDto)1 UserMembershipQuery (org.sonar.db.user.UserMembershipQuery)1