use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class UpdateTemplateActionTest method update_with_the_same_values.
@Test
public void update_with_the_same_values() throws Exception {
loginAsAdmin(db.getDefaultOrganization());
call(template.getUuid(), template.getName(), template.getDescription(), template.getKeyPattern());
PermissionTemplateDto reloaded = db.getDbClient().permissionTemplateDao().selectByUuid(db.getSession(), template.getUuid());
assertThat(reloaded.getName()).isEqualTo(template.getName());
assertThat(reloaded.getDescription()).isEqualTo(template.getDescription());
assertThat(reloaded.getKeyPattern()).isEqualTo(template.getKeyPattern());
}
use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class UpdateTemplateActionTest method fail_if_name_already_exists_in_database_case_insensitive.
@Test
public void fail_if_name_already_exists_in_database_case_insensitive() throws Exception {
loginAsAdmin(db.getDefaultOrganization());
PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
String nameCaseInsensitive = anotherTemplate.getName().toUpperCase();
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("A template with the name '" + nameCaseInsensitive + "' already exists (case insensitive).");
call(this.template.getUuid(), nameCaseInsensitive, null, null);
}
use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class UpdateTemplateActionTest method update_name_only.
@Test
public void update_name_only() throws Exception {
loginAsAdmin(db.getDefaultOrganization());
call(template.getUuid(), "Finance", null, null);
PermissionTemplateDto finance = selectTemplateInDefaultOrganization("Finance");
assertThat(finance.getName()).isEqualTo("Finance");
assertThat(finance.getDescription()).isEqualTo(template.getDescription());
assertThat(finance.getKeyPattern()).isEqualTo(template.getKeyPattern());
}
use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class AddGroupToTemplateAction method handle.
@Override
public void handle(Request request, Response response) {
try (DbSession dbSession = dbClient.openSession(false)) {
String permission = request.mandatoryParam(PARAM_PERMISSION);
GroupIdOrAnyone groupId = support.findGroup(dbSession, request);
checkRequest(!SYSTEM_ADMIN.equals(permission) || !groupId.isAnyone(), format("It is not possible to add the '%s' permission to the group 'Anyone'.", permission));
PermissionTemplateDto template = support.findTemplate(dbSession, fromRequest(request));
checkGlobalAdmin(userSession, template.getOrganizationUuid());
if (!groupAlreadyAdded(dbSession, template.getId(), permission, groupId)) {
dbClient.permissionTemplateDao().insertGroupPermission(dbSession, template.getId(), groupId.getId(), permission);
dbSession.commit();
}
}
response.noContent();
}
use of org.sonar.db.permission.template.PermissionTemplateDto in project sonarqube by SonarSource.
the class RemoveProjectCreatorFromTemplateAction method doHandle.
private void doHandle(RemoveProjectCreatorFromTemplateWsRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
PermissionTemplateDto template = wsSupport.findTemplate(dbSession, WsTemplateRef.newTemplateRef(request.getTemplateId(), request.getOrganization(), request.getTemplateName()));
checkGlobalAdmin(userSession, template.getOrganizationUuid());
PermissionTemplateCharacteristicDao dao = dbClient.permissionTemplateCharacteristicDao();
dao.selectByPermissionAndTemplateId(dbSession, request.getPermission(), template.getId()).ifPresent(permissionTemplateCharacteristicDto -> updateTemplateCharacteristic(dbSession, permissionTemplateCharacteristicDto));
}
}
Aggregations