Search in sources :

Example 61 with PermissionTemplateDto

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

the class DeleteTemplateActionTest method fail_to_delete_by_uuid_if_template_is_default_template_for_project.

private void fail_to_delete_by_uuid_if_template_is_default_template_for_project(WsActionTester underTest) throws Exception {
    OrganizationDto organization = db.organizations().insert();
    PermissionTemplateDto projectTemplate = insertTemplateAndAssociatedPermissions(organization);
    db.organizations().setDefaultTemplates(projectTemplate, db.permissionTemplates().insertTemplate(organization));
    loginAsAdmin(organization);
    expectedException.expect(BadRequestException.class);
    expectedException.expectMessage("It is not possible to delete the default permission template for projects");
    newRequestByUuid(underTest, projectTemplate.getUuid());
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 62 with PermissionTemplateDto

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

the class DeleteTemplateActionTest method fail_to_delete_by_name_if_not_admin_with_views.

@Test
public void fail_to_delete_by_name_if_not_admin_with_views() throws Exception {
    OrganizationDto organization = db.organizations().insert();
    PermissionTemplateDto template = db.permissionTemplates().insertTemplate(PermissionTemplateTesting.newPermissionTemplateDto().setOrganizationUuid(organization.getUuid()).setName("the name"));
    userSession.logIn();
    expectedException.expect(ForbiddenException.class);
    newRequestByName(underTestWithViews, organization, template);
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 63 with PermissionTemplateDto

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

the class DeleteTemplateActionTest method delete_template_by_name_returns_empty_when_wrong_organization_is_provided.

@Test
public void delete_template_by_name_returns_empty_when_wrong_organization_is_provided() throws Exception {
    OrganizationDto organization = db.organizations().insert();
    db.organizations().setDefaultTemplates(db.permissionTemplates().insertTemplate(organization), db.permissionTemplates().insertTemplate(organization));
    PermissionTemplateDto template = insertTemplateAndAssociatedPermissions(organization);
    OrganizationDto otherOrganization = db.organizations().insert();
    loginAsAdmin(organization);
    runOnAllUnderTests((underTest) -> {
        try {
            newRequestByName(underTest, otherOrganization, template);
            fail("NotFoundException should have been raised");
        } catch (NotFoundException e) {
            assertThat(e).hasMessage("Permission template with name '" + template.getName() + "' is not found (case insensitive) in organization with key '" + otherOrganization.getKey() + "'");
        }
    });
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) NotFoundException(org.sonar.server.exceptions.NotFoundException) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 64 with PermissionTemplateDto

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

the class DeleteTemplateActionTest method fail_to_delete_by_uuid_if_not_admin_with_views.

@Test
public void fail_to_delete_by_uuid_if_not_admin_with_views() throws Exception {
    OrganizationDto organization = db.organizations().insert();
    PermissionTemplateDto template = insertTemplateAndAssociatedPermissions(organization);
    userSession.logIn();
    expectedException.expect(ForbiddenException.class);
    newRequestByUuid(underTestWithViews, template.getUuid());
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 65 with PermissionTemplateDto

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

the class DeleteTemplateActionTest method fail_to_delete_by_uuid_if_not_admin_without_views.

@Test
public void fail_to_delete_by_uuid_if_not_admin_without_views() throws Exception {
    OrganizationDto organization = db.organizations().insert();
    PermissionTemplateDto template = insertTemplateAndAssociatedPermissions(organization);
    userSession.logIn();
    expectedException.expect(ForbiddenException.class);
    newRequestByUuid(underTestWithoutViews, template.getUuid());
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

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