Search in sources :

Example 76 with PermissionTemplateDto

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

the class SetDefaultTemplateActionTest method fail_if_anonymous.

@Test
public void fail_if_anonymous() throws Exception {
    OrganizationDto organization = db.organizations().insert();
    PermissionTemplateDto template = insertTemplate(organization);
    userSession.anonymous();
    expectedException.expect(UnauthorizedException.class);
    newRequest(template.getUuid(), PROJECT);
}
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 77 with PermissionTemplateDto

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

the class SetDefaultTemplateActionTest method fail_if_not_admin.

@Test
public void fail_if_not_admin() throws Exception {
    OrganizationDto organization = db.organizations().insert();
    PermissionTemplateDto template = insertTemplate(organization);
    userSession.logIn();
    expectedException.expect(ForbiddenException.class);
    newRequest(template.getUuid(), null);
}
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 78 with PermissionTemplateDto

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

the class SetDefaultTemplateActionTest method update_project_default_template_by_template_name.

@Test
public void update_project_default_template_by_template_name() throws Exception {
    OrganizationDto organization = db.organizations().insert();
    PermissionTemplateDto viewDefaultTemplate = db.permissionTemplates().insertTemplate(organization);
    db.organizations().setDefaultTemplates(db.permissionTemplates().insertTemplate(organization), viewDefaultTemplate);
    PermissionTemplateDto template = insertTemplate(organization);
    loginAsAdmin(organization);
    newRequest().setParam(PARAM_ORGANIZATION, organization.getKey()).setParam(PARAM_TEMPLATE_NAME, template.getName().toUpperCase()).execute();
    db.getSession().commit();
    assertDefaultTemplates(organization, template.getUuid(), viewDefaultTemplate.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 79 with PermissionTemplateDto

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

the class SetDefaultTemplateActionTest method update_project_default_template.

@Test
public void update_project_default_template() throws Exception {
    PermissionTemplateDto viewDefaultTemplate = db.permissionTemplates().insertTemplate(db.getDefaultOrganization());
    db.organizations().setDefaultTemplates(db.permissionTemplates().insertTemplate(db.getDefaultOrganization()), viewDefaultTemplate);
    PermissionTemplateDto template = insertTemplate(db.getDefaultOrganization());
    loginAsAdmin(db.getDefaultOrganization());
    newRequest(template.getUuid(), Qualifiers.PROJECT);
    assertDefaultTemplates(db.getDefaultOrganization(), template.getUuid(), viewDefaultTemplate.getUuid());
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) BasePermissionWsTest(org.sonar.server.permission.ws.BasePermissionWsTest) Test(org.junit.Test)

Example 80 with PermissionTemplateDto

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

the class TemplateGroupsActionTest method search_with_text_query_return_anyone_group_even_when_no_permission_set.

@Test
public void search_with_text_query_return_anyone_group_even_when_no_permission_set() throws Exception {
    PermissionTemplateDto template = addTemplateToDefaultOrganization();
    GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "group");
    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), group.getId()));
    commit();
    loginAsAdmin(db.getDefaultOrganization());
    InputStream output = newRequest().setMediaType(PROTOBUF).setParam(PARAM_TEMPLATE_ID, template.getUuid()).setParam(TEXT_QUERY, "nyo").execute().getInputStream();
    WsGroupsResponse response = WsGroupsResponse.parseFrom(output);
    assertThat(response.getGroupsList()).extracting("name").containsExactly("Anyone");
    assertThat(response.getGroups(0).getPermissionsList()).isEmpty();
}
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) 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