Search in sources :

Example 66 with PermissionTemplateDto

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

the class DeleteTemplateActionTest method delete_template_by_name_case_insensitive.

@Test
public void delete_template_by_name_case_insensitive() throws Exception {
    runOnAllUnderTests((underTest) -> {
        OrganizationDto organization = db.organizations().insert();
        db.organizations().setDefaultTemplates(db.permissionTemplates().insertTemplate(organization), db.permissionTemplates().insertTemplate(organization));
        PermissionTemplateDto template = insertTemplateAndAssociatedPermissions(organization);
        loginAsAdmin(organization);
        newRequestByName(underTest, organization, template);
        assertTemplateDoesNotExist(template);
    });
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 67 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_no_organization_is_provided_and_templates_does_not_belong_to_default_organization.

@Test
public void delete_template_by_name_returns_empty_when_no_organization_is_provided_and_templates_does_not_belong_to_default_organization() throws Exception {
    OrganizationDto organization = db.organizations().insert();
    db.organizations().setDefaultTemplates(db.permissionTemplates().insertTemplate(organization), db.permissionTemplates().insertTemplate(organization));
    PermissionTemplateDto template = insertTemplateAndAssociatedPermissions(organization);
    loginAsAdmin(organization);
    runOnAllUnderTests((underTest) -> {
        try {
            newRequestByName(underTest, null, 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 '" + db.getDefaultOrganization().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 68 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_template_is_default_template_for_project.

private void fail_to_delete_by_name_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");
    newRequestByName(underTest, organization.getKey(), projectTemplate.getName());
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 69 with PermissionTemplateDto

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

the class DeleteTemplateActionTest method default_template_for_views_can_be_deleted_by_uuid_if_views_is_not_installed_and_default_template_for_views_is_reset.

@Test
public void default_template_for_views_can_be_deleted_by_uuid_if_views_is_not_installed_and_default_template_for_views_is_reset() throws Exception {
    OrganizationDto organization = db.organizations().insert();
    PermissionTemplateDto projectTemplate = db.permissionTemplates().insertTemplate(organization);
    PermissionTemplateDto viewTemplate = insertTemplateAndAssociatedPermissions(organization);
    db.organizations().setDefaultTemplates(projectTemplate, viewTemplate);
    loginAsAdmin(organization);
    newRequestByUuid(this.underTestWithoutViews, viewTemplate.getUuid());
    assertTemplateDoesNotExist(viewTemplate);
    assertThat(db.getDbClient().organizationDao().getDefaultTemplates(db.getSession(), organization.getUuid()).get().getViewUuid()).isNull();
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 70 with PermissionTemplateDto

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

the class DeleteTemplateActionTest method delete_template_in_db.

@Test
public void delete_template_in_db() throws Exception {
    runOnAllUnderTests((underTest) -> {
        OrganizationDto organization = db.organizations().insert();
        PermissionTemplateDto template = insertTemplateAndAssociatedPermissions(organization);
        db.organizations().setDefaultTemplates(db.permissionTemplates().insertTemplate(organization), db.permissionTemplates().insertTemplate(organization));
        loginAsAdmin(organization);
        TestResponse result = newRequestByUuid(underTest, template.getUuid());
        assertThat(result.getInput()).isEmpty();
        assertTemplateDoesNotExist(template);
    });
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) TestResponse(org.sonar.server.ws.TestResponse) 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