use of org.sonar.db.permission.UserPermissionDto in project sonarqube by SonarSource.
the class PermissionTemplateService method copyPermissions.
private void copyPermissions(DbSession dbSession, PermissionTemplateDto template, ComponentDto project, @Nullable Integer projectCreatorUserId) {
dbClient.resourceDao().updateAuthorizationDate(project.getId(), dbSession);
dbClient.groupPermissionDao().deleteByRootComponentId(dbSession, project.getId());
dbClient.userPermissionDao().deleteProjectPermissions(dbSession, project.getId());
List<PermissionTemplateUserDto> usersPermissions = dbClient.permissionTemplateDao().selectUserPermissionsByTemplateId(dbSession, template.getId());
String organizationUuid = template.getOrganizationUuid();
usersPermissions.forEach(up -> {
UserPermissionDto dto = new UserPermissionDto(organizationUuid, up.getPermission(), up.getUserId(), project.getId());
dbClient.userPermissionDao().insert(dbSession, dto);
});
List<PermissionTemplateGroupDto> groupsPermissions = dbClient.permissionTemplateDao().selectGroupPermissionsByTemplateId(dbSession, template.getId());
groupsPermissions.forEach(gp -> {
GroupPermissionDto dto = new GroupPermissionDto().setOrganizationUuid(organizationUuid).setGroupId(isAnyone(gp.getGroupName()) ? null : gp.getGroupId()).setRole(gp.getPermission()).setResourceId(project.getId());
dbClient.groupPermissionDao().insert(dbSession, dto);
});
List<PermissionTemplateCharacteristicDto> characteristics = dbClient.permissionTemplateCharacteristicDao().selectByTemplateIds(dbSession, asList(template.getId()));
if (projectCreatorUserId != null) {
Set<String> permissionsForCurrentUserAlreadyInDb = usersPermissions.stream().filter(userPermission -> projectCreatorUserId.equals(userPermission.getUserId())).map(PermissionTemplateUserDto::getPermission).collect(java.util.stream.Collectors.toSet());
characteristics.stream().filter(PermissionTemplateCharacteristicDto::getWithProjectCreator).filter(characteristic -> !permissionsForCurrentUserAlreadyInDb.contains(characteristic.getPermission())).forEach(c -> {
UserPermissionDto dto = new UserPermissionDto(organizationUuid, c.getPermission(), projectCreatorUserId, project.getId());
dbClient.userPermissionDao().insert(dbSession, dto);
});
}
}
use of org.sonar.db.permission.UserPermissionDto in project sonarqube by SonarSource.
the class UserPermissionChanger method addPermission.
private boolean addPermission(DbSession dbSession, UserPermissionChange change) {
if (loadExistingPermissions(dbSession, change).contains(change.getPermission())) {
return false;
}
UserPermissionDto dto = new UserPermissionDto(change.getOrganizationUuid(), change.getPermission(), change.getUserId().getId(), change.getNullableProjectId());
dbClient.userPermissionDao().insert(dbSession, dto);
return true;
}
use of org.sonar.db.permission.UserPermissionDto in project sonarqube by SonarSource.
the class UsersAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto org = support.findOrganization(dbSession, request.param(PARAM_ORGANIZATION));
Optional<ProjectId> projectId = support.findProjectId(dbSession, request);
checkProjectAdmin(userSession, org.getUuid(), projectId);
PermissionQuery query = buildPermissionQuery(request, projectId);
List<UserDto> users = findUsers(dbSession, org, query);
int total = dbClient.userPermissionDao().countUsers(dbSession, org.getUuid(), query);
List<UserPermissionDto> userPermissions = findUserPermissions(dbSession, org, users, projectId);
Paging paging = Paging.forPageIndex(request.mandatoryParamAsInt(Param.PAGE)).withPageSize(query.getPageSize()).andTotal(total);
UsersWsResponse usersWsResponse = buildResponse(users, userPermissions, paging);
writeProtobuf(usersWsResponse, request, response);
}
}
use of org.sonar.db.permission.UserPermissionDto in project sonarqube by SonarSource.
the class SearchActionTest method return_only_users_favorite.
@Test
public void return_only_users_favorite() {
OrganizationDto organizationDto = db.organizations().insert();
addComponent(newProjectDto(organizationDto).setKey("K1"));
ComponentDto otherUserFavorite = newProjectDto(organizationDto).setKey("K42");
db.components().insertComponent(otherUserFavorite);
db.favorites().add(otherUserFavorite, 42);
dbClient.userPermissionDao().insert(dbSession, new UserPermissionDto(organizationDto.getUuid(), UserRole.USER, 42, otherUserFavorite.getId()));
db.commit();
SearchResponse result = call();
assertThat(result.getFavoritesList()).extracting(Favorite::getKey).containsExactly("K1");
}
use of org.sonar.db.permission.UserPermissionDto in project sonarqube by SonarSource.
the class SearchActionTest method addComponent.
private void addComponent(ComponentDto component) {
db.components().insertComponent(component);
db.favorites().add(component, USER_ID);
dbClient.userPermissionDao().insert(dbSession, new UserPermissionDto(component.getOrganizationUuid(), UserRole.USER, USER_ID, component.getId()));
db.commit();
}
Aggregations