Search in sources :

Example 36 with PermissionTemplateDto

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

the class SetDefaultTemplateActionTest method update_view_default_template.

@Test
public void update_view_default_template() throws Exception {
    OrganizationDto organization = db.organizations().insert();
    PermissionTemplateDto projectDefaultTemplate = db.permissionTemplates().insertTemplate(organization);
    db.organizations().setDefaultTemplates(projectDefaultTemplate, null);
    PermissionTemplateDto template = insertTemplate(organization);
    loginAsAdmin(organization);
    newRequest(template.getUuid(), VIEW);
    assertDefaultTemplates(organization, projectDefaultTemplate.getUuid(), template.getUuid());
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) BasePermissionWsTest(org.sonar.server.permission.ws.BasePermissionWsTest) Test(org.junit.Test)

Example 37 with PermissionTemplateDto

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

the class TemplateGroupsActionTest method search_with_text_query.

@Test
public void search_with_text_query() throws Exception {
    OrganizationDto defaultOrg = db.getDefaultOrganization();
    PermissionTemplateDto template = addTemplateToDefaultOrganization();
    GroupDto group1 = db.users().insertGroup(defaultOrg, "group-1-name");
    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), group1.getId()));
    GroupDto group2 = db.users().insertGroup(defaultOrg, "group-2-name");
    GroupDto group3 = db.users().insertGroup(defaultOrg, "group-3");
    commit();
    loginAsAdmin(db.getDefaultOrganization());
    InputStream output = newRequest().setMediaType(PROTOBUF).setParam(PARAM_TEMPLATE_NAME, template.getName()).setParam(TEXT_QUERY, "-nam").execute().getInputStream();
    WsGroupsResponse response = WsGroupsResponse.parseFrom(output);
    assertThat(response.getGroupsList()).extracting("name").containsExactly("group-1-name", "group-2-name");
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) InputStream(java.io.InputStream) PermissionTemplateTesting.newPermissionTemplateGroupDto(org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateGroupDto) PermissionTemplateGroupDto(org.sonar.db.permission.template.PermissionTemplateGroupDto) GroupDto(org.sonar.db.user.GroupDto) GroupTesting.newGroupDto(org.sonar.db.user.GroupTesting.newGroupDto) WsGroupsResponse(org.sonarqube.ws.WsPermissions.WsGroupsResponse) OrganizationDto(org.sonar.db.organization.OrganizationDto) BasePermissionWsTest(org.sonar.server.permission.ws.BasePermissionWsTest) Test(org.junit.Test)

Example 38 with PermissionTemplateDto

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

the class TemplateGroupsActionTest method fail_if_insufficient_privileges.

@Test
public void fail_if_insufficient_privileges() throws Exception {
    PermissionTemplateDto template1 = addTemplateToDefaultOrganization();
    userSession.logIn();
    expectedException.expect(ForbiddenException.class);
    newRequest().setParam(PARAM_PERMISSION, USER).setParam(PARAM_TEMPLATE_ID, template1.getUuid()).execute();
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) BasePermissionWsTest(org.sonar.server.permission.ws.BasePermissionWsTest) Test(org.junit.Test)

Example 39 with PermissionTemplateDto

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

the class TemplateGroupsActionTest method fail_if_not_logged_in.

@Test
public void fail_if_not_logged_in() throws Exception {
    PermissionTemplateDto template1 = addTemplateToDefaultOrganization();
    userSession.anonymous();
    expectedException.expect(UnauthorizedException.class);
    newRequest().setParam(PARAM_PERMISSION, USER).setParam(PARAM_TEMPLATE_ID, template1.getUuid()).execute();
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) BasePermissionWsTest(org.sonar.server.permission.ws.BasePermissionWsTest) Test(org.junit.Test)

Example 40 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_another_template.

@Test
public void fail_if_name_already_exists_in_another_template() throws Exception {
    loginAsAdmin(db.getDefaultOrganization());
    PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
    expectedException.expect(BadRequestException.class);
    expectedException.expectMessage("A template with the name '" + anotherTemplate.getName() + "' already exists (case insensitive).");
    call(this.template.getUuid(), anotherTemplate.getName(), 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)

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