Search in sources :

Example 86 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class TemplateGroupsActionTest method do_not_fail_when_group_name_exists_in_multiple_organizations.

@Test
public void do_not_fail_when_group_name_exists_in_multiple_organizations() {
    PermissionTemplateDto template = addTemplateToDefaultOrganization();
    String groupName = "group-name";
    GroupDto group1 = db.users().insertGroup(db.getDefaultOrganization(), groupName);
    addGroupToTemplate(newPermissionTemplateGroup(CODEVIEWER, template.getId(), group1.getId()));
    addGroupToTemplate(newPermissionTemplateGroup(ADMIN, template.getId(), group1.getId()));
    OrganizationDto otherOrganization = db.organizations().insert();
    db.users().insertGroup(otherOrganization, groupName);
    loginAsAdmin(db.getDefaultOrganization());
    newRequest().setMediaType(PROTOBUF).setParam(PARAM_TEMPLATE_ID, template.getUuid()).setParam(TEXT_QUERY, "-nam").execute().getInputStream();
}
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) OrganizationDto(org.sonar.db.organization.OrganizationDto) BasePermissionWsTest(org.sonar.server.permission.ws.BasePermissionWsTest) Test(org.junit.Test)

Example 87 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class TemplateGroupsActionTest method search_by_permission.

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

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class TemplateGroupsActionTest method search_with_pagination.

@Test
public void search_with_pagination() 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");
    addGroupToTemplate(newPermissionTemplateGroup(USER, template.getId(), group2.getId()));
    commit();
    loginAsAdmin(db.getDefaultOrganization());
    InputStream output = newRequest().setMediaType(PROTOBUF).setParam(PARAM_PERMISSION, USER).setParam(PARAM_TEMPLATE_NAME, template.getName()).setParam(PAGE, "2").setParam(PAGE_SIZE, "1").execute().getInputStream();
    WsGroupsResponse response = WsGroupsResponse.parseFrom(output);
    assertThat(response.getGroupsList()).extracting("name").containsExactly("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 89 with GroupDto

use of org.sonar.db.user.GroupDto 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 90 with GroupDto

use of org.sonar.db.user.GroupDto 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)

Aggregations

GroupDto (org.sonar.db.user.GroupDto)177 Test (org.junit.Test)158 OrganizationDto (org.sonar.db.organization.OrganizationDto)74 UserDto (org.sonar.db.user.UserDto)67 ComponentDto (org.sonar.db.component.ComponentDto)38 GroupTesting.newGroupDto (org.sonar.db.user.GroupTesting.newGroupDto)31 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)18 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)17 PermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateGroupDto)14 UserGroupDto (org.sonar.db.user.UserGroupDto)12 DbSession (org.sonar.db.DbSession)11 BasePermissionWsTest (org.sonar.server.permission.ws.BasePermissionWsTest)9 PermissionTemplateTesting.newPermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateGroupDto)8 WsGroupsResponse (org.sonarqube.ws.WsPermissions.WsGroupsResponse)7 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)3 System2 (org.sonar.api.utils.System2)3 DbClient (org.sonar.db.DbClient)3 PermissionTemplateTesting.newPermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto)3 Strings (com.google.common.base.Strings)2