Search in sources :

Example 41 with PermissionTemplateDto

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());
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) PermissionTemplateTesting.newPermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto) BasePermissionWsTest(org.sonar.server.permission.ws.BasePermissionWsTest) Test(org.junit.Test)

Example 42 with PermissionTemplateDto

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);
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) PermissionTemplateTesting.newPermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto) BasePermissionWsTest(org.sonar.server.permission.ws.BasePermissionWsTest) Test(org.junit.Test)

Example 43 with PermissionTemplateDto

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());
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) PermissionTemplateTesting.newPermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto) BasePermissionWsTest(org.sonar.server.permission.ws.BasePermissionWsTest) Test(org.junit.Test)

Example 44 with PermissionTemplateDto

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();
}
Also used : DbSession(org.sonar.db.DbSession) PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) GroupIdOrAnyone(org.sonar.server.usergroups.ws.GroupIdOrAnyone)

Example 45 with PermissionTemplateDto

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

Aggregations

PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)97 Test (org.junit.Test)63 BasePermissionWsTest (org.sonar.server.permission.ws.BasePermissionWsTest)42 OrganizationDto (org.sonar.db.organization.OrganizationDto)33 GroupDto (org.sonar.db.user.GroupDto)17 DbSession (org.sonar.db.DbSession)16 UserDto (org.sonar.db.user.UserDto)15 PermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateGroupDto)14 InputStream (java.io.InputStream)13 PermissionTemplateTesting.newPermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto)12 DefaultTemplates (org.sonar.db.organization.DefaultTemplates)10 PermissionTemplateUserDto (org.sonar.db.permission.template.PermissionTemplateUserDto)9 WsPermissions (org.sonarqube.ws.WsPermissions)9 PermissionTemplateTesting.newPermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateGroupDto)8 GroupTesting.newGroupDto (org.sonar.db.user.GroupTesting.newGroupDto)8 PermissionTemplateTesting.newPermissionTemplateUserDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateUserDto)7 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)7 WsGroupsResponse (org.sonarqube.ws.WsPermissions.WsGroupsResponse)7 ComponentDto (org.sonar.db.component.ComponentDto)6 Date (java.util.Date)5