Search in sources :

Example 6 with PermissionTemplateCharacteristicDto

use of org.sonar.db.permission.template.PermissionTemplateCharacteristicDto in project sonarqube by SonarSource.

the class SearchTemplatesActionTest method addPermissionTemplateWithProjectCreator.

private void addPermissionTemplateWithProjectCreator(String templateUuid, String permission, String templateName) {
    dbClient.permissionTemplateCharacteristicDao().insert(dbSession, new PermissionTemplateCharacteristicDto().setUuid(Uuids.createFast()).setWithProjectCreator(true).setTemplateUuid(templateUuid).setPermission(permission).setCreatedAt(1_000_000_000L).setUpdatedAt(2_000_000_000L), templateName);
    db.commit();
}
Also used : PermissionTemplateCharacteristicDto(org.sonar.db.permission.template.PermissionTemplateCharacteristicDto)

Example 7 with PermissionTemplateCharacteristicDto

use of org.sonar.db.permission.template.PermissionTemplateCharacteristicDto in project sonarqube by SonarSource.

the class RemoveProjectCreatorFromTemplateAction method updateTemplateCharacteristic.

private void updateTemplateCharacteristic(DbSession dbSession, PermissionTemplateCharacteristicDto templatePermission) {
    PermissionTemplateCharacteristicDto targetTemplatePermission = templatePermission.setUpdatedAt(system.now()).setWithProjectCreator(false);
    dbClient.permissionTemplateCharacteristicDao().update(dbSession, targetTemplatePermission);
    dbSession.commit();
}
Also used : PermissionTemplateCharacteristicDto(org.sonar.db.permission.template.PermissionTemplateCharacteristicDto)

Example 8 with PermissionTemplateCharacteristicDto

use of org.sonar.db.permission.template.PermissionTemplateCharacteristicDto in project sonarqube by SonarSource.

the class AddProjectCreatorToTemplateAction method addTemplatePermission.

private void addTemplatePermission(DbSession dbSession, AddProjectCreatorToTemplateRequest request, PermissionTemplateDto template) {
    long now = system.now();
    dbClient.permissionTemplateCharacteristicDao().insert(dbSession, new PermissionTemplateCharacteristicDto().setUuid(Uuids.create()).setPermission(request.getPermission()).setTemplateUuid(template.getUuid()).setWithProjectCreator(true).setCreatedAt(now).setUpdatedAt(now), template.getName());
    dbSession.commit();
}
Also used : PermissionTemplateCharacteristicDto(org.sonar.db.permission.template.PermissionTemplateCharacteristicDto)

Example 9 with PermissionTemplateCharacteristicDto

use of org.sonar.db.permission.template.PermissionTemplateCharacteristicDto in project sonarqube by SonarSource.

the class AddProjectCreatorToTemplateAction method doHandle.

private void doHandle(AddProjectCreatorToTemplateRequest request) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        PermissionTemplateDto template = wsSupport.findTemplate(dbSession, WsTemplateRef.newTemplateRef(request.getTemplateId(), request.getTemplateName()));
        checkGlobalAdmin(userSession);
        Optional<PermissionTemplateCharacteristicDto> templatePermission = dbClient.permissionTemplateCharacteristicDao().selectByPermissionAndTemplateId(dbSession, request.getPermission(), template.getUuid());
        if (templatePermission.isPresent()) {
            updateTemplatePermission(dbSession, templatePermission.get(), template.getName());
        } else {
            addTemplatePermission(dbSession, request, template);
        }
    }
}
Also used : DbSession(org.sonar.db.DbSession) PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) PermissionTemplateCharacteristicDto(org.sonar.db.permission.template.PermissionTemplateCharacteristicDto)

Example 10 with PermissionTemplateCharacteristicDto

use of org.sonar.db.permission.template.PermissionTemplateCharacteristicDto in project sonarqube by SonarSource.

the class AddProjectCreatorToTemplateAction method updateTemplatePermission.

private void updateTemplatePermission(DbSession dbSession, PermissionTemplateCharacteristicDto templatePermission, String templateName) {
    PermissionTemplateCharacteristicDto targetTemplatePermission = templatePermission.setUpdatedAt(system.now()).setWithProjectCreator(true);
    dbClient.permissionTemplateCharacteristicDao().update(dbSession, targetTemplatePermission, templateName);
    dbSession.commit();
}
Also used : PermissionTemplateCharacteristicDto(org.sonar.db.permission.template.PermissionTemplateCharacteristicDto)

Aggregations

PermissionTemplateCharacteristicDto (org.sonar.db.permission.template.PermissionTemplateCharacteristicDto)12 DbSession (org.sonar.db.DbSession)4 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 String.format (java.lang.String.format)2 MessageFormat (java.text.MessageFormat)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections.singletonList (java.util.Collections.singletonList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Set (java.util.Set)2 CheckForNull (javax.annotation.CheckForNull)2 Nullable (javax.annotation.Nullable)2 StringUtils (org.apache.commons.lang.StringUtils)2 Test (org.junit.Test)2 Qualifiers (org.sonar.api.resources.Qualifiers)2 DefaultGroups.isAnyone (org.sonar.api.security.DefaultGroups.isAnyone)2 ServerSide (org.sonar.api.server.ServerSide)2 DbClient (org.sonar.db.DbClient)2