Search in sources :

Example 41 with GroupDto

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

the class AddGroupActionTest method reference_group_by_its_name_in_organization.

@Test
public void reference_group_by_its_name_in_organization() throws Exception {
    OrganizationDto org = db.organizations().insert();
    GroupDto group = db.users().insertGroup(org, "the-group");
    loginAsAdmin(org);
    newRequest().setParam(PARAM_ORGANIZATION, org.getKey()).setParam(PARAM_GROUP_NAME, group.getName()).setParam(PARAM_PERMISSION, PROVISIONING).execute();
    assertThat(db.users().selectGroupPermissions(group, null)).containsOnly(PROVISIONING);
}
Also used : GroupDto(org.sonar.db.user.GroupDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 42 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 43 with GroupDto

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

the class PermissionTemplateDaoTest method add_group_permission_to_template.

@Test
public void add_group_permission_to_template() {
    PermissionTemplateDto permissionTemplate = templateDb.insertTemplate();
    GroupDto group = db.users().insertGroup();
    underTest.insertGroupPermission(dbSession, permissionTemplate.getUuid(), group.getUuid(), "user", permissionTemplate.getName(), group.getName());
    dbSession.commit();
    assertThat(db.getDbClient().permissionTemplateDao().selectGroupPermissionsByTemplateUuid(db.getSession(), permissionTemplate.getUuid())).extracting(PermissionTemplateGroupDto::getTemplateUuid, PermissionTemplateGroupDto::getGroupUuid, PermissionTemplateGroupDto::getPermission, PermissionTemplateGroupDto::getCreatedAt, PermissionTemplateGroupDto::getUpdatedAt).containsOnly(tuple(permissionTemplate.getUuid(), group.getUuid(), "user", NOW, NOW));
}
Also used : PermissionTemplateTesting.newPermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto) GroupDto(org.sonar.db.user.GroupDto) GroupTesting.newGroupDto(org.sonar.db.user.GroupTesting.newGroupDto) Test(org.junit.Test)

Example 44 with GroupDto

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

the class PermissionTemplateDaoTest method group_count_by_template_and_permission.

@Test
public void group_count_by_template_and_permission() {
    PermissionTemplateDto template1 = templateDb.insertTemplate();
    PermissionTemplateDto template2 = templateDb.insertTemplate();
    PermissionTemplateDto template3 = templateDb.insertTemplate();
    PermissionTemplateDto template4 = templateDb.insertTemplate();
    GroupDto group1 = db.users().insertGroup(newGroupDto());
    GroupDto group2 = db.users().insertGroup(newGroupDto());
    GroupDto group3 = db.users().insertGroup(newGroupDto());
    templateDb.addGroupToTemplate(template1.getUuid(), group1.getUuid(), CODEVIEWER, template1.getName(), group1.getName());
    templateDb.addGroupToTemplate(template1.getUuid(), group2.getUuid(), CODEVIEWER, template1.getName(), group2.getName());
    templateDb.addGroupToTemplate(template1.getUuid(), group3.getUuid(), CODEVIEWER, template1.getName(), group3.getName());
    templateDb.addGroupToTemplate(template1.getUuid(), null, CODEVIEWER, template1.getName(), null);
    templateDb.addGroupToTemplate(template1.getUuid(), group1.getUuid(), ADMIN, template1.getName(), group1.getName());
    templateDb.addGroupToTemplate(template2.getUuid(), group1.getUuid(), ADMIN, template2.getName(), group1.getName());
    templateDb.addGroupToTemplate(template4.getUuid(), group1.getUuid(), ISSUE_ADMIN, template4.getName(), group1.getName());
    final List<CountByTemplateAndPermissionDto> result = new ArrayList<>();
    underTest.groupsCountByTemplateUuidAndPermission(dbSession, asList(template1.getUuid(), template2.getUuid(), template3.getUuid()), context -> result.add(context.getResultObject()));
    assertThat(result).extracting(CountByTemplateAndPermissionDto::getPermission, CountByTemplateAndPermissionDto::getTemplateUuid, CountByTemplateAndPermissionDto::getCount).containsOnly(tuple(ADMIN, template1.getUuid(), 1), tuple(CODEVIEWER, template1.getUuid(), 4), tuple(ADMIN, template2.getUuid(), 1));
}
Also used : PermissionTemplateTesting.newPermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto) GroupDto(org.sonar.db.user.GroupDto) GroupTesting.newGroupDto(org.sonar.db.user.GroupTesting.newGroupDto) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 45 with GroupDto

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

the class PermissionTemplateDaoTest method remove_by_group.

@Test
public void remove_by_group() {
    PermissionTemplateDto permissionTemplate = templateDb.insertTemplate();
    GroupDto group1 = db.users().insertGroup();
    GroupDto group2 = db.users().insertGroup();
    templateDb.addGroupToTemplate(permissionTemplate, group1, "user");
    templateDb.addGroupToTemplate(permissionTemplate, group1, "admin");
    templateDb.addGroupToTemplate(permissionTemplate, group2, "user");
    underTest.deleteByGroup(db.getSession(), group1.getUuid(), group1.getName());
    db.getSession().commit();
    assertThat(db.getDbClient().permissionTemplateDao().selectGroupPermissionsByTemplateUuid(db.getSession(), permissionTemplate.getUuid())).extracting(PermissionTemplateGroupDto::getGroupUuid, PermissionTemplateGroupDto::getPermission).containsOnly(tuple(group2.getUuid(), "user"));
}
Also used : PermissionTemplateTesting.newPermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto) GroupDto(org.sonar.db.user.GroupDto) GroupTesting.newGroupDto(org.sonar.db.user.GroupTesting.newGroupDto) Test(org.junit.Test)

Aggregations

GroupDto (org.sonar.db.user.GroupDto)424 Test (org.junit.Test)387 UserDto (org.sonar.db.user.UserDto)148 ComponentDto (org.sonar.db.component.ComponentDto)127 GroupTesting.newGroupDto (org.sonar.db.user.GroupTesting.newGroupDto)70 OrganizationDto (org.sonar.db.organization.OrganizationDto)42 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)36 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)34 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)31 QualityGateDto (org.sonar.db.qualitygate.QualityGateDto)28 DbSession (org.sonar.db.DbSession)20 PermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateGroupDto)17 NotFoundException (org.sonar.server.exceptions.NotFoundException)14 PermissionTemplateTesting.newPermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto)13 UserGroupDto (org.sonar.db.user.UserGroupDto)12 BasePermissionWsTest (org.sonar.server.permission.ws.BasePermissionWsTest)12 TestResponse (org.sonar.server.ws.TestResponse)11 Qualitygates (org.sonarqube.ws.Qualitygates)10 PermissionTemplateTesting.newPermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateGroupDto)9 SearchGroupsResponse (org.sonarqube.ws.Qualityprofiles.SearchGroupsResponse)9