Search in sources :

Example 86 with PermissionTemplateDto

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

the class TemplateGroupsActionTest method template_groups_of_json_example.

@Test
public void template_groups_of_json_example() throws Exception {
    GroupDto adminGroup = insertGroupOnDefaultOrganization("sonar-administrators", "System administrators");
    GroupDto userGroup = insertGroupOnDefaultOrganization("sonar-users", "Any new users created will automatically join this group");
    PermissionTemplateDto template = addTemplateToDefaultOrganization();
    addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getId(), adminGroup.getId()));
    addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getId(), userGroup.getId()));
    // Anyone group
    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), null));
    addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getId(), null));
    commit();
    loginAsAdmin(db.getDefaultOrganization());
    String response = newRequest().setParam(PARAM_PERMISSION, ISSUE_ADMIN).setParam(PARAM_TEMPLATE_ID, template.getUuid()).execute().getInput();
    assertJson(response).ignoreFields("id").withStrictArrayOrder().isSimilarTo(getClass().getResource("template_groups-example.json"));
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) 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) BasePermissionWsTest(org.sonar.server.permission.ws.BasePermissionWsTest) Test(org.junit.Test)

Example 87 with PermissionTemplateDto

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

the class TemplateGroupsActionTest method search_with_text_query_return_all_groups_even_when_no_permission_set.

@Test
public void search_with_text_query_return_all_groups_even_when_no_permission_set() throws Exception {
    OrganizationDto defaultOrg = db.getDefaultOrganization();
    PermissionTemplateDto template = addTemplateToDefaultOrganization();
    db.users().insertGroup(defaultOrg, "group-1-name");
    db.users().insertGroup(defaultOrg, "group-2-name");
    db.users().insertGroup(defaultOrg, "group-3-name");
    commit();
    loginAsAdmin(db.getDefaultOrganization());
    InputStream output = newRequest().setMediaType(PROTOBUF).setParam(PARAM_TEMPLATE_ID, template.getUuid()).setParam(TEXT_QUERY, "-name").execute().getInputStream();
    WsGroupsResponse response = WsGroupsResponse.parseFrom(output);
    assertThat(response.getGroupsList()).extracting("name").containsExactly("group-1-name", "group-2-name", "group-3-name");
    assertThat(response.getGroups(0).getPermissionsList()).isEmpty();
    assertThat(response.getGroups(1).getPermissionsList()).isEmpty();
    assertThat(response.getGroups(2).getPermissionsList()).isEmpty();
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) InputStream(java.io.InputStream) WsGroupsResponse(org.sonarqube.ws.WsPermissions.WsGroupsResponse) OrganizationDto(org.sonar.db.organization.OrganizationDto) BasePermissionWsTest(org.sonar.server.permission.ws.BasePermissionWsTest) Test(org.junit.Test)

Example 88 with PermissionTemplateDto

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

the class TemplateGroupsActionTest method return_all_permissions_of_matching_groups.

@Test
public void return_all_permissions_of_matching_groups() throws Exception {
    PermissionTemplateDto template = addTemplateToDefaultOrganization();
    GroupDto group1 = db.users().insertGroup(db.getDefaultOrganization(), "group-1-name");
    addGroupToTemplate(newPermissionTemplateGroup(CODEVIEWER, template.getId(), group1.getId()));
    addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getId(), group1.getId()));
    GroupDto group2 = db.users().insertGroup(db.getDefaultOrganization(), "group-2-name");
    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), group2.getId()));
    addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getId(), group2.getId()));
    GroupDto group3 = db.users().insertGroup(db.getDefaultOrganization(), "group-3-name");
    // Anyone
    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), null));
    addGroupToTemplate(newPermissionTemplateGroup(ISSUE_ADMIN, template.getId(), null));
    PermissionTemplateDto anotherTemplate = addTemplateToDefaultOrganization();
    addGroupToTemplate(newPermissionTemplateGroup(ADMIN, anotherTemplate.getId(), group3.getId()));
    commit();
    loginAsAdmin(db.getDefaultOrganization());
    InputStream output = newRequest().setMediaType(PROTOBUF).setParam(PARAM_TEMPLATE_ID, template.getUuid()).execute().getInputStream();
    WsGroupsResponse response = WsGroupsResponse.parseFrom(output);
    assertThat(response.getGroupsList()).extracting("name").containsExactly("Anyone", "group-1-name", "group-2-name");
    assertThat(response.getGroups(0).getPermissionsList()).containsOnly("user", "issueadmin");
    assertThat(response.getGroups(1).getPermissionsList()).containsOnly("codeviewer", "admin");
    assertThat(response.getGroups(2).getPermissionsList()).containsOnly("user", "admin");
}
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)

Example 89 with PermissionTemplateDto

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

the class TemplateUsersActionTest method search_using_permission.

@Test
public void search_using_permission() 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, template.getUuid()).setMediaType(PROTOBUF).execute().getInputStream();
    WsPermissions.UsersWsResponse response = WsPermissions.UsersWsResponse.parseFrom(bytes);
    assertThat(response.getUsersList()).extracting("login").containsExactly("login-1", "login-2");
    assertThat(response.getUsers(0).getPermissionsList()).containsOnly("issueadmin", "user");
    assertThat(response.getUsers(1).getPermissionsList()).containsOnly("user");
}
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 90 with PermissionTemplateDto

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

the class TemplateUsersActionTest method users_are_sorted_by_name.

@Test
public void users_are_sorted_by_name() throws Exception {
    UserDto user1 = insertUser(newUserDto().setLogin("login-2").setName("name-2"));
    UserDto user2 = insertUser(newUserDto().setLogin("login-3").setName("name-3"));
    UserDto user3 = insertUser(newUserDto().setLogin("login-1").setName("name-1"));
    PermissionTemplateDto template = addTemplateToDefaultOrganization();
    addUserToTemplate(newPermissionTemplateUser(USER, template, user1));
    addUserToTemplate(newPermissionTemplateUser(USER, template, user2));
    addUserToTemplate(newPermissionTemplateUser(ISSUE_ADMIN, template, user3));
    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()).extracting("login").containsExactly("login-1", "login-2", "login-3");
}
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