Search in sources :

Example 1 with GroupPermissionDto

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;
}
Also used : GroupPermissionDto(org.sonar.db.permission.GroupPermissionDto)

Example 2 with GroupPermissionDto

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;
}
Also used : GroupPermissionDto(org.sonar.db.permission.GroupPermissionDto)

Example 3 with GroupPermissionDto

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;
}
Also used : GroupPermissionDto(org.sonar.db.permission.GroupPermissionDto)

Example 4 with GroupPermissionDto

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);
        });
    }
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) StringUtils(org.apache.commons.lang.StringUtils) OrganizationPermission(org.sonar.db.permission.OrganizationPermission) DbSession(org.sonar.db.DbSession) GroupPermissionDto(org.sonar.db.permission.GroupPermissionDto) PermissionTemplateGroupDto(org.sonar.db.permission.template.PermissionTemplateGroupDto) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) DefaultTemplatesResolverImpl(org.sonar.server.permission.ws.template.DefaultTemplatesResolverImpl) PermissionTemplateUserDto(org.sonar.db.permission.template.PermissionTemplateUserDto) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Arrays.asList(java.util.Arrays.asList) DefaultTemplatesResolver(org.sonar.server.permission.ws.template.DefaultTemplatesResolver) Nullable(javax.annotation.Nullable) PermissionIndexer(org.sonar.server.permission.index.PermissionIndexer) Iterator(java.util.Iterator) Collection(java.util.Collection) DefaultTemplates(org.sonar.db.organization.DefaultTemplates) Set(java.util.Set) Collectors(org.sonar.core.util.stream.Collectors) String.format(java.lang.String.format) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Qualifiers(org.sonar.api.resources.Qualifiers) PermissionTemplateCharacteristicDto(org.sonar.db.permission.template.PermissionTemplateCharacteristicDto) DefaultGroups.isAnyone(org.sonar.api.security.DefaultGroups.isAnyone) ServerSide(org.sonar.api.server.ServerSide) UserSession(org.sonar.server.user.UserSession) CheckForNull(javax.annotation.CheckForNull) UserPermissionDto(org.sonar.db.permission.UserPermissionDto) ComponentKeys(org.sonar.core.component.ComponentKeys) PermissionTemplateUserDto(org.sonar.db.permission.template.PermissionTemplateUserDto) PermissionTemplateCharacteristicDto(org.sonar.db.permission.template.PermissionTemplateCharacteristicDto) UserPermissionDto(org.sonar.db.permission.UserPermissionDto) PermissionTemplateGroupDto(org.sonar.db.permission.template.PermissionTemplateGroupDto) GroupPermissionDto(org.sonar.db.permission.GroupPermissionDto)

Example 5 with GroupPermissionDto

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);
}
Also used : ArrayList(java.util.ArrayList) ComponentDto(org.sonar.db.component.ComponentDto) GroupPermissionDto(org.sonar.db.permission.GroupPermissionDto) UserDto(org.sonar.db.user.UserDto) GroupPermissionDto(org.sonar.db.permission.GroupPermissionDto) GroupDto(org.sonar.db.user.GroupDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Aggregations

GroupPermissionDto (org.sonar.db.permission.GroupPermissionDto)8 ArrayList (java.util.ArrayList)2 DbSession (org.sonar.db.DbSession)2 ComponentDto (org.sonar.db.component.ComponentDto)2 GroupDto (org.sonar.db.user.GroupDto)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 String.format (java.lang.String.format)1 MessageFormat (java.text.MessageFormat)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 Collections.singletonList (java.util.Collections.singletonList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Set (java.util.Set)1 CheckForNull (javax.annotation.CheckForNull)1 Nullable (javax.annotation.Nullable)1 StringUtils (org.apache.commons.lang.StringUtils)1 Test (org.junit.Test)1 Qualifiers (org.sonar.api.resources.Qualifiers)1 DefaultGroups.isAnyone (org.sonar.api.security.DefaultGroups.isAnyone)1