use of org.sonar.db.permission.GroupPermissionDto in project sonarqube by SonarSource.
the class UserDbTester method insertProjectPermissionOnGroup.
public GroupPermissionDto insertProjectPermissionOnGroup(GroupDto group, String permission, ComponentDto project) {
checkArgument(group.getOrganizationUuid().equals(project.getOrganizationUuid()), "Different organizations");
GroupPermissionDto dto = new GroupPermissionDto().setOrganizationUuid(group.getOrganizationUuid()).setGroupId(group.getId()).setRole(permission).setResourceId(project.getId());
db.getDbClient().groupPermissionDao().insert(db.getSession(), dto);
db.commit();
return dto;
}
use of org.sonar.db.permission.GroupPermissionDto in project sonarqube by SonarSource.
the class UserDbTester method insertPermissionOnGroup.
public GroupPermissionDto insertPermissionOnGroup(GroupDto group, String permission) {
GroupPermissionDto dto = new GroupPermissionDto().setOrganizationUuid(group.getOrganizationUuid()).setGroupId(group.getId()).setRole(permission);
db.getDbClient().groupPermissionDao().insert(db.getSession(), dto);
db.commit();
return dto;
}
use of org.sonar.db.permission.GroupPermissionDto in project sonarqube by SonarSource.
the class GroupPermissionChanger method addPermission.
private boolean addPermission(DbSession dbSession, GroupPermissionChange change) {
if (loadExistingPermissions(dbSession, change).contains(change.getPermission())) {
return false;
}
validateNotAnyoneAndAdminPermission(change.getPermission(), change.getGroupIdOrAnyone());
GroupPermissionDto addedDto = new GroupPermissionDto().setRole(change.getPermission()).setOrganizationUuid(change.getOrganizationUuid()).setGroupId(change.getGroupIdOrAnyone().getId()).setResourceId(change.getNullableProjectId());
dbClient.groupPermissionDao().insert(dbSession, addedDto);
return true;
}
use of org.sonar.db.permission.GroupPermissionDto 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.GroupPermissionDto in project sonarqube by SonarSource.
the class PermissionIndexerDaoTest method select_by_projects_with_high_number_of_projects.
@Test
public void select_by_projects_with_high_number_of_projects() throws Exception {
List<String> projects = new ArrayList<>();
for (int i = 0; i < 350; i++) {
ComponentDto project = ComponentTesting.newProjectDto(dbTester.getDefaultOrganization(), Integer.toString(i));
dbClient.componentDao().insert(dbSession, project);
projects.add(project.uuid());
GroupPermissionDto dto = new GroupPermissionDto().setOrganizationUuid(group.getOrganizationUuid()).setGroupId(group.getId()).setRole(USER).setResourceId(project.getId());
dbClient.groupPermissionDao().insert(dbSession, dto);
}
dbSession.commit();
Map<String, PermissionIndexerDao.Dto> dtos = underTest.selectByUuids(dbClient, dbSession, projects).stream().collect(Collectors.uniqueIndex(PermissionIndexerDao.Dto::getProjectUuid, Function.identity()));
assertThat(dtos).hasSize(350);
}
Aggregations