Search in sources :

Example 26 with PermissionTemplateDto

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

the class TemplateGroupsActionTest method search_by_template_name.

@Test
public void search_by_template_name() throws Exception {
    OrganizationDto defaultOrg = db.getDefaultOrganization();
    GroupDto group1 = db.users().insertGroup(defaultOrg, "group-1-name");
    GroupDto group2 = db.users().insertGroup(defaultOrg, "group-2-name");
    GroupDto group3 = db.users().insertGroup(defaultOrg, "group-3-name");
    PermissionTemplateDto template = addTemplateToDefaultOrganization();
    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), group1.getId()));
    addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getId(), group2.getId()));
    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), null));
    PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
    addGroupToTemplate(newPermissionTemplateGroup(USER, anotherTemplate.getId(), group1.getId()));
    commit();
    loginAsAdmin(db.getDefaultOrganization());
    InputStream output = newRequest().setMediaType(PROTOBUF).setParam(PARAM_TEMPLATE_NAME, template.getName()).execute().getInputStream();
    WsGroupsResponse response = WsGroupsResponse.parseFrom(output);
    assertThat(response.getGroupsList()).extracting("name").containsExactly("Anyone", "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 27 with PermissionTemplateDto

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

the class TemplateUsersActionTest method empty_result_when_no_user_on_template.

@Test
public void empty_result_when_no_user_on_template() throws Exception {
    UserDto user = insertUser(newUserDto().setLogin("login-1").setName("name-1").setEmail("email-1"));
    PermissionTemplateDto template = addTemplateToDefaultOrganization();
    PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
    addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user));
    loginAsAdmin(db.getDefaultOrganization());
    InputStream bytes = newRequest(null, null).setParam(PARAM_TEMPLATE_NAME, template.getName()).setMediaType(PROTOBUF).execute().getInputStream();
    WsPermissions.UsersWsResponse response = WsPermissions.UsersWsResponse.parseFrom(bytes);
    assertThat(response.getUsersList()).isEmpty();
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) InputStream(java.io.InputStream) UserDto(org.sonar.db.user.UserDto) PermissionTemplateUserDto(org.sonar.db.permission.template.PermissionTemplateUserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) PermissionTemplateTesting.newPermissionTemplateUserDto(org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateUserDto) WsPermissions(org.sonarqube.ws.WsPermissions) BasePermissionWsTest(org.sonar.server.permission.ws.BasePermissionWsTest) Test(org.junit.Test)

Example 28 with PermissionTemplateDto

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

the class TemplateUsersActionTest method fail_if_not_a_project_permission.

@Test
public void fail_if_not_a_project_permission() throws Exception {
    PermissionTemplateDto template = addTemplateToDefaultOrganization();
    loginAsAdmin(db.getDefaultOrganization());
    expectedException.expect(IllegalArgumentException.class);
    newRequest(GlobalPermissions.PROVISIONING, template.getUuid()).execute();
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) BasePermissionWsTest(org.sonar.server.permission.ws.BasePermissionWsTest) Test(org.junit.Test)

Example 29 with PermissionTemplateDto

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

the class TemplateUsersActionTest method search_for_users_by_template_name.

@Test
public void search_for_users_by_template_name() throws Exception {
    loginAsAdmin(db.getDefaultOrganization());
    UserDto user1 = insertUser(newUserDto().setLogin("login-1").setName("name-1").setEmail("email-1"));
    UserDto user2 = insertUser(newUserDto().setLogin("login-2").setName("name-2").setEmail("email-2"));
    UserDto user3 = insertUser(newUserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
    PermissionTemplateDto template = addTemplateToDefaultOrganization();
    addUserToTemplate(newPermissionTemplateUser(USER, template, user1));
    addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
    addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1));
    addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
    PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
    addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
    InputStream bytes = newRequest(null, null).setParam(PARAM_TEMPLATE_NAME, template.getName()).setMediaType(PROTOBUF).execute().getInputStream();
    WsPermissions.UsersWsResponse response = WsPermissions.UsersWsResponse.parseFrom(bytes);
    assertThat(response.getUsersList()).extracting("login").containsExactly("login-1", "login-2", "login-3");
    assertThat(response.getUsers(0).getPermissionsList()).containsOnly("issueadmin", "user");
    assertThat(response.getUsers(1).getPermissionsList()).containsOnly("user");
    assertThat(response.getUsers(2).getPermissionsList()).containsOnly("issueadmin");
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) InputStream(java.io.InputStream) UserDto(org.sonar.db.user.UserDto) PermissionTemplateUserDto(org.sonar.db.permission.template.PermissionTemplateUserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) PermissionTemplateTesting.newPermissionTemplateUserDto(org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateUserDto) WsPermissions(org.sonarqube.ws.WsPermissions) BasePermissionWsTest(org.sonar.server.permission.ws.BasePermissionWsTest) Test(org.junit.Test)

Example 30 with PermissionTemplateDto

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

the class TemplateUsersActionTest method search_with_pagination.

@Test
public void search_with_pagination() throws Exception {
    UserDto user1 = insertUser(newUserDto().setLogin("login-1").setName("name-1").setEmail("email-1"));
    UserDto user2 = insertUser(newUserDto().setLogin("login-2").setName("name-2").setEmail("email-2"));
    UserDto user3 = insertUser(newUserDto().setLogin("login-3").setName("name-3").setEmail("email-3"));
    PermissionTemplateDto template = addTemplateToDefaultOrganization();
    addUserToTemplate(newPermissionTemplateUser(USER, template, user1));
    addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
    addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user1));
    addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
    PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
    addUserToTemplate(newPermissionTemplateUser(USER, anotherTemplate, user1));
    loginAsAdmin(db.getDefaultOrganization());
    InputStream bytes = newRequest(USER, null).setParam(PARAM_TEMPLATE_NAME, template.getName()).setParam(WebService.Param.SELECTED, "all").setParam(WebService.Param.PAGE, "2").setParam(WebService.Param.PAGE_SIZE, "1").setMediaType(PROTOBUF).execute().getInputStream();
    WsPermissions.UsersWsResponse response = WsPermissions.UsersWsResponse.parseFrom(bytes);
    assertThat(response.getUsersList()).extracting("login").containsOnly("login-2");
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) InputStream(java.io.InputStream) UserDto(org.sonar.db.user.UserDto) PermissionTemplateUserDto(org.sonar.db.permission.template.PermissionTemplateUserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) PermissionTemplateTesting.newPermissionTemplateUserDto(org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateUserDto) WsPermissions(org.sonarqube.ws.WsPermissions) 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