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