dbTester.users().insertPermissionOnUser(otherOrganizationDto, user1, "not deleted u2");
dbTester.users().insertPermissionOnGroup(group1, "u3");
dbTester.users().insertPermissionOnGroup(otherGroup1, "not deleted u3");
- dbTester.users().insertProjectPermissionOnAnyone(organizationDto, "u4", projectDto);
- dbTester.users().insertProjectPermissionOnAnyone(otherOrganizationDto, "not deleted u4", otherProjectDto);
+ dbTester.users().insertProjectPermissionOnAnyone("u4", projectDto);
+ dbTester.users().insertProjectPermissionOnAnyone("not deleted u4", otherProjectDto);
dbTester.users().insertProjectPermissionOnGroup(group1, "u5", projectDto);
dbTester.users().insertProjectPermissionOnGroup(otherGroup1, "not deleted u5", otherProjectDto);
dbTester.users().insertProjectPermissionOnUser(user1, "u6", projectDto);
@Test
public void remove_project_permission_from_user() {
ComponentDto project2 = db.components().insertProject(org1);
- db.users().insertPermissionOnUser(org1, user1, QUALITY_GATE_ADMIN);
+ db.users().insertPermissionOnUser(user1, QUALITY_GATE_ADMIN);
db.users().insertProjectPermissionOnUser(user1, ISSUE_ADMIN, project);
db.users().insertProjectPermissionOnUser(user1, USER, project);
db.users().insertProjectPermissionOnUser(user2, ISSUE_ADMIN, project);
userDbTester.insertProjectPermissionOnGroup(group, ADMIN, view1);
// Anyone group has user access on both projects
- userDbTester.insertProjectPermissionOnAnyone(dbTester.getDefaultOrganization(), USER, project1);
- userDbTester.insertProjectPermissionOnAnyone(dbTester.getDefaultOrganization(), ADMIN, project1);
- userDbTester.insertProjectPermissionOnAnyone(dbTester.getDefaultOrganization(), USER, project2);
- userDbTester.insertProjectPermissionOnAnyone(dbTester.getDefaultOrganization(), USER, view1);
- userDbTester.insertProjectPermissionOnAnyone(dbTester.getDefaultOrganization(), ADMIN, view1);
- userDbTester.insertProjectPermissionOnAnyone(dbTester.getDefaultOrganization(), USER, view2);
+ userDbTester.insertProjectPermissionOnAnyone(USER, project1);
+ userDbTester.insertProjectPermissionOnAnyone(ADMIN, project1);
+ userDbTester.insertProjectPermissionOnAnyone(USER, project2);
+ userDbTester.insertProjectPermissionOnAnyone(USER, view1);
+ userDbTester.insertProjectPermissionOnAnyone(ADMIN, view1);
+ userDbTester.insertProjectPermissionOnAnyone(USER, view2);
}
}
userDbTester.insertProjectPermissionOnUser(user, ADMIN, view);
GroupDto group = userDbTester.insertGroup();
userDbTester.insertProjectPermissionOnGroup(group, USER, project);
- userDbTester.insertProjectPermissionOnAnyone(dbTester.getDefaultOrganization(), USER, project);
+ userDbTester.insertProjectPermissionOnAnyone(USER, project);
userDbTester.insertProjectPermissionOnGroup(group, USER, view);
- userDbTester.insertProjectPermissionOnAnyone(dbTester.getDefaultOrganization(), USER, view);
+ userDbTester.insertProjectPermissionOnAnyone(USER, view);
underTest.indexAllIfEmpty();
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
-import static org.sonar.db.component.ComponentTesting.newView;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_ID;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_NAME;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_ORGANIZATION_KEY;
@Test
public void remove_with_view_uuid() throws Exception {
- ComponentDto view = db.components().insertComponent(newView(db.getDefaultOrganization(), "view-uuid").setKey("view-key"));
+ ComponentDto view = db.components().insertView();
db.users().insertPermissionOnGroup(aGroup, SYSTEM_ADMIN);
db.users().insertProjectPermissionOnGroup(aGroup, ADMIN, view);
db.users().insertProjectPermissionOnGroup(aGroup, ISSUE_ADMIN, view);
private void executeRequest(GroupDto groupDto, String permission) throws Exception {
newRequest()
- .setParam(PARAM_GROUP_NAME, groupDto.getName())
- .setParam(PARAM_PERMISSION, permission)
- .execute();
+ .setParam(PARAM_GROUP_NAME, groupDto.getName())
+ .setParam(PARAM_PERMISSION, permission)
+ .execute();
}
private void executeRequest(GroupDto groupDto, OrganizationDto organizationDto, String permission) throws Exception {
newRequest()
- .setParam(PARAM_GROUP_NAME, groupDto.getName())
- .setParam(PARAM_PERMISSION, permission)
- .setParam(PARAM_ORGANIZATION_KEY, organizationDto.getKey())
- .execute();
+ .setParam(PARAM_GROUP_NAME, groupDto.getName())
+ .setParam(PARAM_PERMISSION, permission)
+ .setParam(PARAM_ORGANIZATION_KEY, organizationDto.getKey())
+ .execute();
}
@Test
// global permission
db.users().insertPermissionOnUser(user1, GlobalPermissions.SYSTEM_ADMIN);
- GroupDto group1 = db.users().insertGroup(db.getDefaultOrganization());
- GroupDto group2 = db.users().insertGroup(db.getDefaultOrganization());
- GroupDto group3 = db.users().insertGroup(db.getDefaultOrganization());
+ GroupDto group1 = db.users().insertGroup();
+ GroupDto group2 = db.users().insertGroup();
+ GroupDto group3 = db.users().insertGroup();
- db.users().insertProjectPermissionOnAnyone(db.getDefaultOrganization(), UserRole.ADMIN, jdk7);
+ db.users().insertProjectPermissionOnAnyone(UserRole.ADMIN, jdk7);
db.users().insertProjectPermissionOnGroup(group1, UserRole.ADMIN, jdk7);
db.users().insertProjectPermissionOnGroup(group2, UserRole.ADMIN, jdk7);
db.users().insertProjectPermissionOnGroup(group3, UserRole.ADMIN, jdk7);
}
private ComponentDto insertJdk7() {
- return db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), "project-uuid-1")
+ return db.components().insertComponent(newProjectDto(db.getDefaultOrganization())
.setName("JDK 7")
.setKey("net.java.openjdk:jdk7")
.setUuid("0bd7b1e7-91d6-439e-a607-4a3a9aad3c6a"));
@Test
public void search_only_for_users_with_permission_when_no_search_query() throws Exception {
// User have permission on project
- ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
- UserDto user = db.users().insertUser(newUserDto());
+ ComponentDto project = db.components().insertProject();
+ UserDto user = db.users().insertUser();
db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project);
// User has no permission
- UserDto withoutPermission = db.users().insertUser(newUserDto());
+ UserDto withoutPermission = db.users().insertUser();
loginAsAdminOnDefaultOrganization();
String result = newRequest()
import org.sonar.api.web.UserRole;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.PermissionQuery;
import org.sonar.db.permission.template.PermissionTemplateDto;
import org.sonar.db.user.GroupDto;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
-import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_ID;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID;
@Before
public void setUp() {
- user1 = db.users().insertUser("user-login-1");
- user2 = db.users().insertUser("user-login-2");
- OrganizationDto defaultOrg = db.getDefaultOrganization();
- group1 = db.users().insertGroup(defaultOrg, "group-name-1");
- group2 = db.users().insertGroup(defaultOrg, "group-name-2");
+ user1 = db.users().insertUser();
+ user2 = db.users().insertUser();
+ group1 = db.users().insertGroup();
+ group2 = db.users().insertGroup();
// template 1
template1 = insertTemplate();
addGroupToTemplate(group1, template2, UserRole.USER);
addGroupToTemplate(group2, template2, UserRole.USER);
- project = db.components().insertComponent(newProjectDto(defaultOrg, "project-uuid-1"));
+ project = db.components().insertProject();
db.users().insertProjectPermissionOnUser(user1, UserRole.ADMIN, project);
db.users().insertProjectPermissionOnUser(user2, UserRole.ADMIN, project);
db.users().insertProjectPermissionOnGroup(group1, UserRole.ADMIN, project);
@Before
public void setUp() {
- user1 = db.users().insertUser("user-login-1");
- user2 = db.users().insertUser("user-login-2");
- OrganizationDto defaultOrg = db.getDefaultOrganization();
- group1 = db.users().insertGroup(defaultOrg, "group-name-1");
- group2 = db.users().insertGroup(defaultOrg, "group-name-2");
+ user1 = db.users().insertUser();
+ user2 = db.users().insertUser();
+ group1 = db.users().insertGroup();
+ group2 = db.users().insertGroup();
// template 1
template1 = insertTemplate();
@Test
public void bulk_apply_template_by_template_uuid() throws Exception {
- OrganizationDto organization = db.getDefaultOrganization();
- ComponentDto project = db.components().insertComponent(newProjectDto(organization));
- ComponentDto view = db.components().insertComponent(newView(organization));
- db.users().insertProjectPermissionOnUser(user1, UserRole.ADMIN, view);
- db.users().insertProjectPermissionOnUser(user2, UserRole.ADMIN, view);
- db.users().insertProjectPermissionOnGroup(group1, UserRole.ADMIN, view);
- db.users().insertProjectPermissionOnGroup(group2, UserRole.ADMIN, view);
+ ComponentDto project = db.components().insertProject();
+ ComponentDto view = db.components().insertView();
+ ComponentDto developer = db.components().insertDeveloper("developer-name");
+ db.users().insertProjectPermissionOnUser(user1, UserRole.ADMIN, developer);
+ db.users().insertProjectPermissionOnUser(user2, UserRole.ADMIN, developer);
+ db.users().insertProjectPermissionOnGroup(group1, UserRole.ADMIN, developer);
+ db.users().insertProjectPermissionOnGroup(group2, UserRole.ADMIN, developer);
loginAsAdminOnDefaultOrganization();
newRequest().setParam(PARAM_TEMPLATE_ID, template1.getUuid()).execute();
import static org.sonar.test.JsonAssert.assertJson;
public class SearchMyProjectsActionTest {
- private static final String USER_LOGIN = "TESTER";
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Before
public void setUp() {
- user = db.users().insertUser(newUserDto().setLogin(USER_LOGIN));
- userSession.login(this.user.getLogin()).setUserId(user.getId().intValue());
+ user = db.users().insertUser();
+ userSession.login(user);
alertStatusMetric = dbClient.metricDao().insert(dbSession, newMetricDto().setKey(ALERT_STATUS_KEY).setValueType(ValueType.LEVEL.name()));
db.commit();
@Test
public void admin_via_groups() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto jdk7 = insertJdk7(organization);
- ComponentDto cLang = insertClang(organization);
+ OrganizationDto org = db.organizations().insert();
+ ComponentDto jdk7 = insertJdk7(org);
+ ComponentDto cLang = insertClang(org);
- GroupDto group = db.users().insertGroup(organization);
+ GroupDto group = db.users().insertGroup(org);
db.users().insertMember(group, user);
db.users().insertProjectPermissionOnGroup(group, UserRole.ADMIN, jdk7);
@Test
public void admin_via_groups_and_users() {
- OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto jdk7 = insertJdk7(organizationDto);
- ComponentDto cLang = insertClang(organizationDto);
- ComponentDto sonarqube = db.components().insertProject(organizationDto);
+ OrganizationDto org = db.organizations().insert();
+ ComponentDto jdk7 = insertJdk7(org);
+ ComponentDto cLang = insertClang(org);
+ ComponentDto sonarqube = db.components().insertProject(org);
- GroupDto group = db.users().insertGroup(organizationDto);
+ GroupDto group = db.users().insertGroup(org);
db.users().insertMember(group, user);
db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, jdk7);
@Test
public void return_all_projects() throws Exception {
- OrganizationDto organizationDto = dbTester.organizations().insert();
- ComponentDto associatedProject = insertProjectAuthorizedToAnyone(organizationDto, newProjectDto(organizationDto));
- ComponentDto unassociatedProject = insertProjectAuthorizedToAnyone(organizationDto, newProjectDto(organizationDto));
+ OrganizationDto org = dbTester.organizations().insert();
+ ComponentDto associatedProject = insertProjectAuthorizedToAnyone(newProjectDto(org));
+ ComponentDto unassociatedProject = insertProjectAuthorizedToAnyone(newProjectDto(org));
associateProjectToQualitGate(associatedProject.getId());
Association result = underTest.find(
@Test
public void return_only_associated_project() throws Exception {
- OrganizationDto organizationDto = dbTester.organizations().insert();
- ComponentDto associatedProject = insertProjectAuthorizedToAnyone(organizationDto, newProjectDto(organizationDto));
- insertProjectAuthorizedToAnyone(organizationDto, newProjectDto(organizationDto));
+ OrganizationDto org = dbTester.organizations().insert();
+ ComponentDto associatedProject = insertProjectAuthorizedToAnyone(newProjectDto(org));
+ insertProjectAuthorizedToAnyone(newProjectDto(org));
associateProjectToQualitGate(associatedProject.getId());
Association result = underTest.find(
@Test
public void return_only_unassociated_project() throws Exception {
- OrganizationDto organizationDto = dbTester.organizations().insert();
- ComponentDto associatedProject = insertProjectAuthorizedToAnyone(organizationDto, newProjectDto(organizationDto));
- ComponentDto unassociatedProject = insertProjectAuthorizedToAnyone(organizationDto, newProjectDto(organizationDto));
+ OrganizationDto org = dbTester.organizations().insert();
+ ComponentDto associatedProject = insertProjectAuthorizedToAnyone(newProjectDto(org));
+ ComponentDto unassociatedProject = insertProjectAuthorizedToAnyone(newProjectDto(org));
associateProjectToQualitGate(associatedProject.getId());
Association result = underTest.find(
@Test
public void test_paging() throws Exception {
- OrganizationDto organizationDto = dbTester.organizations().insert();
- ComponentDto project1 = insertProjectAuthorizedToAnyone(organizationDto, newProjectDto(organizationDto).setName("Project 1"));
- ComponentDto project2 = insertProjectAuthorizedToAnyone(organizationDto, newProjectDto(organizationDto).setName("Project 2"));
- ComponentDto project3 = insertProjectAuthorizedToAnyone(organizationDto, newProjectDto(organizationDto).setName("Project 3"));
+ OrganizationDto org = dbTester.organizations().insert();
+ ComponentDto project1 = insertProjectAuthorizedToAnyone(newProjectDto(org).setName("Project 1"));
+ ComponentDto project2 = insertProjectAuthorizedToAnyone(newProjectDto(org).setName("Project 2"));
+ ComponentDto project3 = insertProjectAuthorizedToAnyone(newProjectDto(org).setName("Project 3"));
associateProjectToQualitGate(project1.getId());
// Return partial result on first page
dbTester.commit();
}
- private ComponentDto insertProjectAuthorizedToAnyone(OrganizationDto organizationDto, ComponentDto project) {
+ private ComponentDto insertProjectAuthorizedToAnyone(ComponentDto project) {
dbTester.components().insertComponent(project);
- dbTester.users().insertProjectPermissionOnAnyone(organizationDto, UserRole.USER, project);
+ dbTester.users().insertProjectPermissionOnAnyone(UserRole.USER, project);
return project;
}
private void addBrowsePermissionToAnyone(ComponentDto... projects) {
for (ComponentDto project : projects) {
- db.users().insertProjectPermissionOnAnyone(organizationDto, UserRole.USER, project);
+ db.users().insertProjectPermissionOnAnyone(UserRole.USER, project);
}
}
@Test
public void hasOrganizationPermission_for_logged_in_user() {
OrganizationDto org = db.organizations().insert();
- ComponentDto project = db.components().insertProject();
+ ComponentDto project = db.components().insertProject(org);
db.users().insertPermissionOnUser(org, userDto, GlobalPermissions.PROVISIONING);
db.users().insertProjectPermissionOnUser(userDto, UserRole.ADMIN, project);
}
}
- private void addAnyonePermissions(OrganizationDto organizationDto, @Nullable ComponentDto component, String... permissions) {
+ private void addAnyonePermissions(OrganizationDto org, @Nullable ComponentDto component, String... permissions) {
for (String permission : permissions) {
if (component == null) {
- db.users().insertPermissionOnAnyone(organizationDto, permission);
+ db.users().insertPermissionOnAnyone(org, permission);
} else {
- db.users().insertProjectPermissionOnAnyone(organizationDto, permission, component);
+ db.users().insertProjectPermissionOnAnyone(permission, component);
}
}
}
assertThat(issueIndex.search(IssueQuery.builder(userSessionRule).viewUuids(newArrayList(viewUuid)).build(), new SearchOptions()).getDocs()).hasSize(2);
}
- private ComponentDto addProjectWithIssue(RuleDto rule, OrganizationDto organizationDto) {
- ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
+ private ComponentDto addProjectWithIssue(RuleDto rule, OrganizationDto org) {
+ ComponentDto project = ComponentTesting.newProjectDto(org);
ComponentDto file = ComponentTesting.newFileDto(project, null);
dbTester.components().insertComponents(project, file);
- dbTester.users().insertProjectPermissionOnAnyone(organizationDto, UserRole.USER, project);
+ dbTester.users().insertProjectPermissionOnAnyone(UserRole.USER, project);
IssueDto issue = IssueTesting.newDto(rule, file, project);
dbClient.issueDao().insert(dbSession, issue);
public void selectRootComponentPermissions_for_logged_in_user() {
db.users().insertMember(group1, user);
ComponentDto project1 = db.components().insertProject(org);
- db.users().insertProjectPermissionOnAnyone(org, "perm1", project1);
+ db.users().insertProjectPermissionOnAnyone("perm1", project1);
db.users().insertProjectPermissionOnGroup(group1, "perm2", project1);
db.users().insertProjectPermissionOnUser(user, "perm3", project1);
@Test
public void selectRootComponentPermissions_for_anonymous_user() {
ComponentDto project1 = db.components().insertProject(org);
- db.users().insertProjectPermissionOnAnyone(org, "perm1", project1);
+ db.users().insertProjectPermissionOnAnyone("perm1", project1);
// ignored permissions
db.users().insertPermissionOnAnyone(org, "ignored");
db.users().insertProjectPermissionOnGroup(group2, ADMIN, project2);
db.users().insertProjectPermissionOnGroup(group3, ADMIN, project2);
// anyone group
- db.users().insertProjectPermissionOnAnyone(db.getDefaultOrganization(), ADMIN, project2);
+ db.users().insertProjectPermissionOnAnyone(ADMIN, project2);
db.users().insertProjectPermissionOnGroup(group1, USER, project2);
db.users().insertProjectPermissionOnGroup(group1, USER, project3);
db.users().insertProjectPermissionOnGroup(group1, SCAN_EXECUTION, project);
db.users().insertProjectPermissionOnGroup(group1, PROVISIONING, project);
- db.users().insertProjectPermissionOnAnyone(db.getDefaultOrganization(), USER, project);
+ db.users().insertProjectPermissionOnAnyone(USER, project);
db.users().insertProjectPermissionOnGroup(group1, SYSTEM_ADMIN, anotherProject);
- db.users().insertProjectPermissionOnAnyone(db.getDefaultOrganization(), SYSTEM_ADMIN, anotherProject);
+ db.users().insertProjectPermissionOnAnyone(SYSTEM_ADMIN, anotherProject);
db.users().insertProjectPermissionOnGroup(group3, SCAN_EXECUTION, anotherProject);
db.users().insertPermissionOnGroup(group2, SCAN_EXECUTION);
assertThat(underTest.selectGroupNamesByQuery(dbSession,
defaultOrganizationUuid, PermissionQuery.builder().build()))
- .doesNotContain(ANYONE)
- .containsExactly(group.getName());
+ .doesNotContain(ANYONE)
+ .containsExactly(group.getName());
}
@Test
@Test
public void selectByGroupIds_on_projects() {
- OrganizationDto organizationDto = db.organizations().insert();
- GroupDto group1 = db.users().insertGroup(organizationDto, "Group-1");
+ OrganizationDto org = db.organizations().insert();
+ GroupDto group1 = db.users().insertGroup(org, "Group-1");
db.users().insertPermissionOnGroup(group1, PROVISIONING);
- GroupDto group2 = db.users().insertGroup(organizationDto, "Group-2");
- ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto));
+ GroupDto group2 = db.users().insertGroup(org, "Group-2");
+ ComponentDto project = db.components().insertComponent(newProjectDto(org));
db.users().insertProjectPermissionOnGroup(group2, USER, project);
- GroupDto group3 = db.users().insertGroup(organizationDto, "Group-3");
+ GroupDto group3 = db.users().insertGroup(org, "Group-3");
db.users().insertProjectPermissionOnGroup(group3, USER, project);
// Anyone group
- db.users().insertPermissionOnAnyone(organizationDto, SCAN_EXECUTION);
- db.users().insertProjectPermissionOnAnyone(organizationDto, PROVISIONING, project);
+ db.users().insertPermissionOnAnyone(org, SCAN_EXECUTION);
+ db.users().insertProjectPermissionOnAnyone(PROVISIONING, project);
assertThat(underTest.selectByGroupIds(dbSession, defaultOrganizationUuid, singletonList(group1.getId()), project.getId())).isEmpty();
- assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), singletonList(group2.getId()), project.getId()))
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(group2.getId()), project.getId()))
.extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getResourceId)
.containsOnly(tuple(group2.getId(), USER, project.getId()));
- assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), singletonList(group3.getId()), project.getId()))
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(group3.getId()), project.getId()))
.extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getResourceId)
.containsOnly(tuple(group3.getId(), USER, project.getId()));
- assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), singletonList(ANYONE_ID), project.getId()))
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(ANYONE_ID), project.getId()))
.extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getResourceId)
.containsOnly(tuple(0L, PROVISIONING, project.getId()));
- assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), asList(group1.getId(), group2.getId(), ANYONE_ID), project.getId())).hasSize(2);
- assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), singletonList(MISSING_ID), project.getId())).isEmpty();
- assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), singletonList(group1.getId()), 123L)).isEmpty();
- assertThat(underTest.selectByGroupIds(dbSession, organizationDto.getUuid(), Collections.emptyList(), project.getId())).isEmpty();
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), asList(group1.getId(), group2.getId(), ANYONE_ID), project.getId())).hasSize(2);
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(MISSING_ID), project.getId())).isEmpty();
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(group1.getId()), 123L)).isEmpty();
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), Collections.emptyList(), project.getId())).isEmpty();
}
@Test
db.users().insertPermissionOnGroup(group1, "perm3");
db.users().insertPermissionOnGroup(group2, "perm4");
db.users().insertProjectPermissionOnGroup(group1, "perm5", project);
- db.users().insertProjectPermissionOnAnyone(org1, "perm6", project);
+ db.users().insertProjectPermissionOnAnyone("perm6", project);
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, org1.getUuid(), group1.getId())).containsOnly("perm2", "perm3");
assertThat(underTest.selectGlobalPermissionsOfGroup(dbSession, org2.getUuid(), group2.getId())).containsOnly("perm4");
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
db.users().insertProjectPermissionOnGroup(group1, "perm4", project1);
db.users().insertProjectPermissionOnGroup(group1, "perm5", project2);
- db.users().insertProjectPermissionOnAnyone(org1, "perm6", project1);
+ db.users().insertProjectPermissionOnAnyone("perm6", project1);
assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), group1.getId(), project1.getId()))
.containsOnly("perm3", "perm4");
@Test
public void projectHasPermissions_is_true_if_at_least_one_permission_on_anyone() {
- OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto project1 = db.components().insertProject(organizationDto);
- ComponentDto project2 = db.components().insertProject(organizationDto);
- db.users().insertProjectPermissionOnAnyone(organizationDto, "perm1", project1);
+ OrganizationDto org = db.organizations().insert();
+ ComponentDto project1 = db.components().insertProject(org);
+ ComponentDto project2 = db.components().insertProject(org);
+ db.users().insertProjectPermissionOnAnyone("perm1", project1);
assertThat(underTest.hasRootComponentPermissions(dbSession, project1.getId())).isTrue();
assertThat(underTest.hasRootComponentPermissions(dbSession, project2.getId())).isFalse();
@Test
public void deleteByRootComponentId() {
- OrganizationDto organizationDto = db.organizations().insert();
- GroupDto group1 = db.users().insertGroup(organizationDto);
- GroupDto group2 = db.users().insertGroup(organizationDto);
- ComponentDto project1 = db.components().insertProject(organizationDto);
- ComponentDto project2 = db.components().insertProject(organizationDto);
+ OrganizationDto org = db.organizations().insert();
+ GroupDto group1 = db.users().insertGroup(org);
+ GroupDto group2 = db.users().insertGroup(org);
+ ComponentDto project1 = db.components().insertProject(org);
+ ComponentDto project2 = db.components().insertProject(org);
db.users().insertPermissionOnGroup(group1, "perm1");
db.users().insertProjectPermissionOnGroup(group1, "perm2", project1);
- db.users().insertProjectPermissionOnAnyone(organizationDto, "perm3", project1);
+ db.users().insertProjectPermissionOnAnyone("perm3", project1);
db.users().insertProjectPermissionOnGroup(group2, "perm4", project2);
underTest.deleteByRootComponentId(dbSession, project1.getId());
@Test
public void delete_global_permission_from_group() {
- OrganizationDto organizationDto = db.organizations().insert();
- GroupDto group1 = db.users().insertGroup(organizationDto);
- ComponentDto project1 = db.components().insertProject(organizationDto);
- db.users().insertPermissionOnAnyone(organizationDto, "perm1");
+ OrganizationDto org = db.organizations().insert();
+ GroupDto group1 = db.users().insertGroup(org);
+ ComponentDto project1 = db.components().insertProject(org);
+ db.users().insertPermissionOnAnyone(org, "perm1");
db.users().insertPermissionOnGroup(group1, "perm2");
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
- db.users().insertProjectPermissionOnAnyone(organizationDto, "perm4", project1);
+ db.users().insertProjectPermissionOnAnyone("perm4", project1);
underTest.delete(dbSession, "perm2", group1.getOrganizationUuid(), group1.getId(), null);
dbSession.commit();
@Test
public void delete_global_permission_from_anyone() {
- OrganizationDto organizationDto = db.organizations().insert();
- GroupDto group1 = db.users().insertGroup(organizationDto);
- ComponentDto project1 = db.components().insertProject(organizationDto);
- db.users().insertPermissionOnAnyone(organizationDto, "perm1");
+ OrganizationDto org = db.organizations().insert();
+ GroupDto group1 = db.users().insertGroup(org);
+ ComponentDto project1 = db.components().insertProject(org);
+ db.users().insertPermissionOnAnyone(org, "perm1");
db.users().insertPermissionOnGroup(group1, "perm2");
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
- db.users().insertProjectPermissionOnAnyone(organizationDto, "perm4", project1);
+ db.users().insertProjectPermissionOnAnyone("perm4", project1);
underTest.delete(dbSession, "perm1", group1.getOrganizationUuid(), null, null);
dbSession.commit();
@Test
public void delete_project_permission_from_group() {
- OrganizationDto organizationDto = db.organizations().insert();
- GroupDto group1 = db.users().insertGroup(organizationDto);
- ComponentDto project1 = db.components().insertProject(organizationDto);
- db.users().insertPermissionOnAnyone(organizationDto, "perm1");
+ OrganizationDto org = db.organizations().insert();
+ GroupDto group1 = db.users().insertGroup(org);
+ ComponentDto project1 = db.components().insertProject(org);
+ db.users().insertPermissionOnAnyone(org, "perm1");
db.users().insertPermissionOnGroup(group1, "perm2");
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
- db.users().insertProjectPermissionOnAnyone(organizationDto, "perm4", project1);
+ db.users().insertProjectPermissionOnAnyone("perm4", project1);
underTest.delete(dbSession, "perm3", group1.getOrganizationUuid(), group1.getId(), project1.getId());
dbSession.commit();
@Test
public void delete_project_permission_from_anybody() {
- OrganizationDto organizationDto = db.organizations().insert();
- GroupDto group1 = db.users().insertGroup(organizationDto);
- ComponentDto project1 = db.components().insertProject(organizationDto);
- db.users().insertPermissionOnAnyone(organizationDto, "perm1");
+ OrganizationDto org = db.organizations().insert();
+ GroupDto group1 = db.users().insertGroup(org);
+ ComponentDto project1 = db.components().insertProject(org);
+ db.users().insertPermissionOnAnyone(org, "perm1");
db.users().insertPermissionOnGroup(group1, "perm2");
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
- db.users().insertProjectPermissionOnAnyone(organizationDto, "perm4", project1);
+ db.users().insertProjectPermissionOnAnyone("perm4", project1);
underTest.delete(dbSession, "perm4", group1.getOrganizationUuid(), null, project1.getId());
dbSession.commit();
db.commit();
}
- public GroupPermissionDto insertProjectPermissionOnAnyone(OrganizationDto org, String permission, ComponentDto project) {
+ public GroupPermissionDto insertProjectPermissionOnAnyone(String permission, ComponentDto project) {
GroupPermissionDto dto = new GroupPermissionDto()
- .setOrganizationUuid(org.getUuid())
+ .setOrganizationUuid(project.getOrganizationUuid())
.setGroupId(null)
.setRole(permission)
.setResourceId(project.getId());
}
public GroupPermissionDto insertProjectPermissionOnGroup(GroupDto group, String permission, ComponentDto project) {
+ checkArgument(group.getOrganizationUuid().equals(project.getOrganizationUuid()), "Different organizations");
GroupPermissionDto dto = new GroupPermissionDto()
.setOrganizationUuid(group.getOrganizationUuid())
.setGroupId(group.getId())
return db.getDbClient().groupPermissionDao().selectGlobalPermissionsOfGroup(db.getSession(),
org.getUuid(), null);
}
+ checkArgument(org.getUuid().equals(project.getOrganizationUuid()), "Different organizations");
return db.getDbClient().groupPermissionDao().selectProjectPermissionsOfGroup(db.getSession(),
org.getUuid(), null, project.getId());
}
}
/**
+<<<<<<< HEAD
* Grant permission on given project in default organization
+=======
+ * Grant permission on given project
+>>>>>>> 6772c5b73a... SONAR-8704 remove error-prone params Organization in UserDbTester
*/
public UserPermissionDto insertProjectPermissionOnUser(UserDto user, String permission, ComponentDto project) {
UserPermissionDto dto = new UserPermissionDto(project.getOrganizationUuid(), permission, user.getId(), project.getId());