Search in sources :

Example 16 with GroupDto

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

the class DeleteActionTest method delete_group_of_an_organization_even_if_name_is_default_group_of_default_organization.

@Test
public void delete_group_of_an_organization_even_if_name_is_default_group_of_default_organization() throws Exception {
    OrganizationDto org = db.organizations().insert();
    addAdmin(org);
    GroupDto group = db.users().insertGroup(org, defaultGroup.getName());
    loginAsAdmin(org);
    newRequest().setParam("id", group.getId().toString()).execute();
    assertThat(db.users().selectGroupById(defaultGroup.getId())).isNotNull();
    assertThat(db.users().selectGroupById(group.getId())).isNull();
}
Also used : GroupDto(org.sonar.db.user.GroupDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 17 with GroupDto

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

the class UpdateActionTest method fails_if_admin_of_another_organization_only.

@Test
public void fails_if_admin_of_another_organization_only() throws Exception {
    OrganizationDto org1 = db.organizations().insert();
    OrganizationDto org2 = db.organizations().insert();
    GroupDto group = db.users().insertGroup(org1, "group1");
    loginAsAdmin(org2);
    expectedException.expect(ForbiddenException.class);
    newRequest().setParam("id", group.getId().toString()).setParam("name", "some-product-bu").setParam("description", "Business Unit for Some Awesome Product").execute();
}
Also used : GroupDto(org.sonar.db.user.GroupDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 18 with GroupDto

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

the class OrganizationDaoTest method selectByPermission_returns_organization_only_if_user_has_specific_permission_by_group_permission.

@Test
public void selectByPermission_returns_organization_only_if_user_has_specific_permission_by_group_permission() {
    OrganizationDto organization = dbTester.organizations().insert();
    OrganizationDto otherOrganization = dbTester.organizations().insert();
    GroupDto group1 = dbTester.users().insertGroup(organization);
    GroupDto group2 = dbTester.users().insertGroup(organization);
    GroupDto otherGroup1 = dbTester.users().insertGroup(otherOrganization);
    GroupDto otherGroup2 = dbTester.users().insertGroup(otherOrganization);
    dbTester.users().insertPermissionOnGroup(group1, PERMISSION_1);
    dbTester.users().insertPermissionOnGroup(otherGroup2, PERMISSION_2);
    dbTester.users().insertPermissionOnGroup(group2, PERMISSION_2);
    dbTester.users().insertPermissionOnGroup(otherGroup1, PERMISSION_1);
    UserDto user = dbTester.users().insertUser();
    dbTester.users().insertMember(group1, user);
    dbTester.users().insertMember(otherGroup2, user);
    UserDto otherUser = dbTester.users().insertUser();
    dbTester.users().insertMember(group2, otherUser);
    dbTester.users().insertMember(otherGroup1, otherUser);
    assertThat(underTest.selectByPermission(dbSession, user.getId(), PERMISSION_1)).extracting(OrganizationDto::getUuid).containsOnlyOnce(organization.getUuid());
    assertThat(underTest.selectByPermission(dbSession, user.getId(), PERMISSION_2)).extracting(OrganizationDto::getUuid).containsOnlyOnce(otherOrganization.getUuid());
    assertThat(underTest.selectByPermission(dbSession, otherUser.getId(), PERMISSION_1)).extracting(OrganizationDto::getUuid).containsOnlyOnce(otherOrganization.getUuid());
    assertThat(underTest.selectByPermission(dbSession, otherUser.getId(), PERMISSION_2)).extracting(OrganizationDto::getUuid).containsOnlyOnce(organization.getUuid());
}
Also used : UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Example 19 with GroupDto

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

the class OrganizationDaoTest method selectByPermission_returns_organization_when_user_has_ADMIN_group_permission_on_some_organization.

@Test
public void selectByPermission_returns_organization_when_user_has_ADMIN_group_permission_on_some_organization() {
    UserDto user = dbTester.users().insertUser();
    OrganizationDto organization1 = dbTester.organizations().insert();
    GroupDto defaultGroup = dbTester.users().insertGroup(organization1);
    dbTester.users().insertPermissionOnGroup(defaultGroup, PERMISSION_1);
    dbTester.users().insertMember(defaultGroup, user);
    OrganizationDto organization2 = dbTester.organizations().insert();
    GroupDto group1 = dbTester.users().insertGroup(organization2);
    dbTester.users().insertPermissionOnGroup(group1, PERMISSION_1);
    dbTester.users().insertMember(group1, user);
    UserDto otherUser = dbTester.users().insertUser();
    OrganizationDto organization3 = dbTester.organizations().insert();
    GroupDto group2 = dbTester.users().insertGroup(organization3);
    dbTester.users().insertPermissionOnGroup(group2, PERMISSION_1);
    dbTester.users().insertMember(group2, otherUser);
    assertThat(underTest.selectByPermission(dbSession, user.getId(), PERMISSION_1)).extracting(OrganizationDto::getUuid).containsOnly(organization1.getUuid(), organization2.getUuid());
    assertThat(underTest.selectByPermission(dbSession, otherUser.getId(), PERMISSION_1)).extracting(OrganizationDto::getUuid).containsOnly(organization3.getUuid());
    assertThat(underTest.selectByPermission(dbSession, 1234, PERMISSION_1)).isEmpty();
}
Also used : UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Example 20 with GroupDto

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

the class GroupPermissionDaoTest method insertGroupWithPermissions.

private int insertGroupWithPermissions(OrganizationDto organization1) {
    GroupDto group = db.users().insertGroup(organization1);
    db.users().insertPermissionOnGroup(group, "foo");
    db.users().insertPermissionOnGroup(group, "bar");
    db.users().insertPermissionOnGroup(group, "doh");
    return group.getId();
}
Also used : GroupDto(org.sonar.db.user.GroupDto)

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