]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9140 only ComponentDto can be used to populate UserSessionRule
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 19 Apr 2017 08:48:19 +0000 (10:48 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 27 Apr 2017 12:25:54 +0000 (14:25 +0200)
85 files changed:
server/sonar-server/src/main/java/org/sonar/server/user/UserSession.java
server/sonar-server/src/test/java/org/sonar/server/batch/IssuesActionTest.java
server/sonar-server/src/test/java/org/sonar/server/batch/ProjectDataLoaderMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/batch/ProjectDataLoaderTest.java
server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityActionTest.java
server/sonar-server/src/test/java/org/sonar/server/ce/ws/ActivityStatusActionTest.java
server/sonar-server/src/test/java/org/sonar/server/ce/ws/ComponentActionTest.java
server/sonar-server/src/test/java/org/sonar/server/ce/ws/TaskActionTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceUpdateKeyTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ws/AppActionTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowActionTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ws/TreeActionTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/queue/ReportSubmitterTest.java
server/sonar-server/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java
server/sonar-server/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ActionFinderTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueFinderTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueQueryFactoryTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/SetSeverityActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/SetTypeActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/TransitionActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/TransitionServiceTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/AddCommentActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/AssignActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/ChangelogActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/DeleteCommentActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/DoTransitionActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/EditCommentActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/SetSeverityActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/SetTagsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/SetTypeActionTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/TagsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/MetricsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/custom/ws/UpdateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java
server/sonar-server/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/AddUserActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/GroupsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/RemoveUserActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/UsersActionTest.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/CreateEventActionTest.java
server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/DeleteEventActionTest.java
server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/UpdateEventActionTest.java
server/sonar-server/src/test/java/org/sonar/server/projectlink/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/projectlink/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/projectlink/ws/SearchActionTest.java
server/sonar-server/src/test/java/org/sonar/server/projecttag/ws/SetActionTest.java
server/sonar-server/src/test/java/org/sonar/server/property/ws/IndexActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/GetByProjectActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/RemoveProjectActionTest.java
server/sonar-server/src/test/java/org/sonar/server/setting/ws/ListDefinitionsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java
server/sonar-server/src/test/java/org/sonar/server/setting/ws/SetActionTest.java
server/sonar-server/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java
server/sonar-server/src/test/java/org/sonar/server/source/ws/HashActionTest.java
server/sonar-server/src/test/java/org/sonar/server/source/ws/IndexActionTest.java
server/sonar-server/src/test/java/org/sonar/server/source/ws/LinesActionTest.java
server/sonar-server/src/test/java/org/sonar/server/source/ws/RawActionTest.java
server/sonar-server/src/test/java/org/sonar/server/source/ws/ScmActionTest.java
server/sonar-server/src/test/java/org/sonar/server/source/ws/ShowActionTest.java
server/sonar-server/src/test/java/org/sonar/server/test/ws/CoveredFilesActionTest.java
server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java
server/sonar-server/src/test/java/org/sonar/server/tester/AbstractMockUserSession.java
server/sonar-server/src/test/java/org/sonar/server/tester/UserSessionRule.java
server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java
server/sonar-server/src/test/java/org/sonar/server/webhook/ws/WebhookDeliveriesActionTest.java
server/sonar-server/src/test/java/org/sonar/server/webhook/ws/WebhookDeliveryActionTest.java

index 379192f6b299b97946255cfaead0fb9a169061cd..06aa9ca0004176a49753554e22d3e2f824cae688 100644 (file)
@@ -111,7 +111,10 @@ public interface UserSession {
    * Using {@link #hasComponentPermission(String, ComponentDto)} is recommended
    * because it does not have to load project if the referenced component
    * is not a project.
+   *
+   * @deprecated use {@link #hasComponentPermission(String, ComponentDto)} instead
    */
+  @Deprecated
   boolean hasComponentUuidPermission(String permission, String componentUuid);
 
   /**
@@ -123,7 +126,10 @@ public interface UserSession {
   /**
    * Ensures that {@link #hasComponentUuidPermission(String, String)} is {@code true},
    * otherwise throws a {@link org.sonar.server.exceptions.ForbiddenException}.
+   *
+   * @deprecated use {@link #checkComponentPermission(String, ComponentDto)} instead
    */
+  @Deprecated
   UserSession checkComponentUuidPermission(String permission, String componentUuid);
 
   /**
index da684380a7573b4f621d4bb61c5d0911a6172b8b..b5c4552c2c7fb611c3c9c7616d447e5a2de085fa 100644 (file)
@@ -311,7 +311,7 @@ public class IssuesActionTest {
   }
 
   private void addBrowsePermissionOnComponent(ComponentDto project) {
-    userSessionRule.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSessionRule.addProjectPermission(UserRole.USER, project);
   }
 
   private ServerIssue call(String componentKey) {
index 13bc7138812125e8ea01dc06e59c5dca51b66eb1..8c70e8e7405d722a5316c86b73e3096d55b32394 100644 (file)
@@ -88,7 +88,7 @@ public class ProjectDataLoaderMediumTest {
     OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
     dbClient.organizationDao().insert(dbSession, organizationDto);
     ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
-    userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
+    userSessionRule.logIn().addProjectPermission(SCAN_EXECUTION, project);
     dbClient.componentDao().insert(dbSession, project);
     addDefaultProfile();
 
@@ -112,7 +112,7 @@ public class ProjectDataLoaderMediumTest {
     OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
     dbClient.organizationDao().insert(dbSession, organizationDto);
     ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
-    userSessionRule.logIn("john").addProjectUuidPermissions(SCAN_EXECUTION, project.projectUuid());
+    userSessionRule.logIn("john").addProjectPermission(SCAN_EXECUTION, project);
     dbClient.componentDao().insert(dbSession, project);
     addDefaultProfile();
 
@@ -136,7 +136,7 @@ public class ProjectDataLoaderMediumTest {
     OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
     dbClient.organizationDao().insert(dbSession, organizationDto);
     ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
-    userSessionRule.logIn("john").addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSessionRule.logIn("john").addProjectPermission(UserRole.USER, project);
     dbClient.componentDao().insert(dbSession, project);
     addDefaultProfile();
 
@@ -158,7 +158,7 @@ public class ProjectDataLoaderMediumTest {
     OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
     dbClient.organizationDao().insert(dbSession, organizationDto);
     ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
-    userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
+    userSessionRule.logIn().addProjectPermission(SCAN_EXECUTION, project);
     dbClient.componentDao().insert(dbSession, project);
     addDefaultProfile();
 
@@ -194,7 +194,7 @@ public class ProjectDataLoaderMediumTest {
     OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
     dbClient.organizationDao().insert(dbSession, organizationDto);
     ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
-    userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
+    userSessionRule.logIn().addProjectPermission(SCAN_EXECUTION, project);
     dbClient.componentDao().insert(dbSession, project);
     addDefaultProfile();
 
@@ -225,7 +225,7 @@ public class ProjectDataLoaderMediumTest {
     OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
     dbClient.organizationDao().insert(dbSession, organizationDto);
     ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
-    userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
+    userSessionRule.logIn().addProjectPermission(SCAN_EXECUTION, project);
     dbClient.componentDao().insert(dbSession, project);
     addDefaultProfile();
 
@@ -272,7 +272,7 @@ public class ProjectDataLoaderMediumTest {
     OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
     dbClient.organizationDao().insert(dbSession, organizationDto);
     ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
-    userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
+    userSessionRule.logIn().addProjectPermission(SCAN_EXECUTION, project);
     dbClient.componentDao().insert(dbSession, project);
     addDefaultProfile();
 
@@ -318,7 +318,7 @@ public class ProjectDataLoaderMediumTest {
     dbClient.organizationDao().insert(dbSession, organizationDto);
     // No snapshot attached on the project -> provisioned project
     ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
-    userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
+    userSessionRule.logIn().addProjectPermission(SCAN_EXECUTION, project);
     dbClient.componentDao().insert(dbSession, project);
     addDefaultProfile();
 
@@ -348,7 +348,7 @@ public class ProjectDataLoaderMediumTest {
     // No module properties
 
     ComponentDto subModule = ComponentTesting.newModuleDto(module);
-    userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
+    userSessionRule.logIn().addProjectPermission(SCAN_EXECUTION, project);
     dbClient.componentDao().insert(dbSession, subModule);
 
     // Sub module properties
@@ -386,7 +386,7 @@ public class ProjectDataLoaderMediumTest {
     dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(module.getId()));
 
     ComponentDto subModule = ComponentTesting.newModuleDto(module);
-    userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
+    userSessionRule.logIn().addProjectPermission(SCAN_EXECUTION, project);
     dbClient.componentDao().insert(dbSession, subModule);
 
     // Sub module properties
@@ -423,7 +423,7 @@ public class ProjectDataLoaderMediumTest {
     // No module property
 
     ComponentDto subModule = ComponentTesting.newModuleDto(module);
-    userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
+    userSessionRule.logIn().addProjectPermission(SCAN_EXECUTION, project);
     dbClient.componentDao().insert(dbSession, subModule);
     // No sub module property
 
@@ -458,7 +458,7 @@ public class ProjectDataLoaderMediumTest {
     dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER").setResourceId(module.getId()));
 
     ComponentDto subModule = ComponentTesting.newModuleDto(module);
-    userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
+    userSessionRule.logIn().addProjectPermission(SCAN_EXECUTION, project);
     dbClient.componentDao().insert(dbSession, subModule);
     // No sub module property
 
@@ -499,7 +499,7 @@ public class ProjectDataLoaderMediumTest {
     dbClient.componentDao().insert(dbSession, project);
     dbSession.commit();
 
-    userSessionRule.logIn("john").addProjectUuidPermissions(UserRole.USER, project.projectUuid());
+    userSessionRule.logIn("john").addProjectPermission(UserRole.USER, project);
 
     thrown.expect(ForbiddenException.class);
     thrown.expectMessage("You're only authorized to execute a local (preview) SonarQube analysis without pushing the results to the SonarQube server. " +
@@ -515,7 +515,7 @@ public class ProjectDataLoaderMediumTest {
     dbClient.componentDao().insert(dbSession, project);
     dbSession.commit();
 
-    userSessionRule.logIn("john").addProjectUuidPermissions(GlobalPermissions.SCAN_EXECUTION, project.projectUuid());
+    userSessionRule.logIn("john").addProjectPermission(GlobalPermissions.SCAN_EXECUTION, project);
 
     thrown.expect(ForbiddenException.class);
     thrown.expectMessage("You don't have the required permissions to access this project. Please contact your SonarQube administrator.");
@@ -527,7 +527,7 @@ public class ProjectDataLoaderMediumTest {
     OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
     dbClient.organizationDao().insert(dbSession, organizationDto);
     ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
-    userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
+    userSessionRule.logIn().addProjectPermission(SCAN_EXECUTION, project);
     dbClient.componentDao().insert(dbSession, project);
     addDefaultProfile();
 
@@ -547,7 +547,7 @@ public class ProjectDataLoaderMediumTest {
     OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
     dbClient.organizationDao().insert(dbSession, organizationDto);
     ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
-    userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
+    userSessionRule.logIn().addProjectPermission(SCAN_EXECUTION, project);
     dbClient.componentDao().insert(dbSession, project);
     addDefaultProfile();
 
@@ -585,7 +585,7 @@ public class ProjectDataLoaderMediumTest {
     tester.get(FileSourceDao.class).insert(dbSession, newFileSourceDto(projectFile).setSrcHash("123456").setRevision("987654321"));
 
     ComponentDto module = ComponentTesting.newModuleDto(project);
-    userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
+    userSessionRule.logIn().addProjectPermission(SCAN_EXECUTION, project);
     dbClient.componentDao().insert(dbSession, module);
 
     // File on module
index 49adcb22cedd7243f1b4c5d5a472a3610b0439dd..a5f342d9fd73b18f0fb0e0fbcd28cc5e0c631f25 100644 (file)
@@ -141,7 +141,7 @@ public class ProjectDataLoaderTest {
   @Test
   public void throw_ForbiddenException_if_browse_permission_but_not_scan_permission() {
     ComponentDto project = dbTester.components().insertProject();
-    userSession.logIn().addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.USER, project);
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("You're only authorized to execute a local (preview) SonarQube analysis without pushing the results to the SonarQube server");
@@ -152,7 +152,7 @@ public class ProjectDataLoaderTest {
   @Test
   public void issues_mode_is_allowed_if_user_has_browse_permission() {
     ComponentDto project = dbTester.components().insertProject();
-    userSession.logIn().addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.USER, project);
 
     ProjectRepositories repositories = underTest.load(ProjectDataQuery.create().setModuleKey(project.key()).setIssuesMode(true));
 
@@ -162,7 +162,7 @@ public class ProjectDataLoaderTest {
   @Test
   public void issues_mode_is_forbidden_if_user_doesnt_have_browse_permission() {
     ComponentDto project = dbTester.components().insertProject();
-    userSession.logIn().addProjectUuidPermissions(GlobalPermissions.SCAN_EXECUTION, project.uuid());
+    userSession.logIn().addProjectPermission(GlobalPermissions.SCAN_EXECUTION, project);
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("You don't have the required permissions to access this project");
@@ -174,7 +174,7 @@ public class ProjectDataLoaderTest {
   public void scan_permission_on_organization_is_enough_even_without_scan_permission_on_project() {
     ComponentDto project = dbTester.components().insertProject();
     userSession.logIn().addPermission(SCAN, project.getOrganizationUuid());
-    userSession.logIn().addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.USER, project);
 
     ProjectRepositories repositories = underTest.load(ProjectDataQuery.create().setModuleKey(project.key()).setIssuesMode(true));
 
index 7a738a8ac5113149a6ddf50ea8fd1ed83ff72237..73e57f68478acb0ee4ca7c798d765f901f162c7f 100644 (file)
@@ -211,9 +211,9 @@ public class ActivityActionTest {
 
   @Test
   public void project_administrator_can_access_his_project_activity() {
-    dbTester.components().insertProject(dbTester.organizations().insert(), "PROJECT_1");
+    ComponentDto project = dbTester.components().insertProject(dbTester.organizations().insert(), "PROJECT_1");
     // no need to be a system admin
-    userSession.logIn().addComponentUuidPermission(UserRole.ADMIN, "PROJECT_1", "PROJECT_1");
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
     insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
     insertActivity("T2", "PROJECT_2", CeActivityDto.Status.FAILED);
 
@@ -305,7 +305,7 @@ public class ActivityActionTest {
     // is reserved to roots
     ComponentDto view = dbTester.components().insertView();
     insertActivity("T1", view.uuid(), CeActivityDto.Status.SUCCESS);
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, view.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, view);
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
@@ -318,7 +318,7 @@ public class ActivityActionTest {
     ComponentDto project = dbTester.components().insertProject(dbTester.getDefaultOrganization(), "PROJECT_1");
     insertQueue("T1", "PROJECT_1", CeQueueDto.Status.IN_PROGRESS);
     insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     ActivityResponse result = call(ws.newRequest()
       .setParam(PARAM_COMPONENT_ID, "PROJECT_1")
index 1fab7fc1069f001b878ab8092f848bb098326031..35534909ba19c40df607052e5b430c3089dfd567 100644 (file)
@@ -80,10 +80,11 @@ public class ActivityStatusActionTest {
   public void status_for_a_project_as_project_admin() {
     String projectUuid = "project-uuid";
     String anotherProjectUuid = "another-project-uuid";
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, projectUuid);
     OrganizationDto organizationDto = db.organizations().insert();
-    db.components().insertComponent(newProjectDto(organizationDto, projectUuid));
+    ComponentDto project = newProjectDto(organizationDto, projectUuid);
+    db.components().insertComponent(project);
     db.components().insertComponent(newProjectDto(organizationDto, anotherProjectUuid));
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
     // pending tasks returned
     insertInQueue(CeQueueDto.Status.PENDING, projectUuid);
     insertInQueue(CeQueueDto.Status.PENDING, projectUuid);
index 03c3dc02dc31002bd21de7eec412dbcab6cc0ed2..fa1b0352e99cca92c0ec9c4494ee39f846f04357 100644 (file)
@@ -60,8 +60,8 @@ public class ComponentActionTest {
 
   @Test
   public void empty_queue_and_empty_activity() {
-    dbTester.components().insertComponent(newProjectDto(dbTester.organizations().insert(), "PROJECT_1"));
-    userSession.addComponentUuidPermission(UserRole.USER, "PROJECT_1", "PROJECT_1");
+    ComponentDto project = dbTester.components().insertComponent(newProjectDto(dbTester.organizations().insert(), "PROJECT_1"));
+    userSession.addProjectPermission(UserRole.USER, project);
 
     WsCe.ProjectResponse response = ws.newRequest()
       .setParam("componentId", "PROJECT_1")
@@ -74,8 +74,8 @@ public class ComponentActionTest {
   @Test
   public void project_tasks() {
     OrganizationDto organizationDto = dbTester.organizations().insert();
-    dbTester.components().insertComponent(newProjectDto(organizationDto, "PROJECT_1"));
-    userSession.addComponentUuidPermission(UserRole.USER, "PROJECT_1", "PROJECT_1");
+    ComponentDto project = dbTester.components().insertComponent(newProjectDto(organizationDto, "PROJECT_1"));
+    userSession.addProjectPermission(UserRole.USER, project);
     insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
     insertActivity("T2", "PROJECT_2", CeActivityDto.Status.FAILED);
     insertActivity("T3", "PROJECT_1", CeActivityDto.Status.FAILED);
@@ -111,8 +111,8 @@ public class ComponentActionTest {
 
   @Test
   public void canceled_tasks_must_not_be_picked_as_current_analysis() {
-    dbTester.components().insertComponent(newProjectDto(dbTester.getDefaultOrganization(), "PROJECT_1"));
-    userSession.addComponentUuidPermission(UserRole.USER, "PROJECT_1", "PROJECT_1");
+    ComponentDto project = dbTester.components().insertComponent(newProjectDto(dbTester.getDefaultOrganization(), "PROJECT_1"));
+    userSession.addProjectPermission(UserRole.USER, project);
     insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
     insertActivity("T2", "PROJECT_2", CeActivityDto.Status.FAILED);
     insertActivity("T3", "PROJECT_1", CeActivityDto.Status.SUCCESS);
@@ -130,8 +130,6 @@ public class ComponentActionTest {
 
   @Test
   public void fail_with_404_when_component_does_not_exist() throws Exception {
-    userSession.addComponentUuidPermission(UserRole.USER, "PROJECT_1", "PROJECT_1");
-
     expectedException.expect(NotFoundException.class);
     ws.newRequest()
       .setParam("componentId", "UNKNOWN")
@@ -161,7 +159,7 @@ public class ComponentActionTest {
   }
 
   private void logInWithBrowsePermission(ComponentDto project) {
-    userSession.logIn().addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.USER, project);
   }
 
   private CeQueueDto insertQueue(String taskUuid, String componentUuid, CeQueueDto.Status status) {
index 99aa93b072ad978b901a26a3ce1c7ab25478a0ae..1380ec2eb123c0727085721847eaaef20685ae3b 100644 (file)
@@ -218,7 +218,7 @@ public class TaskActionTest {
 
   @Test
   public void get_project_queue_task_with_scan_permission_on_project() {
-    userSession.logIn().addProjectUuidPermissions(GlobalPermissions.SCAN_EXECUTION, project.uuid());
+    userSession.logIn().addProjectPermission(GlobalPermissions.SCAN_EXECUTION, project);
     CeQueueDto task = createAndPersistQueueTask(project);
 
     call(task.getUuid());
@@ -262,7 +262,7 @@ public class TaskActionTest {
 
   @Test
   public void get_project_archived_task_with_scan_permission_on_project() {
-    userSession.logIn().addProjectUuidPermissions(GlobalPermissions.SCAN_EXECUTION, project.uuid());
+    userSession.logIn().addProjectPermission(GlobalPermissions.SCAN_EXECUTION, project);
     CeActivityDto task = createAndPersistArchivedTask(project);
 
     call(task.getUuid());
index 204698c958b15ed2d78f21dc0d0e93ab3eacf673..1fc5f7f6993124e209920c897915d1220c72e0b5 100644 (file)
@@ -123,7 +123,7 @@ public class ComponentServiceUpdateKeyTest {
     expectedException.expect(ForbiddenException.class);
 
     ComponentDto project = insertSampleRootProject();
-    userSession.logIn("john").addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.logIn("john").addProjectPermission(UserRole.USER, project);
 
     underTest.updateKey(dbSession, project, "sample2:root");
   }
@@ -215,6 +215,6 @@ public class ComponentServiceUpdateKeyTest {
   }
 
   private void logInAsProjectAdministrator(ComponentDto provisionedProject) {
-    userSession.logIn("john").addProjectUuidPermissions(UserRole.ADMIN, provisionedProject.uuid());
+    userSession.logIn("john").addProjectPermission(UserRole.ADMIN, provisionedProject);
   }
 }
index 347565c86dae162295861acbea623c301b66bf53..0de565d501fed03aae5dbf8e1cf5b5b56c2d9bd1 100644 (file)
@@ -80,17 +80,17 @@ public class AppActionTest {
 
   @Test
   public void file_without_measures() throws Exception {
-    insertComponentsAndAnalysis();
+    ComponentDto[] components = insertComponentsAndAnalysis();
     dbTester.commit();
 
-    userSessionRule.logIn("john").addComponentUuidPermission(UserRole.USER, PROJECT_UUID, FILE_UUID);
+    userSessionRule.logIn("john").addProjectPermission(UserRole.USER, components);
     TestRequest request = wsTester.newRequest().setParam("uuid", FILE_UUID);
     jsonAssert(request, "app.json");
   }
 
   @Test
   public void file_with_measures() throws Exception {
-    insertComponentsAndAnalysis();
+    ComponentDto[] components = insertComponentsAndAnalysis();
     insertFileMeasure(metricsByKey.get(LINES_KEY).getId(), 200d, null);
     insertFileMeasure(metricsByKey.get(DUPLICATED_LINES_DENSITY_KEY).getId(), 7.4, null);
     insertFileMeasure(metricsByKey.get(SQALE_RATING_KEY).getId(), null, "C");
@@ -101,18 +101,19 @@ public class AppActionTest {
 
     userSessionRule
       .logIn("john")
-      .addComponentUuidPermission(UserRole.USER, PROJECT_UUID, FILE_UUID);
+      .addProjectPermission(UserRole.USER, components);
     TestRequest request = wsTester.newRequest().setParam("uuid", FILE_UUID);
     jsonAssert(request, "app_with_measures.json");
   }
 
   @Test
   public void file_with_coverage() throws Exception {
-    insertComponentsAndAnalysis();
+    ComponentDto[] components = insertComponentsAndAnalysis();
     insertFileMeasure(metricsByKey.get(COVERAGE_KEY).getId(), 95.4, null);
     dbTester.commit();
 
-    userSessionRule.logIn("john").addComponentUuidPermission(UserRole.USER, PROJECT_UUID, FILE_UUID);
+    userSessionRule.logIn("john")
+      .addProjectPermission(UserRole.USER, components);
     TestRequest request = wsTester.newRequest().setParam("uuid", FILE_UUID);
     jsonAssert(request, "app_with_ut_measure.json");
   }
@@ -137,7 +138,7 @@ public class AppActionTest {
     dbTester.commit();
   }
 
-  private void insertComponentsAndAnalysis() {
+  private ComponentDto[] insertComponentsAndAnalysis() {
     ComponentDto project = ComponentTesting.newProjectDto(dbTester.getDefaultOrganization(), PROJECT_UUID)
       .setLongName("SonarQube")
       .setKey(PROJECT_KEY);
@@ -152,6 +153,7 @@ public class AppActionTest {
     dbTester.getDbClient().componentDao().insert(dbTester.getSession(), project, module, file);
     SnapshotDto analysis = SnapshotTesting.newAnalysis(project).setUuid(ANALYSIS_UUID);
     dbTester.getDbClient().snapshotDao().insert(dbTester.getSession(), analysis);
+    return new ComponentDto[] {project, module, file};
   }
 
   private void insertFileMeasure(int metricId, @Nullable Double value, @Nullable String data) {
index c431c791837e79607bd3df838c14e18b61afc12c..55861bb473f35be4e687acf84a4411e0d0a6c729 100644 (file)
@@ -93,8 +93,9 @@ public class ShowActionTest {
 
   @Test
   public void show_with_browse_permission() {
-    userSession.logIn().addProjectUuidPermissions(UserRole.USER, "project-uuid");
-    componentDb.insertProjectAndSnapshot(newProjectDto(db.organizations().insert(), "project-uuid"));
+    ComponentDto project = newProjectDto(db.organizations().insert(), "project-uuid");
+    componentDb.insertProjectAndSnapshot(project);
+    userSession.logIn().addProjectPermission(UserRole.USER, project);
 
     ShowWsResponse response = newRequest("project-uuid", null);
 
@@ -118,7 +119,7 @@ public class ShowActionTest {
     ComponentDto module = componentDb.insertComponent(newModuleDto(project));
     ComponentDto directory = componentDb.insertComponent(newDirectory(module, "dir"));
     ComponentDto file = componentDb.insertComponent(newFileDto(directory));
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
 
     ShowWsResponse response = newRequest(null, file.key());
 
@@ -130,7 +131,7 @@ public class ShowActionTest {
   public void show_without_ancestors_when_project() throws Exception {
     ComponentDto project = componentDb.insertProject();
     componentDb.insertComponent(newModuleDto(project));
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
 
     ShowWsResponse response = newRequest(null, project.key());
 
@@ -144,7 +145,7 @@ public class ShowActionTest {
     componentDb.insertSnapshot(newAnalysis(project).setCreatedAt(1_000_000_000L).setLast(false));
     componentDb.insertSnapshot(newAnalysis(project).setCreatedAt(2_000_000_000L).setLast(false));
     componentDb.insertSnapshot(newAnalysis(project).setCreatedAt(3_000_000_000L).setLast(true));
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
 
     ShowWsResponse response = newRequest(null, project.key());
 
@@ -158,7 +159,7 @@ public class ShowActionTest {
     ComponentDto module = componentDb.insertComponent(newModuleDto(project));
     ComponentDto directory = componentDb.insertComponent(newDirectory(module, "dir"));
     ComponentDto file = componentDb.insertComponent(newFileDto(directory));
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
 
     ShowWsResponse response = newRequest(null, file.key());
 
index 1518d9ed2202a077a752f676863950aab9af3c70..f47c7508ca4ce56fef98707588a8a53ce324c1f5 100644 (file)
@@ -300,9 +300,9 @@ public class TreeActionTest {
 
   @Test
   public void fail_when_not_enough_privileges() {
+    ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid"));
     userSession.logIn()
-      .addProjectUuidPermissions(UserRole.CODEVIEWER, "project-uuid");
-    componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid"));
+      .addProjectPermission(UserRole.CODEVIEWER, project);
     db.commit();
 
     expectedException.expect(ForbiddenException.class);
@@ -424,6 +424,6 @@ public class TreeActionTest {
   }
 
   private void logInWithBrowsePermission(ComponentDto project) {
-    userSession.logIn().addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.USER, project);
   }
 }
index 8f7a1c80ec5fa5732a172736f95c1e2f4f71a0bd..89b050617864670acbbfc9897ddd5d8785acba0c 100644 (file)
@@ -36,7 +36,9 @@ import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.ce.CeTaskTypes;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
 import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.permission.OrganizationPermission;
 import org.sonar.server.component.ComponentUpdater;
 import org.sonar.server.component.NewComponent;
 import org.sonar.server.exceptions.ForbiddenException;
@@ -110,7 +112,7 @@ public class ReportSubmitterTest {
   @Test
   public void submit_a_report_on_existing_project() {
     ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
-    userSession.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
+    userSession.logIn().addProjectPermission(SCAN_EXECUTION, project);
 
     mockSuccessfulPrepareSubmitCall();
 
@@ -137,7 +139,7 @@ public class ReportSubmitterTest {
   public void provision_project_if_does_not_exist() throws Exception {
     OrganizationDto organization = db.organizations().insert();
     userSession
-      .addProjectUuidPermissions(SCAN_EXECUTION, PROJECT_UUID)
+      .addPermission(OrganizationPermission.SCAN, organization.getUuid())
       .addPermission(PROVISION_PROJECTS, organization);
 
     mockSuccessfulPrepareSubmitCall();
@@ -168,7 +170,7 @@ public class ReportSubmitterTest {
   @Test
   public void no_favorite_when_no_project_creator_permission_on_permission_template() {
     userSession
-      .addProjectUuidPermissions(SCAN_EXECUTION, PROJECT_UUID)
+      .addPermission(OrganizationPermission.SCAN, db.getDefaultOrganization().getUuid())
       .addPermission(PROVISION_PROJECTS, db.getDefaultOrganization());
 
     mockSuccessfulPrepareSubmitCall();
@@ -187,7 +189,7 @@ public class ReportSubmitterTest {
   @Test
   public void submit_a_report_on_new_project_with_scan_permission_on_organization() {
     userSession
-      .addProjectUuidPermissions(SCAN_EXECUTION, PROJECT_UUID)
+      .addPermission(OrganizationPermission.SCAN, db.getDefaultOrganization().getUuid())
       .addPermission(PROVISION_PROJECTS, db.getDefaultOrganization());
 
     mockSuccessfulPrepareSubmitCall();
@@ -218,7 +220,7 @@ public class ReportSubmitterTest {
   @Test
   public void submit_a_report_on_existing_project_with_project_scan_permission() {
     ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
-    userSession.addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
+    userSession.addProjectPermission(SCAN_EXECUTION, project);
 
     mockSuccessfulPrepareSubmitCall();
 
@@ -236,7 +238,7 @@ public class ReportSubmitterTest {
 
   @Test
   public void fail_with_forbidden_exception_on_new_project_when_only_project_scan_permission() {
-    userSession.addProjectUuidPermissions(SCAN_EXECUTION, PROJECT_UUID);
+    userSession.addProjectPermission(SCAN_EXECUTION, ComponentTesting.newProjectDto(db.getDefaultOrganization(), PROJECT_UUID));
 
     mockSuccessfulPrepareSubmitCall();
     when(componentUpdater.create(any(DbSession.class), any(NewComponent.class), eq(null))).thenReturn(new ComponentDto().setUuid(PROJECT_UUID).setKey(PROJECT_KEY));
@@ -251,7 +253,7 @@ public class ReportSubmitterTest {
   @Test
   public void project_branch_must_not_benefit_from_the_scan_permission_on_main_project() {
     ComponentDto mainProject = db.components().insertProject();
-    userSession.addProjectUuidPermissions(GlobalPermissions.SCAN_EXECUTION, mainProject.uuid());
+    userSession.addProjectPermission(GlobalPermissions.SCAN_EXECUTION, mainProject);
 
     // user does not have the "scan" permission on the branch, so it can't scan it
     String branchName = "branchFoo";
index 9d7c0c78c5d5b90e1cac97b78518db8b82d69fbd..e6cacf51b6e3ba72e41301e19c74209099796018 100644 (file)
@@ -83,7 +83,7 @@ public class ShowActionTest {
     ComponentDto file = db.components().insertComponent(newFileDto(project).setKey("foo.js"));
     db.components().insertSnapshot(newAnalysis(project));
 
-    userSessionRule.addProjectUuidPermissions(UserRole.CODEVIEWER, project.uuid());
+    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project);
 
     WsTester.Result result = newBaseRequest().setParam("key", file.key()).execute();
 
@@ -127,7 +127,7 @@ public class ShowActionTest {
     db.getDbClient().measureDao().insert(db.getSession(), newMeasureDto(dataMetric, file, snapshot).setData(xml));
     db.commit();
 
-    userSessionRule.addProjectUuidPermissions(UserRole.CODEVIEWER, project.uuid());
+    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project);
 
     WsTester.TestRequest request = requestFactory.apply(file);
     WsTester.Result result = request.execute();
index 4ce86209eef31ba5a08640b933cee0df9209ff87..84130b7b27733644c25f1c92d7211c5436567f7e 100644 (file)
@@ -88,7 +88,7 @@ public class AddActionTest {
   public void add_a_file() {
     ComponentDto project = insertProjectAndPermissions();
     ComponentDto file = db.components().insertComponent(newFileDto(project));
-    userSession.addComponentUuidPermission(UserRole.USER, PROJECT_UUID, file.uuid());
+    userSession.addProjectPermission(UserRole.USER, project, file);
 
     call(file.key());
 
@@ -105,9 +105,9 @@ public class AddActionTest {
 
   @Test
   public void fail_when_no_browse_permission_on_the_project() {
-    insertProject();
+    ComponentDto project = insertProject();
     userSession.logIn();
-    userSession.addProjectUuidPermissions(UserRole.ADMIN, PROJECT_UUID);
+    userSession.addProjectPermission(UserRole.ADMIN, project);
 
     expectedException.expect(ForbiddenException.class);
 
@@ -146,12 +146,13 @@ public class AddActionTest {
   }
 
   private ComponentDto insertProjectAndPermissions() {
+    ComponentDto project = insertProject();
     userSession
       .logIn()
       .setUserId(USER_ID)
-      .addProjectUuidPermissions(UserRole.USER, PROJECT_UUID);
+      .addProjectPermission(UserRole.USER, project);
 
-    return insertProject();
+    return project;
   }
 
   private TestResponse call(@Nullable String componentKey) {
index b5941fd91f984df1d76c05c8602cb45e553e1ff8..2d3ea708c08f93a3c06e4a5ab934de1e9f349799 100644 (file)
@@ -23,6 +23,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
 import org.sonar.db.issue.IssueDto;
 import org.sonar.db.organization.OrganizationTesting;
 import org.sonar.server.tester.UserSessionRule;
@@ -60,7 +61,7 @@ public class ActionFinderTest {
 
   @Test
   public void return_provided_actions_with_set_severity_and_set_type_when_issue_admin() {
-    userSession.addProjectUuidPermissions(ISSUE_ADMIN, PROJECT_UUID);
+    userSession.addProjectPermission(ISSUE_ADMIN, ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto(), PROJECT_UUID));
     assertThat(underTest.listAvailableActions(issue)).containsOnly("comment", "assign", "set_tags", "set_type", "assign_to_me", "set_severity");
   }
 
index 464d94b685a178fec935781289c60fccfa1030a6..bc3f00546e364d38e623917123e58f5130417363 100644 (file)
@@ -61,7 +61,8 @@ public class IssueFinderTest {
   @Test
   public void get_by_issue_key() throws Exception {
     IssueDto issueDto = insertIssue();
-    userSession.addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    String permission = USER;
+    addProjectPermission(issueDto, permission);
 
     IssueDto result = underTest.getByKey(db.getSession(), issueDto.getKey());
 
@@ -72,7 +73,7 @@ public class IssueFinderTest {
   @Test
   public void fail_when_issue_key_does_not_exist() throws Exception {
     IssueDto issueDto = insertIssue();
-    userSession.addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    addProjectPermission(issueDto, USER);
 
     expectedException.expect(NotFoundException.class);
     expectedException.expectMessage("Issue with key 'UNKNOWN' does not exist");
@@ -82,7 +83,7 @@ public class IssueFinderTest {
   @Test
   public void fail_when_not_enough_permission() throws Exception {
     IssueDto issueDto = insertIssue();
-    userSession.addProjectUuidPermissions(CODEVIEWER, issueDto.getProjectUuid());
+    addProjectPermission(issueDto, CODEVIEWER);
 
     expectedException.expect(ForbiddenException.class);
     underTest.getByKey(db.getSession(), issueDto.getKey());
@@ -94,4 +95,8 @@ public class IssueFinderTest {
     ComponentDto file = componentDbTester.insertComponent(newFileDto(project));
     return issueDbTester.insertIssue(newDto(rule, file, project));
   }
+
+  private void addProjectPermission(IssueDto issueDto, String permission) {
+    userSession.addProjectPermission(permission, db.getDbClient().componentDao().selectByUuid(db.getSession(), issueDto.getProjectUuid()).get());
+  }
 }
index 294ab90c868f4371113241cc7534c93587478923..7f2c1285656f1e944d7773acb52f9a72163cd09e 100644 (file)
@@ -192,7 +192,7 @@ public class IssueQueryFactoryTest {
     ComponentDto view = db.components().insertView();
     SearchWsRequest request = new SearchWsRequest()
       .setComponentRootUuids(asList(view.uuid()));
-    userSession.addProjectUuidPermissions(UserRole.USER, view.uuid());
+    userSession.addProjectPermission(UserRole.USER, view);
 
     IssueQuery query = underTest.create(request);
 
index b2f04caedd9e7648e927a0201114bcc17f744f92..6a24e75d3b6da1838b506f07dc1bd030e25ffde1 100644 (file)
@@ -155,7 +155,7 @@ public class IssueServiceMediumTest {
     ComponentDto project = ComponentTesting.newProjectDto(organization);
     tester.get(ComponentDao.class).insert(session, project);
 
-    userSessionRule.logIn().addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSessionRule.logIn().addProjectPermission(UserRole.USER, project);
     session.commit();
 
     // project can be seen by group "anyone"
index 914ae6fffb10e03ca91b32dc80acfc0da4cb2dce..15a80439331df3c136b7341154c8056e8eb82bb8 100644 (file)
@@ -67,8 +67,9 @@ public class SetSeverityActionTest {
 
   @Test
   public void set_severity() {
-    DefaultIssue issue = newIssue().setSeverity(MAJOR).toDefaultIssue();
-    setUserWithBrowseAndAdministerIssuePermission(issue.projectUuid());
+    IssueDto issueDto = newIssue().setSeverity(MAJOR);
+    DefaultIssue issue = issueDto.toDefaultIssue();
+    setUserWithBrowseAndAdministerIssuePermission(issueDto);
     BulkChangeAction.ActionContext context = new BulkChangeAction.ActionContext(issue, IssueChangeContext.createUser(NOW, userSession.getLogin()), null);
 
     action.execute(ImmutableMap.of("severity", MINOR), context);
@@ -93,8 +94,9 @@ public class SetSeverityActionTest {
 
   @Test
   public void support_only_unresolved_issues() {
-    DefaultIssue issue = newIssue().setSeverity(MAJOR).toDefaultIssue();
-    setUserWithBrowseAndAdministerIssuePermission(issue.projectUuid());
+    IssueDto issueDto = newIssue().setSeverity(MAJOR);
+    DefaultIssue issue = issueDto.toDefaultIssue();
+    setUserWithBrowseAndAdministerIssuePermission(issueDto);
 
     assertThat(action.supports(issue.setResolution(null))).isTrue();
     assertThat(action.supports(issue.setResolution(Issue.RESOLUTION_FIXED))).isFalse();
@@ -102,18 +104,20 @@ public class SetSeverityActionTest {
 
   @Test
   public void support_only_issues_with_issue_admin_permission() {
-    DefaultIssue authorizedIssue = newIssue().setSeverity(MAJOR).toDefaultIssue();
-    setUserWithBrowseAndAdministerIssuePermission(authorizedIssue.projectUuid());
-    DefaultIssue unauthorizedIssue = newIssue().setSeverity(MAJOR).toDefaultIssue();
+    IssueDto authorizedIssue = newIssue().setSeverity(MAJOR);
+    setUserWithBrowseAndAdministerIssuePermission(authorizedIssue);
+    IssueDto unauthorizedIssue = newIssue().setSeverity(MAJOR);
 
-    assertThat(action.supports(authorizedIssue.setResolution(null))).isTrue();
-    assertThat(action.supports(unauthorizedIssue.setResolution(null))).isFalse();
+    assertThat(action.supports(authorizedIssue.toDefaultIssue().setResolution(null))).isTrue();
+    assertThat(action.supports(unauthorizedIssue.toDefaultIssue().setResolution(null))).isFalse();
   }
 
-  private void setUserWithBrowseAndAdministerIssuePermission(String projectUuid) {
+  private void setUserWithBrowseAndAdministerIssuePermission(IssueDto issue) {
+    ComponentDto project = db.getDbClient().componentDao().selectByUuid(db.getSession(), issue.getProjectUuid()).get();
+    ComponentDto component = db.getDbClient().componentDao().selectByUuid(db.getSession(), issue.getComponentUuid()).get();
     userSession.logIn(USER_LOGIN)
-      .addProjectUuidPermissions(ISSUE_ADMIN, projectUuid)
-      .addProjectUuidPermissions(USER, projectUuid);
+      .addProjectPermission(ISSUE_ADMIN, project, component)
+      .addProjectPermission(USER, project, component);
   }
 
   private IssueDto newIssue() {
index 4ff0e5d8f6b1b950e239d19fbaeb0f2aa54ab653..f08d793deb8fd7529a5b4b52c443b560ee9df602 100644 (file)
@@ -66,8 +66,9 @@ public class SetTypeActionTest {
 
   @Test
   public void set_type() {
-    DefaultIssue issue = newIssue().setType(BUG).toDefaultIssue();
-    setUserWithBrowseAndAdministerIssuePermission(issue.projectUuid());
+    IssueDto issueDto = newIssue().setType(BUG);
+    DefaultIssue issue = issueDto.toDefaultIssue();
+    setUserWithBrowseAndAdministerIssuePermission(issueDto);
 
     action.execute(ImmutableMap.of("type", VULNERABILITY.name()),
       new BulkChangeAction.ActionContext(issue, IssueChangeContext.createUser(NOW, userSession.getLogin()), null));
@@ -99,8 +100,9 @@ public class SetTypeActionTest {
 
   @Test
   public void support_only_unresolved_issues() {
-    DefaultIssue issue = newIssue().setType(BUG).toDefaultIssue();
-    setUserWithBrowseAndAdministerIssuePermission(issue.projectUuid());
+    IssueDto issueDto = newIssue().setType(BUG);
+    DefaultIssue issue = issueDto.toDefaultIssue();
+    setUserWithBrowseAndAdministerIssuePermission(issueDto);
 
     assertThat(action.supports(issue.setResolution(null))).isTrue();
     assertThat(action.supports(issue.setResolution(Issue.RESOLUTION_FIXED))).isFalse();
@@ -108,18 +110,21 @@ public class SetTypeActionTest {
 
   @Test
   public void support_only_issues_with_issue_admin_permission() {
-    DefaultIssue authorizedIssue = newIssue().setType(BUG).toDefaultIssue();
-    setUserWithBrowseAndAdministerIssuePermission(authorizedIssue.projectUuid());
+    IssueDto authorizedIssueDto = newIssue().setType(BUG);
+    DefaultIssue authorizedIssue = authorizedIssueDto.toDefaultIssue();
+    setUserWithBrowseAndAdministerIssuePermission(authorizedIssueDto);
     DefaultIssue unauthorizedIssue = newIssue().setType(BUG).toDefaultIssue();
 
     assertThat(action.supports(authorizedIssue.setResolution(null))).isTrue();
     assertThat(action.supports(unauthorizedIssue.setResolution(null))).isFalse();
   }
 
-  private void setUserWithBrowseAndAdministerIssuePermission(String projectUuid) {
+  private void setUserWithBrowseAndAdministerIssuePermission(IssueDto issueDto) {
+    ComponentDto project = db.getDbClient().componentDao().selectByUuid(db.getSession(), issueDto.getProjectUuid()).get();
+    ComponentDto component = db.getDbClient().componentDao().selectByUuid(db.getSession(), issueDto.getComponentUuid()).get();
     userSession.logIn(USER_LOGIN)
-      .addProjectUuidPermissions(ISSUE_ADMIN, projectUuid)
-      .addProjectUuidPermissions(USER, projectUuid);
+      .addProjectPermission(ISSUE_ADMIN, project, component)
+      .addProjectPermission(USER, project, component);
   }
 
   private IssueDto newIssue() {
index 598033a10637a5b44350ae5ad7bae94f59cb34ee..d73a3e066eecc5092fb003b0f12e18d3872b427a 100644 (file)
@@ -73,7 +73,7 @@ public class TransitionActionTest {
 
   @Test
   public void execute() {
-    userSession.logIn("john").addProjectUuidPermissions(ISSUE_ADMIN, issue.projectUuid());
+    loginAndAddProjectPermission("john", ISSUE_ADMIN);
     issue.setStatus(Issue.STATUS_RESOLVED);
     issue.setResolution(Issue.RESOLUTION_FIXED);
 
@@ -85,7 +85,7 @@ public class TransitionActionTest {
 
   @Test
   public void does_not_execute_if_transition_is_not_available() {
-    userSession.logIn("john").addProjectUuidPermissions(ISSUE_ADMIN, issue.projectUuid());
+    loginAndAddProjectPermission("john", ISSUE_ADMIN);
     issue.setStatus(Issue.STATUS_CLOSED);
 
     action.execute(ImmutableMap.of("transition", "reopen"), context);
@@ -119,4 +119,8 @@ public class TransitionActionTest {
     return newDto(rule, file, project);
   }
 
+  private void loginAndAddProjectPermission(String login, String permission) {
+    userSession.logIn(login).addProjectPermission(permission, ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto(), issue.projectUuid()));
+  }
+
 }
index d01e22e84b9375d69eecb585c201d132e060b4d2..68690ec21a97449939c2e1c43680c1259676e218 100644 (file)
@@ -62,7 +62,7 @@ public class TransitionServiceTest {
   @Test
   public void list_transitions() throws Exception {
     IssueDto issue = newIssue().setStatus(STATUS_OPEN).setResolution(null);
-    userSession.logIn("john").addProjectUuidPermissions(ISSUE_ADMIN, issue.getProjectUuid());
+    userSession.logIn("john").addProjectPermission(ISSUE_ADMIN, ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto(), issue.getProjectUuid()));
 
     List<Transition> result = underTest.listTransitions(issue.toDefaultIssue());
 
index 167bf3dc0f2cf144f59b0a55c64275841f5cb554..45c5f5bd814d7b25ac021ff00e4b23d607b445bf 100644 (file)
@@ -105,7 +105,7 @@ public class AddCommentActionTest {
   @Test
   public void add_comment() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue();
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    loginWithBrowsePermission(issueDto, USER);
 
     call(issueDto.getKey(), "please fix it");
 
@@ -151,7 +151,7 @@ public class AddCommentActionTest {
   @Test
   public void fail_when_empty_comment_text() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue();
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    loginWithBrowsePermission(issueDto, USER);
 
     expectedException.expect(IllegalArgumentException.class);
     call(issueDto.getKey(), "");
@@ -166,7 +166,7 @@ public class AddCommentActionTest {
   @Test
   public void fail_when_not_enough_permission() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue();
-    userSession.logIn("john").addProjectUuidPermissions(CODEVIEWER, issueDto.getProjectUuid());
+    loginWithBrowsePermission(issueDto, CODEVIEWER);
 
     expectedException.expect(ForbiddenException.class);
     call(issueDto.getKey(), "please fix it");
@@ -189,4 +189,10 @@ public class AddCommentActionTest {
     return request.execute();
   }
 
+  private void loginWithBrowsePermission(IssueDto issueDto, String permission) {
+    userSession.logIn("john").addProjectPermission(permission,
+      dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getProjectUuid()).get(),
+      dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getComponentUuid()).get());
+  }
+
 }
index cac29c2121d2a69efaceaa23029797fe1332e8db..88fac14b25f5aec60eac28a4ebd904cbfe4795e4 100644 (file)
@@ -69,13 +69,10 @@ public class AssignActionTest {
 
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
-
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
-
   @Rule
   public EsTester es = new EsTester(new IssueIndexDefinition(new MapSettings()));
-
   @Rule
   public DbTester db = DbTester.create(system2);
 
@@ -211,7 +208,7 @@ public class AssignActionTest {
   @Test
   public void fail_when_missing_browse_permission() throws Exception {
     IssueDto issue = newIssue();
-    userSession.logIn(CURRENT_USER_LOGIN).addProjectUuidPermissions(CODEVIEWER, issue.getProjectUuid());
+    setUserWithPermission(issue, CODEVIEWER);
 
     expectedException.expect(ForbiddenException.class);
 
@@ -246,11 +243,12 @@ public class AssignActionTest {
   }
 
   private IssueDto newIssue() {
-    return db.issues().insertIssue(
+    IssueDto issue = db.issues().insertIssue(
       issueDto -> issueDto
         .setAssignee(PREVIOUS_ASSIGNEE)
         .setCreatedAt(PAST).setIssueCreationTime(PAST)
         .setUpdatedAt(PAST).setIssueUpdateTime(PAST));
+    return issue;
   }
 
   private IssueDto newIssueWithBrowsePermission() {
@@ -260,8 +258,15 @@ public class AssignActionTest {
   }
 
   private void setUserWithBrowsePermission(IssueDto issue) {
+    setUserWithPermission(issue, USER);
+  }
+
+  private void setUserWithPermission(IssueDto issue, String permission) {
     insertUser(CURRENT_USER_LOGIN);
-    userSession.logIn(CURRENT_USER_LOGIN).addProjectUuidPermissions(USER, issue.getProjectUuid());
+    userSession.logIn(CURRENT_USER_LOGIN)
+      .addProjectPermission(permission,
+        db.getDbClient().componentDao().selectByUuid(db.getSession(), issue.getProjectUuid()).get(),
+        db.getDbClient().componentDao().selectByUuid(db.getSession(), issue.getComponentUuid()).get());
   }
 
   private void checkIssueAssignee(String issueKey, @Nullable String expectedAssignee) {
index 009b960bee86c42e3b76400f979252b19423abbf..b7d328f46746161ae1219ef63413d40dea35f2cf 100644 (file)
@@ -487,7 +487,7 @@ public class BulkChangeActionTest {
   private void addUserProjectPermissions(ComponentDto project, String... permissions) {
     for (String permission : permissions) {
       db.users().insertProjectPermissionOnUser(user, permission, project);
-      userSession.addProjectUuidPermissions(permission, project.uuid());
+      userSession.addProjectPermission(permission, project);
     }
   }
 
index 792059432fb10bbe920a7edf874ae938d563f90e..9e7c07db3832e05dc557bfc366144c090dc84641 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.server.issue.ws;
 
 import javax.annotation.Nullable;
+import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -63,13 +64,21 @@ public class ChangelogActionTest {
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
 
+  private ComponentDto project;
+  private ComponentDto file;
   private WsActionTester tester = new WsActionTester(new ChangelogAction(db.getDbClient(), new IssueFinder(db.getDbClient(), userSession), new AvatarResolverImpl()));
 
+  @Before
+  public void setUp() throws Exception {
+    project = db.components().insertProject();
+    file = db.components().insertComponent(newFileDto(project));
+  }
+
   @Test
   public void return_changelog() throws Exception {
     UserDto user = insertUser();
     IssueDto issueDto = db.issues().insertIssue(newIssue());
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    userSession.logIn("john").addProjectPermission(USER, project, file);
     db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", "MAJOR", "BLOCKER"));
 
     ChangelogWsResponse result = call(issueDto.getKey());
@@ -89,7 +98,7 @@ public class ChangelogActionTest {
     ComponentDto file1 = db.components().insertComponent(newFileDto(project));
     ComponentDto file2 = db.components().insertComponent(newFileDto(project));
     IssueDto issueDto = db.issues().insertIssue(newDto(rule, file2, project));
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    userSession.logIn("john").addProjectPermission(USER, project, file1, file2);
     db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setDiff("file", file1.uuid(), file2.uuid()));
 
     ChangelogWsResponse result = call(issueDto.getKey());
@@ -104,7 +113,7 @@ public class ChangelogActionTest {
   @Test
   public void changelog_of_file_move_is_empty_when_files_does_not_exists() throws Exception {
     IssueDto issueDto = db.issues().insertIssue(newIssue());
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    userSession.logIn("john").addProjectPermission(USER, project, file);
     db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setDiff("file", "UNKNOWN_1", "UNKNOWN_2"));
 
     ChangelogWsResponse result = call(issueDto.getKey());
@@ -118,7 +127,7 @@ public class ChangelogActionTest {
   public void return_changelog_on_user_without_email() throws Exception {
     UserDto user = db.users().insertUser(UserTesting.newUserDto("john", "John", null));
     IssueDto issueDto = db.issues().insertIssue(newIssue());
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    userSession.logIn("john").addProjectPermission(USER, project, file);
     db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", "MAJOR", "BLOCKER"));
 
     ChangelogWsResponse result = call(issueDto.getKey());
@@ -132,7 +141,7 @@ public class ChangelogActionTest {
   @Test
   public void return_changelog_not_having_user() throws Exception {
     IssueDto issueDto = db.issues().insertIssue(newIssue());
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    userSession.logIn("john").addProjectPermission(USER, project, file);
     db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(null).setDiff("severity", "MAJOR", "BLOCKER"));
 
     ChangelogWsResponse result = call(issueDto.getKey());
@@ -147,7 +156,7 @@ public class ChangelogActionTest {
   @Test
   public void return_changelog_on_none_existing_user() throws Exception {
     IssueDto issueDto = db.issues().insertIssue(newIssue());
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    userSession.logIn("john").addProjectPermission(USER, project, file);
     db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin("UNKNOWN").setDiff("severity", "MAJOR", "BLOCKER"));
 
     ChangelogWsResponse result = call(issueDto.getKey());
@@ -163,7 +172,7 @@ public class ChangelogActionTest {
   public void return_multiple_diffs() throws Exception {
     UserDto user = insertUser();
     IssueDto issueDto = db.issues().insertIssue(newIssue());
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    userSession.logIn("john").addProjectPermission(USER, project, file);
     db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", "MAJOR", "BLOCKER").setDiff("status", "RESOLVED", "CLOSED"));
 
     ChangelogWsResponse result = call(issueDto.getKey());
@@ -177,7 +186,7 @@ public class ChangelogActionTest {
   public void return_changelog_when_no_old_value() throws Exception {
     UserDto user = insertUser();
     IssueDto issueDto = db.issues().insertIssue(newIssue());
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    userSession.logIn("john").addProjectPermission(USER, project, file);
     db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", null, "BLOCKER"));
 
     ChangelogWsResponse result = call(issueDto.getKey());
@@ -190,7 +199,7 @@ public class ChangelogActionTest {
   public void return_changelog_when_no_new_value() throws Exception {
     UserDto user = insertUser();
     IssueDto issueDto = db.issues().insertIssue(newIssue());
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    userSession.logIn("john").addProjectPermission(USER, project, file);
     db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", "MAJOR", null));
 
     ChangelogWsResponse result = call(issueDto.getKey());
@@ -203,7 +212,7 @@ public class ChangelogActionTest {
   public void return_many_changelog() throws Exception {
     UserDto user = insertUser();
     IssueDto issueDto = db.issues().insertIssue(newIssue());
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    userSession.logIn("john").addProjectPermission(USER, project, file);
     db.issues().insertFieldDiffs(issueDto,
       new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", "MAJOR", "BLOCKER"),
       new FieldDiffs().setDiff("status", "RESOLVED", "CLOSED"));
@@ -217,7 +226,7 @@ public class ChangelogActionTest {
   public void replace_technical_debt_key_by_effort() throws Exception {
     UserDto user = insertUser();
     IssueDto issueDto = db.issues().insertIssue(newIssue());
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    userSession.logIn("john").addProjectPermission(USER, project, file);
     db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("technicalDebt", "10", "20"));
 
     ChangelogWsResponse result = call(issueDto.getKey());
@@ -229,7 +238,7 @@ public class ChangelogActionTest {
   @Test
   public void return_empty_changelog_when_no_changes_on_issue() {
     IssueDto issueDto = db.issues().insertIssue(newIssue());
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    userSession.logIn("john").addProjectPermission(USER, project, file);
 
     ChangelogWsResponse result = call(issueDto.getKey());
 
@@ -239,7 +248,7 @@ public class ChangelogActionTest {
   @Test
   public void fail_when_not_enough_permission() {
     IssueDto issueDto = db.issues().insertIssue(newIssue());
-    userSession.logIn("john").addProjectUuidPermissions(CODEVIEWER, issueDto.getProjectUuid());
+    userSession.logIn("john").addProjectPermission(CODEVIEWER, project, file);
 
     expectedException.expect(ForbiddenException.class);
     call(issueDto.getKey());
@@ -249,7 +258,7 @@ public class ChangelogActionTest {
   public void test_example() throws Exception {
     UserDto user = db.users().insertUser(newUserDto("john.smith", "John Smith", "john@smith.com"));
     IssueDto issueDto = db.issues().insertIssue(newIssue());
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    userSession.logIn("john").addProjectPermission(USER, project, file);
     db.issues().insertFieldDiffs(issueDto, new FieldDiffs()
       .setUserLogin(user.getLogin())
       .setDiff("severity", "MAJOR", "BLOCKER")
@@ -278,8 +287,6 @@ public class ChangelogActionTest {
 
   private IssueDto newIssue() {
     RuleDto rule = db.rules().insertRule(newRuleDto());
-    ComponentDto project = db.components().insertProject();
-    ComponentDto file = db.components().insertComponent(newFileDto(project));
     return newDto(rule, file, project);
   }
 
index 24a8d3798fd9c3c96b23174f8f8c5e75d1760159..d3d3770c096bc8da09272b356f4615fde1877451 100644 (file)
@@ -73,7 +73,7 @@ public class DeleteCommentActionTest {
   public void delete_comment() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue();
     IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    loginAndAddProjectPermission("john", issueDto, USER);
 
     call(commentDto.getKey());
 
@@ -85,7 +85,7 @@ public class DeleteCommentActionTest {
   public void delete_comment_using_deprecated_key_parameter() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue();
     IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    loginAndAddProjectPermission("john", issueDto, USER);
 
     tester.newRequest().setParam("key", commentDto.getKey()).setParam("text", "please have a look").execute();
 
@@ -97,7 +97,7 @@ public class DeleteCommentActionTest {
   public void fail_when_comment_does_not_belong_to_current_user() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue();
     IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
-    userSession.logIn("another").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    loginAndAddProjectPermission("another", issueDto, USER);
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("You can only delete your own comments");
@@ -108,7 +108,7 @@ public class DeleteCommentActionTest {
   public void fail_when_comment_has_not_user() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue();
     IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, null, "please fix it");
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    loginAndAddProjectPermission("john", issueDto, USER);
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("You can only delete your own comments");
@@ -141,7 +141,7 @@ public class DeleteCommentActionTest {
   public void fail_when_not_enough_permission() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue();
     IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
-    userSession.logIn("john").addProjectUuidPermissions(CODEVIEWER, issueDto.getProjectUuid());
+    loginAndAddProjectPermission("john", issueDto, CODEVIEWER);
 
     expectedException.expect(ForbiddenException.class);
     call(commentDto.getKey());
@@ -163,4 +163,8 @@ public class DeleteCommentActionTest {
     return request.execute();
   }
 
+  private void loginAndAddProjectPermission(String login, IssueDto issueDto, String permission) {
+    userSession.logIn(login).addProjectPermission(permission, dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getProjectUuid()).get());
+  }
+
 }
index 682c9fe61014add5501816e10317e27db972e749..68c91866b99cebff3ec69bad0b2cb79a3d500bb4 100644 (file)
@@ -103,19 +103,23 @@ public class DoTransitionActionTest {
   private IssueIndexer issueIndexer = new IssueIndexer(esTester.client(), new IssueIteratorFactory(dbClient));
   private IssueUpdater issueUpdater = new IssueUpdater(dbClient,
     new ServerIssueStorage(system2, new DefaultRuleFinder(dbClient, defaultOrganizationProvider), dbClient, issueIndexer), mock(NotificationManager.class));
+  private ComponentDto project;
+  private ComponentDto file;
 
   private WsAction underTest = new DoTransitionAction(dbClient, userSession, new IssueFinder(dbClient, userSession), issueUpdater, transitionService, responseWriter);
   private WsActionTester tester = new WsActionTester(underTest);
 
   @Before
   public void setUp() throws Exception {
+    project = componentDbTester.insertProject();
+    file = componentDbTester.insertComponent(newFileDto(project));
     workflow.start();
   }
 
   @Test
   public void do_transition() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue(newIssue().setStatus(STATUS_OPEN).setResolution(null));
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    userSession.logIn("john").addProjectPermission(USER, project, file);
 
     call(issueDto.getKey(), "confirm");
 
@@ -143,7 +147,7 @@ public class DoTransitionActionTest {
   @Test
   public void fail_if_no_transition_param() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue(newIssue().setStatus(STATUS_OPEN).setResolution(null));
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    userSession.logIn("john").addProjectPermission(USER, project, file);
 
     expectedException.expect(IllegalArgumentException.class);
     call(issueDto.getKey(), null);
@@ -152,7 +156,7 @@ public class DoTransitionActionTest {
   @Test
   public void fail_if_not_enough_permission_to_access_issue() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue(newIssue().setStatus(STATUS_OPEN).setResolution(null));
-    userSession.logIn("john").addProjectUuidPermissions(CODEVIEWER, issueDto.getProjectUuid());
+    userSession.logIn("john").addProjectPermission(CODEVIEWER, project, file);
 
     expectedException.expect(ForbiddenException.class);
     call(issueDto.getKey(), "confirm");
@@ -161,7 +165,7 @@ public class DoTransitionActionTest {
   @Test
   public void fail_if_not_enough_permission_to_apply_transition() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue(newIssue().setStatus(STATUS_OPEN).setResolution(null));
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    userSession.logIn("john").addProjectPermission(USER, project, file);
 
     // False-positive transition is requiring issue admin permission
     expectedException.expect(ForbiddenException.class);
@@ -187,8 +191,6 @@ public class DoTransitionActionTest {
 
   private IssueDto newIssue() {
     RuleDto rule = ruleDbTester.insertRule(newRuleDto());
-    ComponentDto project = componentDbTester.insertProject();
-    ComponentDto file = componentDbTester.insertComponent(newFileDto(project));
     return newDto(rule, file, project);
   }
 
index 2c0ce12cead7dd10680f6e5f93f4f991718866ab..dc524f6bc746da3ded6e6d95b3552f658edd3196 100644 (file)
@@ -85,7 +85,7 @@ public class EditCommentActionTest {
   public void edit_comment() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue();
     IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    loginWithBrowsePermission("john", USER, issueDto);
 
     call(commentDto.getKey(), "please have a look");
 
@@ -99,7 +99,7 @@ public class EditCommentActionTest {
   public void edit_comment_using_deprecated_key_parameter() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue();
     IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    loginWithBrowsePermission("john", USER, issueDto);
 
     tester.newRequest().setParam("key", commentDto.getKey()).setParam("text", "please have a look").execute();
 
@@ -113,7 +113,7 @@ public class EditCommentActionTest {
   public void fail_when_comment_does_not_belong_to_current_user() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue();
     IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
-    userSession.logIn("another").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    loginWithBrowsePermission("another", USER, issueDto);
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("You can only edit your own comments");
@@ -124,7 +124,7 @@ public class EditCommentActionTest {
   public void fail_when_comment_has_not_user() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue();
     IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, null, "please fix it");
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    loginWithBrowsePermission("john", USER, issueDto);
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("You can only edit your own comments");
@@ -159,7 +159,7 @@ public class EditCommentActionTest {
   public void fail_when_empty_comment_text() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue();
     IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    loginWithBrowsePermission("john", USER, issueDto);
 
     expectedException.expect(IllegalArgumentException.class);
     call(commentDto.getKey(), "");
@@ -175,7 +175,7 @@ public class EditCommentActionTest {
   public void fail_when_not_enough_permission() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue();
     IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
-    userSession.logIn("john").addProjectUuidPermissions(CODEVIEWER, issueDto.getProjectUuid());
+    loginWithBrowsePermission("john", CODEVIEWER, issueDto);
 
     expectedException.expect(ForbiddenException.class);
     call(commentDto.getKey(), "please have a look");
@@ -197,4 +197,10 @@ public class EditCommentActionTest {
     setNullable(commentText, comment -> request.setParam("text", comment));
     return request.execute();
   }
+
+  private void loginWithBrowsePermission(String login, String permission, IssueDto issueDto) {
+    userSession.logIn(login).addProjectPermission(permission,
+        dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getProjectUuid()).get(),
+        dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getComponentUuid()).get());
+  }
 }
index 43c46a306ec76620c664aa3ba3db1c190e110c76..28cd589d3536cea0ff4129d37f3d2eed06e57536 100644 (file)
@@ -494,7 +494,7 @@ public class SearchActionComponentsMediumTest {
     indexView(view.uuid(), newArrayList(project.uuid()));
 
     setAnyoneProjectPermission(view, UserRole.USER);
-    userSessionRule.logIn("john").addProjectUuidPermissions(UserRole.USER, view.uuid());
+    userSessionRule.logIn("john").addProjectPermission(UserRole.USER, view);
 
     wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH)
       .setParam(IssuesWsParameters.PARAM_COMPONENT_UUIDS, view.uuid())
@@ -514,7 +514,7 @@ public class SearchActionComponentsMediumTest {
 
     setAnyoneProjectPermission(view, UserRole.USER);
     // User has wrong permission on the view, no issue will be returned
-    userSessionRule.logIn("john").addProjectUuidPermissions(UserRole.CODEVIEWER, view.uuid());
+    userSessionRule.logIn("john").addProjectPermission(UserRole.CODEVIEWER, view);
 
     wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH)
       .setParam(IssuesWsParameters.PARAM_COMPONENT_UUIDS, view.uuid())
@@ -535,7 +535,7 @@ public class SearchActionComponentsMediumTest {
     indexView(subView.uuid(), newArrayList(project.uuid()));
 
     setAnyoneProjectPermission(view, UserRole.USER);
-    userSessionRule.logIn("john").addComponentUuidPermission(UserRole.USER, view.uuid(), subView.uuid());
+    userSessionRule.logIn("john").addProjectPermission(UserRole.USER, view, subView);
 
     wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH)
       .setParam(IssuesWsParameters.PARAM_COMPONENT_UUIDS, subView.uuid())
@@ -557,7 +557,7 @@ public class SearchActionComponentsMediumTest {
 
     setAnyoneProjectPermission(view, UserRole.USER);
     // User has wrong permission on the view, no issue will be returned
-    userSessionRule.logIn("john").addComponentUuidPermission(UserRole.CODEVIEWER, view.uuid(), subView.uuid());
+    userSessionRule.logIn("john").addProjectPermission(UserRole.CODEVIEWER, view, subView);
 
     wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH)
       .setParam(IssuesWsParameters.PARAM_COMPONENT_UUIDS, subView.uuid())
index e7da1c433fa428febecf3a0cee8dd58e52327945..7041184c121f0879a6163e1d3d757f150868459b 100644 (file)
@@ -705,7 +705,7 @@ public class SearchActionMediumTest {
 
   private void setDefaultProjectPermission(ComponentDto project) {
     // project can be seen by anyone and by code viewer
-    userSessionRule.logIn().addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSessionRule.logIn().addProjectPermission(UserRole.USER, project);
     // TODO correctly feed default organization. Not a problem as long as issues search does not support "anyone"
     // for each organization
     GroupPermissionChange permissionChange = new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.USER, new ProjectId(project), GroupIdOrAnyone.forAnyone(project.getOrganizationUuid()));
@@ -715,7 +715,7 @@ public class SearchActionMediumTest {
   private void setProjectPermission(ComponentDto project, String... permissions) {
     // project can be seen by anyone and by code viewer
     userSessionRule.logIn("admin");
-    Arrays.stream(permissions).forEach(permission -> userSessionRule.addProjectUuidPermissions(permission, project.uuid()));
+    Arrays.stream(permissions).forEach(permission -> userSessionRule.addProjectPermission(permission, project));
     tester.get(PermissionUpdater.class).apply(session, Arrays.stream(permissions)
       // TODO correctly feed default organization. Not a problem as long as issues search does not support "anyone" for each organization
       .map(permission -> new GroupPermissionChange(PermissionChange.Operation.ADD, permission, new ProjectId(project), GroupIdOrAnyone.forAnyone(project.getOrganizationUuid())))
index 9ee03ecfd6c9e39f254ceaa21765decdbae6de2b..e06e50b8a9c01af8779fd1837e9925ae55c5c2cb 100644 (file)
@@ -101,7 +101,7 @@ public class SetSeverityActionTest {
   @Test
   public void set_severity() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue(newIssue().setSeverity(MAJOR));
-    setUserWithBrowseAndAdministerIssuePermission(issueDto.getProjectUuid());
+    setUserWithBrowseAndAdministerIssuePermission(issueDto);
 
     call(issueDto.getKey(), MINOR);
 
@@ -114,7 +114,7 @@ public class SetSeverityActionTest {
   @Test
   public void insert_entry_in_changelog_when_setting_severity() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue(newIssue().setSeverity(MAJOR));
-    setUserWithBrowseAndAdministerIssuePermission(issueDto.getProjectUuid());
+    setUserWithBrowseAndAdministerIssuePermission(issueDto);
 
     call(issueDto.getKey(), MINOR);
 
@@ -128,7 +128,7 @@ public class SetSeverityActionTest {
   @Test
   public void fail_if_bad_severity() {
     IssueDto issueDto = issueDbTester.insertIssue(newIssue().setSeverity("unknown"));
-    setUserWithBrowseAndAdministerIssuePermission(issueDto.getProjectUuid());
+    setUserWithBrowseAndAdministerIssuePermission(issueDto);
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Value of parameter 'severity' (unknown) must be one of: [INFO, MINOR, MAJOR, CRITICAL, BLOCKER]");
@@ -144,7 +144,7 @@ public class SetSeverityActionTest {
   @Test
   public void fail_when_missing_browse_permission() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue();
-    userSession.logIn("john").addProjectUuidPermissions(ISSUE_ADMIN, issueDto.getProjectUuid());
+    logInAndAddProjectPermission(issueDto, ISSUE_ADMIN);
 
     expectedException.expect(ForbiddenException.class);
     call(issueDto.getKey(), MAJOR);
@@ -153,7 +153,7 @@ public class SetSeverityActionTest {
   @Test
   public void fail_when_missing_administer_issue_permission() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue();
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    logInAndAddProjectPermission(issueDto, USER);
 
     expectedException.expect(ForbiddenException.class);
     call(issueDto.getKey(), MAJOR);
@@ -183,9 +183,14 @@ public class SetSeverityActionTest {
     return newDto(rule, file, project);
   }
 
-  private void setUserWithBrowseAndAdministerIssuePermission(String projectUuid) {
+  private void logInAndAddProjectPermission(IssueDto issueDto, String permission) {
+    userSession.logIn("john").addProjectPermission(permission, dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getProjectUuid()).get());
+  }
+
+  private void setUserWithBrowseAndAdministerIssuePermission(IssueDto issueDto) {
+    ComponentDto project = dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getProjectUuid()).get();
     userSession.logIn("john")
-      .addProjectUuidPermissions(ISSUE_ADMIN, projectUuid)
-      .addProjectUuidPermissions(USER, projectUuid);
+      .addProjectPermission(ISSUE_ADMIN, project)
+      .addProjectPermission(USER, project);
   }
 }
index 2a9dbf7d5503a87567e310db9014484e248dd6cd..694e530215f3de1245c86442fe23c2c2693f742f 100644 (file)
@@ -95,7 +95,7 @@ public class SetTagsActionTest {
   @Test
   public void set_tags() {
     IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag")));
-    setUserWithBrowsePermission(issueDto.getProjectUuid());
+    setUserWithBrowsePermission(issueDto);
 
     call(issueDto.getKey(), "bug", "todo");
 
@@ -107,7 +107,7 @@ public class SetTagsActionTest {
   @Test
   public void remove_existing_tags_when_value_is_not_set() {
     IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag")));
-    setUserWithBrowsePermission(issueDto.getProjectUuid());
+    setUserWithBrowsePermission(issueDto);
 
     call(issueDto.getKey());
 
@@ -118,7 +118,7 @@ public class SetTagsActionTest {
   @Test
   public void remove_existing_tags_when_value_is_empty_string() {
     IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag")));
-    setUserWithBrowsePermission(issueDto.getProjectUuid());
+    setUserWithBrowsePermission(issueDto);
 
     call(issueDto.getKey(), "");
 
@@ -129,7 +129,7 @@ public class SetTagsActionTest {
   @Test
   public void set_tags_using_deprecated_key_param() {
     IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag")));
-    setUserWithBrowsePermission(issueDto.getProjectUuid());
+    setUserWithBrowsePermission(issueDto);
 
     ws.newRequest().setParam("key", issueDto.getKey()).setParam("tags", "bug").execute();
 
@@ -140,7 +140,7 @@ public class SetTagsActionTest {
   @Test
   public void tags_are_stored_as_lowercase() {
     IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag")));
-    setUserWithBrowsePermission(issueDto.getProjectUuid());
+    setUserWithBrowsePermission(issueDto);
 
     call(issueDto.getKey(), "bug", "Convention");
 
@@ -151,7 +151,7 @@ public class SetTagsActionTest {
   @Test
   public void empty_tags_are_ignored() {
     IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag")));
-    setUserWithBrowsePermission(issueDto.getProjectUuid());
+    setUserWithBrowsePermission(issueDto);
 
     call(issueDto.getKey(), "security", "", "convention");
 
@@ -162,7 +162,7 @@ public class SetTagsActionTest {
   @Test
   public void insert_entry_in_changelog_when_setting_tags() throws Exception {
     IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag")));
-    setUserWithBrowsePermission(issueDto.getProjectUuid());
+    setUserWithBrowsePermission(issueDto);
 
     call(issueDto.getKey(), "new-tag");
 
@@ -176,7 +176,7 @@ public class SetTagsActionTest {
   @Test
   public void fail_when_bad_tag_format() {
     IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag")));
-    setUserWithBrowsePermission(issueDto.getProjectUuid());
+    setUserWithBrowsePermission(issueDto);
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Tag 'pol op' is invalid. Rule tags accept only the characters: a-z, 0-9, '+', '-', '#', '.'");
@@ -194,7 +194,7 @@ public class SetTagsActionTest {
   @Test
   public void fail_when_missing_browse_permission() throws Exception {
     IssueDto issueDto = db.issues().insertIssue();
-    userSession.logIn("john").addProjectUuidPermissions(ISSUE_ADMIN, issueDto.getProjectUuid());
+    logInAndAddProjectPermission(issueDto, ISSUE_ADMIN);
 
     expectedException.expect(ForbiddenException.class);
 
@@ -237,8 +237,12 @@ public class SetTagsActionTest {
     return IssueTesting.newIssue(rule, file, project);
   }
 
-  private void setUserWithBrowsePermission(String projectUuid) {
-    userSession.logIn("john").addProjectUuidPermissions(USER, projectUuid);
+  private void setUserWithBrowsePermission(IssueDto issueDto) {
+    logInAndAddProjectPermission(issueDto, USER);
+  }
+
+  private void logInAndAddProjectPermission(IssueDto issueDto, String permission) {
+    userSession.logIn("john").addProjectPermission(permission, dbClient.componentDao().selectByUuid(db.getSession(), issueDto.getProjectUuid()).get());
   }
 
 }
index ca5cd1b443675744fd69f26fdc4676bb3abc4f73..b5e9af4f82eec5e95efeb3880c08ecf09f9a7d3c 100644 (file)
@@ -97,7 +97,7 @@ public class SetTypeActionTest {
   @Test
   public void set_type() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue(newIssue().setType(CODE_SMELL));
-    setUserWithBrowseAndAdministerIssuePermission(issueDto.getProjectUuid());
+    setUserWithBrowseAndAdministerIssuePermission(issueDto);
 
     call(issueDto.getKey(), BUG.name());
 
@@ -109,7 +109,7 @@ public class SetTypeActionTest {
   @Test
   public void insert_entry_in_changelog_when_setting_type() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue(newIssue().setType(CODE_SMELL));
-    setUserWithBrowseAndAdministerIssuePermission(issueDto.getProjectUuid());
+    setUserWithBrowseAndAdministerIssuePermission(issueDto);
 
     call(issueDto.getKey(), BUG.name());
 
@@ -123,7 +123,7 @@ public class SetTypeActionTest {
   @Test
   public void fail_if_bad_type_value() {
     IssueDto issueDto = issueDbTester.insertIssue(newIssue().setType(CODE_SMELL));
-    setUserWithBrowseAndAdministerIssuePermission(issueDto.getProjectUuid());
+    setUserWithBrowseAndAdministerIssuePermission(issueDto);
 
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Value of parameter 'type' (unknown) must be one of: [CODE_SMELL, BUG, VULNERABILITY]");
@@ -139,7 +139,9 @@ public class SetTypeActionTest {
   @Test
   public void fail_when_missing_browse_permission() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue();
-    userSession.logIn("john").addProjectUuidPermissions(ISSUE_ADMIN, issueDto.getProjectUuid());
+    String login = "john";
+    String permission = ISSUE_ADMIN;
+    logInAndAddProjectPermission(login, issueDto, permission);
 
     expectedException.expect(ForbiddenException.class);
     call(issueDto.getKey(), BUG.name());
@@ -148,7 +150,7 @@ public class SetTypeActionTest {
   @Test
   public void fail_when_missing_administer_issue_permission() throws Exception {
     IssueDto issueDto = issueDbTester.insertIssue();
-    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+    logInAndAddProjectPermission("john", issueDto, USER);
 
     expectedException.expect(ForbiddenException.class);
     call(issueDto.getKey(), BUG.name());
@@ -178,9 +180,14 @@ public class SetTypeActionTest {
     return newDto(rule, file, project);
   }
 
-  private void setUserWithBrowseAndAdministerIssuePermission(String projectUuid) {
+  private void setUserWithBrowseAndAdministerIssuePermission(IssueDto issueDto) {
+    ComponentDto project = dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getProjectUuid()).get();
     userSession.logIn("john")
-      .addProjectUuidPermissions(ISSUE_ADMIN, projectUuid)
-      .addProjectUuidPermissions(USER, projectUuid);
+      .addProjectPermission(ISSUE_ADMIN, project)
+      .addProjectPermission(USER, project);
+  }
+
+  private void logInAndAddProjectPermission(String login, IssueDto issueDto, String permission) {
+    userSession.logIn(login).addProjectPermission(permission, dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getProjectUuid()).get());
   }
 }
index 2a3d61a577f1661914c494e786675d4e1cde51b4..fdadb23e5c43d477e51fc3a96896f34031637fdf 100644 (file)
@@ -213,7 +213,7 @@ public class TagsActionTest {
   }
 
   private void setUserWithBrowsePermission(IssueDto issue) {
-    userSession.logIn("john").addProjectUuidPermissions(USER, issue.getProjectUuid());
+    userSession.logIn("john").addProjectPermission(USER, db.getDbClient().componentDao().selectByUuid(db.getSession(), issue.getProjectUuid()).get());
   }
 
   private IssueDto insertIssueWithBrowsePermission(RuleDefinitionDto rule, String... tags) {
index f8c2a445f7fe5a60d10e2534afaa21f5f76fbcb7..13a6c7d1d6936ae883dfc9b12813b162a1f70925 100644 (file)
@@ -69,17 +69,15 @@ public class CreateActionTest {
 
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
-
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
-
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
-
   @Rule
   public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings()));
 
   DbClient dbClient = db.getDbClient();
+  ComponentDto project;
 
   final DbSession dbSession = db.getSession();
 
@@ -97,12 +95,15 @@ public class CreateActionTest {
       .setActive(true));
     dbSession.commit();
 
-    userSession.logIn("login").addProjectUuidPermissions(UserRole.ADMIN, DEFAULT_PROJECT_UUID);
+    OrganizationDto organizationDto = db.organizations().insert();
+    project = ComponentTesting.newProjectDto(organizationDto, DEFAULT_PROJECT_UUID).setKey(DEFAULT_PROJECT_KEY);
+    dbClient.componentDao().insert(dbSession, project);
+    dbSession.commit();
+    userSession.logIn("login").addProjectPermission(UserRole.ADMIN, project);
   }
 
   @Test
   public void create_boolean_custom_measure_in_db() throws Exception {
-    insertProject(DEFAULT_PROJECT_UUID);
     MetricDto metric = insertMetric(BOOL);
 
     newRequest()
@@ -123,7 +124,6 @@ public class CreateActionTest {
 
   @Test
   public void create_int_custom_measure_in_db() throws Exception {
-    insertProject(DEFAULT_PROJECT_UUID);
     MetricDto metric = insertMetric(INT);
 
     newRequest()
@@ -139,7 +139,6 @@ public class CreateActionTest {
 
   @Test
   public void create_text_custom_measure_in_db() throws Exception {
-    insertProject(DEFAULT_PROJECT_UUID);
     MetricDto metric = insertMetric(STRING);
 
     newRequest()
@@ -154,9 +153,8 @@ public class CreateActionTest {
 
   @Test
   public void create_text_custom_measure_as_project_admin() throws Exception {
-    insertProject(DEFAULT_PROJECT_UUID);
     MetricDto metric = insertMetric(STRING);
-    userSession.logIn("login").addProjectUuidPermissions(UserRole.ADMIN, DEFAULT_PROJECT_UUID);
+    userSession.logIn("login").addProjectPermission(UserRole.ADMIN, project);
 
     newRequest()
       .setParam(CreateAction.PARAM_PROJECT_ID, DEFAULT_PROJECT_UUID)
@@ -170,7 +168,6 @@ public class CreateActionTest {
 
   @Test
   public void create_text_custom_measure_with_metric_key() throws Exception {
-    insertProject(DEFAULT_PROJECT_UUID);
     MetricDto metric = insertMetric(STRING);
 
     newRequest()
@@ -185,7 +182,6 @@ public class CreateActionTest {
 
   @Test
   public void create_text_custom_measure_with_project_key() throws Exception {
-    insertProject(DEFAULT_PROJECT_UUID);
     MetricDto metric = insertMetric(STRING);
 
     newRequest()
@@ -200,7 +196,6 @@ public class CreateActionTest {
 
   @Test
   public void create_float_custom_measure_in_db() throws Exception {
-    insertProject(DEFAULT_PROJECT_UUID);
     MetricDto metric = insertMetric(FLOAT);
 
     newRequest()
@@ -216,7 +211,6 @@ public class CreateActionTest {
 
   @Test
   public void create_work_duration_custom_measure_in_db() throws Exception {
-    insertProject(DEFAULT_PROJECT_UUID);
     MetricDto metric = insertMetric(WORK_DUR);
 
     newRequest()
@@ -232,7 +226,6 @@ public class CreateActionTest {
 
   @Test
   public void create_level_type_custom_measure_in_db() throws Exception {
-    insertProject(DEFAULT_PROJECT_UUID);
     MetricDto metric = insertMetric(LEVEL);
 
     newRequest()
@@ -247,7 +240,6 @@ public class CreateActionTest {
 
   @Test
   public void response_with_object_and_id() throws Exception {
-    insertProject(DEFAULT_PROJECT_UUID);
     MetricDto metric = insertMetric(STRING);
 
     WsTester.Result response = newRequest()
@@ -266,10 +258,11 @@ public class CreateActionTest {
   @Test
   public void create_custom_measure_on_a_view() throws Exception {
     String viewUuid = "VIEW_UUID";
-    dbClient.componentDao().insert(dbSession, ComponentTesting.newView(db.organizations().insert(), viewUuid));
+    ComponentDto view = ComponentTesting.newView(db.organizations().insert(), viewUuid);
+    dbClient.componentDao().insert(dbSession, view);
     dbSession.commit();
     MetricDto metric = insertMetric(BOOL);
-    userSession.logIn("login").addProjectUuidPermissions(UserRole.ADMIN, viewUuid);
+    userSession.logIn("login").addProjectPermission(UserRole.ADMIN, view);
 
     newRequest()
       .setParam(CreateAction.PARAM_PROJECT_ID, viewUuid)
@@ -293,7 +286,7 @@ public class CreateActionTest {
     dbClient.componentDao().insert(dbSession, ComponentTesting.newSubView(view, subViewUuid, "SUB_VIEW_KEY"));
     dbSession.commit();
     MetricDto metric = insertMetric(BOOL);
-    userSession.logIn("login").addProjectUuidPermissions(UserRole.ADMIN, view.uuid());
+    userSession.logIn("login").addProjectPermission(UserRole.ADMIN, view);
 
     newRequest()
       .setParam(CreateAction.PARAM_PROJECT_ID, subViewUuid)
@@ -323,7 +316,6 @@ public class CreateActionTest {
   public void fail_when_project_id_nor_project_key_provided() throws Exception {
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Either 'projectId' or 'projectKey' must be provided, not both");
-    insertProject(DEFAULT_PROJECT_UUID);
     MetricDto metric = insertMetric(STRING);
 
     newRequest()
@@ -336,7 +328,6 @@ public class CreateActionTest {
   public void fail_when_project_id_and_project_key_are_provided() throws Exception {
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("Either 'projectId' or 'projectKey' must be provided, not both");
-    insertProject(DEFAULT_PROJECT_UUID);
     MetricDto metric = insertMetric(STRING);
 
     newRequest()
@@ -351,8 +342,7 @@ public class CreateActionTest {
   public void fail_when_project_key_does_not_exist_in_db() throws Exception {
     expectedException.expect(NotFoundException.class);
     expectedException.expectMessage("Component key 'another-project-key' not found");
-    insertProject(DEFAULT_PROJECT_UUID);
-    MetricDto metric = insertMetric(STRING);
+    insertMetric(STRING);
 
     newRequest()
       .setParam(CreateAction.PARAM_PROJECT_KEY, "another-project-key")
@@ -365,7 +355,6 @@ public class CreateActionTest {
   public void fail_when_project_id_does_not_exist_in_db() throws Exception {
     expectedException.expect(NotFoundException.class);
     expectedException.expectMessage("Component id 'another-project-uuid' not found");
-    insertProject(DEFAULT_PROJECT_UUID);
     MetricDto metric = insertMetric(STRING);
 
     newRequest()
@@ -379,8 +368,7 @@ public class CreateActionTest {
   public void fail_when_metric_id_nor_metric_key_is_provided() throws Exception {
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("The metric id or the metric key must be provided, not both.");
-    insertProject(DEFAULT_PROJECT_UUID);
-    MetricDto metric = insertMetric(STRING);
+    insertMetric(STRING);
 
     newRequest()
       .setParam(CreateAction.PARAM_PROJECT_ID, DEFAULT_PROJECT_UUID)
@@ -392,7 +380,6 @@ public class CreateActionTest {
   public void fail_when_metric_id_and_metric_key_are_provided() throws Exception {
     expectedException.expect(IllegalArgumentException.class);
     expectedException.expectMessage("The metric id or the metric key must be provided, not both.");
-    insertProject(DEFAULT_PROJECT_UUID);
     MetricDto metric = insertMetric(STRING);
 
     newRequest()
@@ -405,9 +392,6 @@ public class CreateActionTest {
 
   @Test
   public void fail_when_metric_is_not_found_in_db() throws Exception {
-    dbClient.componentDao().insert(dbSession, ComponentTesting.newProjectDto(db.organizations().insert(), DEFAULT_PROJECT_UUID));
-    dbSession.commit();
-
     expectedException.expect(RowNotFoundException.class);
     expectedException.expectMessage("Metric id '42' not found");
 
@@ -420,7 +404,6 @@ public class CreateActionTest {
 
   @Test
   public void fail_when_measure_already_exists_on_same_project_and_same_metric() throws Exception {
-    insertProject(DEFAULT_PROJECT_UUID);
     MetricDto metric = insertMetric(STRING);
 
     expectedException.expect(ServerException.class);
@@ -440,7 +423,6 @@ public class CreateActionTest {
 
   @Test
   public void fail_when_value_is_not_well_formatted() throws Exception {
-    insertProject(DEFAULT_PROJECT_UUID);
     MetricDto metric = insertMetric(BOOL);
 
     expectedException.expect(BadRequestException.class);
@@ -455,7 +437,6 @@ public class CreateActionTest {
   @Test
   public void fail_when_not_project_administrator() throws Exception {
     userSession.logIn();
-    insertProject(DEFAULT_PROJECT_UUID);
     MetricDto metric = insertMetric(STRING);
 
     expectedException.expect(ForbiddenException.class);
@@ -471,8 +452,6 @@ public class CreateActionTest {
   public void fail_when_not_a_project() throws Exception {
     MetricDto metric = MetricTesting.newMetricDto().setEnabled(true).setValueType(STRING.name()).setKey("metric-key");
     dbClient.metricDao().insert(dbSession, metric);
-    ComponentDto project = ComponentTesting.newProjectDto(db.organizations().insert(), DEFAULT_PROJECT_UUID).setKey(DEFAULT_PROJECT_KEY);
-    dbClient.componentDao().insert(dbSession, project);
     dbClient.componentDao().insert(dbSession, ComponentTesting.newDirectory(project, "directory-uuid", "path/to/directory").setKey("directory-key"));
     dbSession.commit();
 
@@ -497,9 +476,4 @@ public class CreateActionTest {
     return metric;
   }
 
-  private void insertProject(String projectUuid) {
-    OrganizationDto organizationDto = db.organizations().insert();
-    dbClient.componentDao().insert(dbSession, ComponentTesting.newProjectDto(organizationDto, projectUuid).setKey(DEFAULT_PROJECT_KEY));
-    dbSession.commit();
-  }
 }
index c96d9d8daa606e08b702982f283765dd2e32831a..ddc01c1061ccbe61340b6f09131fb19a2d3e549c 100644 (file)
@@ -64,7 +64,7 @@ public class DeleteActionTest {
   @Test
   public void project_administrator_can_delete_custom_measures() throws Exception {
     ComponentDto project = db.components().insertProject();
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
     long id = insertCustomMeasure(project);
 
     newRequest().setParam(PARAM_ID, valueOf(id)).execute();
index c979aa7d2e7f2e1bd1aa98db66df8e9ce42f9982..a6e20b455a99f0d9d6e4d8ca5161f2f21bf07768 100644 (file)
@@ -76,7 +76,7 @@ public class MetricsActionTest {
       .setActive(true));
     ws = new WsTester(new CustomMeasuresWs(new MetricsAction(dbClient, userSession, new ComponentFinder(dbClient))));
     defaultProject = insertDefaultProject();
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, defaultProject.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, defaultProject);
   }
 
   @Test
@@ -145,7 +145,7 @@ public class MetricsActionTest {
   @Test
   public void list_metrics_as_a_project_admin() throws Exception {
     insertCustomMetric("metric-key-1");
-    userSession.logIn("login").addProjectUuidPermissions(UserRole.ADMIN, defaultProject.uuid());
+    userSession.logIn("login").addProjectPermission(UserRole.ADMIN, defaultProject);
 
     String response = newRequest().outputAsString();
 
index 06f5bbc8045803890b990fcf078b4d9c4a20b502..b9ea1be717ef990d103ee42f59602f4579146879 100644 (file)
@@ -81,7 +81,7 @@ public class SearchActionTest {
     CustomMeasureJsonWriter customMeasureJsonWriter = new CustomMeasureJsonWriter(new UserJsonWriter(userSessionRule));
     ws = new WsTester(new CustomMeasuresWs(new SearchAction(dbClient, customMeasureJsonWriter, userSessionRule, new ComponentFinder(dbClient))));
     defaultProject = insertDefaultProject();
-    userSessionRule.logIn().addProjectUuidPermissions(UserRole.ADMIN, defaultProject.uuid());
+    userSessionRule.logIn().addProjectPermission(UserRole.ADMIN, defaultProject);
 
     db.getDbClient().userDao().insert(dbSession, new UserDto()
       .setLogin("login")
@@ -200,7 +200,7 @@ public class SearchActionTest {
 
   @Test
   public void search_as_project_admin() throws Exception {
-    userSessionRule.logIn("login").addProjectUuidPermissions(UserRole.ADMIN, DEFAULT_PROJECT_UUID);
+    userSessionRule.logIn("login").addProjectPermission(UserRole.ADMIN, defaultProject);
     MetricDto metric1 = insertCustomMetric(1);
     insertCustomMeasure(1, metric1);
 
index b5e151d363884f6a0cd3c7a3a0da55b3b2611cd5..193f27620d070ae4eeb63d73748523c4e26bd7fc 100644 (file)
@@ -328,6 +328,6 @@ public class UpdateActionTest {
   }
 
   private void logInAsProjectAdministrator(ComponentDto component) {
-    userSessionRule.logIn("login").addProjectUuidPermissions(UserRole.ADMIN, component.uuid());
+    userSessionRule.logIn("login").addProjectPermission(UserRole.ADMIN, component);
   }
 }
index 93dce596cd186b2ca59d0f53007fd28aa139f0b8..8ae3aabc8053fe1ab6e2520edc34c281c8fa64fb 100644 (file)
@@ -96,8 +96,8 @@ public class ComponentActionTest {
 
   @Test
   public void provided_project() {
-    componentDb.insertComponent(newProjectDto(db.getDefaultOrganization(), PROJECT_UUID));
-    userSession.addProjectUuidPermissions(UserRole.USER, PROJECT_UUID);
+    ComponentDto project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization(), PROJECT_UUID));
+    userSession.addProjectPermission(UserRole.USER, project);
     insertNclocMetric();
 
     ComponentWsResponse response = newRequest(PROJECT_UUID, "ncloc");
index 8ebad37a738a22be36e09fa462b0868de90697ff..95a9f77d4bb143721101a7cfdb4fbd5f6514f7c4 100644 (file)
@@ -148,7 +148,7 @@ public class ComponentTreeActionTest {
         .setPeriodDate(System.currentTimeMillis())
         .setPeriodMode("last_version")
         .setPeriodDate(System.currentTimeMillis()));
-    userSession.anonymous().addProjectUuidPermissions(UserRole.USER, "project-uuid");
+    userSession.anonymous().addProjectPermission(UserRole.USER, projectDto);
     ComponentDto directoryDto = newDirectory(projectDto, "directory-uuid", "path/to/directory").setName("directory-1");
     componentDb.insertComponent(directoryDto);
     ComponentDto file = newFileDto(directoryDto, null, "file-uuid").setName("file-1");
@@ -179,7 +179,7 @@ public class ComponentTreeActionTest {
   public void load_measures_with_best_value() {
     ComponentDto projectDto = newProjectDto(db.getDefaultOrganization(), "project-uuid");
     SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto);
-    userSession.anonymous().addProjectUuidPermissions(UserRole.USER, "project-uuid");
+    userSession.anonymous().addProjectPermission(UserRole.USER, projectDto);
     ComponentDto directoryDto = newDirectory(projectDto, "directory-uuid", "path/to/directory").setName("directory-1");
     componentDb.insertComponent(directoryDto);
     ComponentDto file = newFileDto(directoryDto, null, "file-uuid").setName("file-1");
@@ -221,8 +221,8 @@ public class ComponentTreeActionTest {
 
   @Test
   public void use_best_value_for_rating() {
-    userSession.anonymous().addProjectUuidPermissions(UserRole.USER, "project-uuid");
     ComponentDto projectDto = newProjectDto(db.getDefaultOrganization(), "project-uuid");
+    userSession.anonymous().addProjectPermission(UserRole.USER, projectDto);
     componentDb.insertComponent(projectDto);
     SnapshotDto projectSnapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(projectDto)
       .setPeriodDate(parseDateTime("2016-01-11T10:49:50+0100").getTime())
index 24e464f9190a71b7b414c9aa2fb8d8bada972534..dfc31efbfd4d8fa78babdb6ca84f22fd2eb1d912 100644 (file)
@@ -94,7 +94,7 @@ public class SearchHistoryActionTest {
   public void setUp() {
     project = newProjectDto(db.getDefaultOrganization());
     analysis = db.components().insertProjectAndSnapshot(project);
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
     nclocMetric = insertNclocMetric();
     complexityMetric = insertComplexityMetric();
     newViolationMetric = insertNewViolationMetric();
@@ -105,7 +105,7 @@ public class SearchHistoryActionTest {
   @Test
   public void empty_response() {
     project = db.components().insertProject();
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
     wsRequest
       .setComponent(project.getKey())
       .setMetrics(singletonList(complexityMetric.getKey()));
@@ -173,7 +173,7 @@ public class SearchHistoryActionTest {
   @Test
   public void pagination_applies_to_analyses() {
     project = db.components().insertProject();
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
     List<String> analysisDates = LongStream.rangeClosed(1, 9)
       .mapToObj(i -> dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setCreatedAt(i * 1_000_000_000)))
       .peek(a -> dbClient.measureDao().insert(dbSession, newMeasureDto(complexityMetric, project, a).setValue(101d)))
@@ -192,7 +192,7 @@ public class SearchHistoryActionTest {
   @Test
   public void inclusive_from_and_to_dates() {
     project = db.components().insertProject();
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
     List<String> analysisDates = LongStream.rangeClosed(1, 9)
       .mapToObj(i -> dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setCreatedAt(System2.INSTANCE.now() + i * 1_000_000_000L)))
       .peek(a -> dbClient.measureDao().insert(dbSession, newMeasureDto(complexityMetric, project, a).setValue(Double.valueOf(a.getCreatedAt()))))
@@ -263,7 +263,7 @@ public class SearchHistoryActionTest {
 
   @Test
   public void fail_if_not_enough_permissions() {
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     expectedException.expect(ForbiddenException.class);
 
@@ -293,7 +293,7 @@ public class SearchHistoryActionTest {
   @Test
   public void json_example() {
     project = db.components().insertProject();
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
     long now = parseDateTime("2017-01-23T17:00:53+0100").getTime();
     LongStream.rangeClosed(0, 2)
       .mapToObj(i -> dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setCreatedAt(now + i * 24 * 1_000 * 60 * 60)))
index cf047f6794f60dcb644e02dfb0afba363cc84a2a..85d258bdb70180ecab3b8ef8763bbc8d3ec6fdd8 100644 (file)
@@ -301,7 +301,7 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> {
   public void adding_project_permission_is_allowed_to_project_administrators() throws Exception {
     GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
     ComponentDto project = db.components().insertProject();
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     newRequest()
       .setParam(PARAM_GROUP_NAME, group.getName())
index 1ead26ac6636ae932efd3bdf94a76a08ee0973c9..2cc8fa0bfce11cdc51f57c2d117e088a4a965b92 100644 (file)
@@ -255,7 +255,7 @@ public class AddUserActionTest extends BasePermissionWsTest<AddUserAction> {
   public void adding_project_permission_is_allowed_to_project_administrators() throws Exception {
     ComponentDto project = db.components().insertProject();
 
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     newRequest()
       .setParam(PARAM_USER_LOGIN, user.getLogin())
index 077a33c362a9649cc143650ad0a3788b3eb1cc30..d755750c72f323d82879debee5d1a08ec84f57ed 100644 (file)
@@ -164,7 +164,7 @@ public class GroupsActionTest extends BasePermissionWsTest<GroupsAction> {
 
     GroupDto groupWithoutPermission = db.users().insertGroup(organizationDto, "group-without-permission");
 
-    userSession.logIn().addProjectUuidPermissions(ADMIN, "project-uuid");
+    userSession.logIn().addProjectPermission(ADMIN, project);
     String result = newRequest()
       .setParam(PARAM_PERMISSION, ISSUE_ADMIN)
       .setParam(PARAM_PROJECT_ID, "project-uuid")
index 32c66ee1040500aeb8b00ea412b8cb04427db8a6..5eb2310c45f193fbefc1b675b040ab880955a1a9 100644 (file)
@@ -296,7 +296,7 @@ public class RemoveGroupActionTest extends BasePermissionWsTest<RemoveGroupActio
     db.users().insertProjectPermissionOnGroup(aGroup, CODEVIEWER, project);
     db.users().insertProjectPermissionOnGroup(aGroup, ISSUE_ADMIN, project);
 
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
     newRequest()
       .setParam(PARAM_GROUP_NAME, aGroup.getName())
       .setParam(PARAM_PROJECT_ID, project.uuid())
index e176dd995baf8b311a22e32b6663c21ca88f13f3..2972a411324081a460058fbf9b852af79ee447b9 100644 (file)
@@ -265,7 +265,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest<RemoveUserAction>
     ComponentDto project = db.components().insertProject();
     db.users().insertProjectPermissionOnUser(user, CODEVIEWER, project);
     db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project);
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     newRequest()
       .setParam(PARAM_USER_LOGIN, user.getLogin())
index 4c2996e7ba3c6ad3494b5ec6de4054d03fa9f1b5..5759b7c9e7a5cf60ae5d8cbf5e0262604095e6fe 100644 (file)
@@ -120,8 +120,8 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea
 
   @Test
   public void search_project_permissions_with_project_permission() throws Exception {
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, "project-uuid");
-    db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
+    ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     String result = newRequest()
       .setParam(PARAM_PROJECT_ID, "project-uuid")
index 175dec1ef7d78b013508f9f795108cfa9718f10f..7c224c860430ec90822e4cab9a335be72e7af157 100644 (file)
@@ -96,7 +96,7 @@ public class UsersActionTest extends BasePermissionWsTest<UsersAction> {
     UserDto withoutPermission = db.users().insertUser(newUserDto());
     db.organizations().addMember(db.getDefaultOrganization(), withoutPermission);
 
-    userSession.logIn().addProjectUuidPermissions(SYSTEM_ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(SYSTEM_ADMIN, project);
     String result = newRequest()
       .setParam(PARAM_PERMISSION, ISSUE_ADMIN)
       .setParam(PARAM_PROJECT_ID, project.uuid())
index b2a493d5a39ffb78ab7c2a6537dda2d921db6826..eba3ee37746106e10a990cd9147df10628ef7fe3 100644 (file)
@@ -70,11 +70,11 @@ public class DeleteActionTest {
   @Before
   public void setUp() {
     ws = new WsTester(new ProjectsWs(
-        new DeleteAction(
-            componentCleanerService,
-            new ComponentFinder(dbClient),
-            dbClient,
-            userSessionRule)));
+      new DeleteAction(
+        componentCleanerService,
+        new ComponentFinder(dbClient),
+        dbClient,
+        userSessionRule)));
   }
 
   @Test
@@ -107,7 +107,7 @@ public class DeleteActionTest {
   @Test
   public void project_administrator_deletes_the_project_by_uuid() throws Exception {
     ComponentDto project = componentDbTester.insertProject();
-    userSessionRule.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSessionRule.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     call(newRequest().setParam(PARAM_PROJECT_ID, project.uuid()));
 
@@ -117,7 +117,7 @@ public class DeleteActionTest {
   @Test
   public void project_administrator_deletes_the_project_by_key() throws Exception {
     ComponentDto project = componentDbTester.insertProject();
-    userSessionRule.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSessionRule.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     call(newRequest().setParam(PARAM_PROJECT, project.key()));
 
@@ -128,7 +128,10 @@ public class DeleteActionTest {
   public void return_403_if_not_project_admin_nor_org_admin() throws Exception {
     ComponentDto project = componentDbTester.insertProject();
 
-    userSessionRule.logIn().addProjectUuidPermissions(project.uuid(), UserRole.CODEVIEWER, UserRole.ISSUE_ADMIN, UserRole.USER);
+    userSessionRule.logIn()
+      .addProjectPermission(UserRole.CODEVIEWER, project)
+      .addProjectPermission(UserRole.ISSUE_ADMIN, project)
+      .addProjectPermission(UserRole.USER, project);
     expectedException.expect(ForbiddenException.class);
 
     call(newRequest().setParam(PARAM_PROJECT_ID, project.uuid()));
index 8424b774e1f346245880c81524c8b64b8cfdba48..e4192a16d39c1c899ddad30b4eb43fb36277f9a3 100644 (file)
@@ -42,7 +42,6 @@ import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.WsActionTester;
-import org.sonarqube.ws.MediaTypes;
 import org.sonarqube.ws.ProjectAnalyses;
 import org.sonarqube.ws.ProjectAnalyses.CreateEventResponse;
 import org.sonarqube.ws.client.projectanalysis.CreateEventRequest;
@@ -354,7 +353,7 @@ public class CreateEventActionTest {
   }
 
   private void logInAsProjectAdministrator(ComponentDto project) {
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
   }
 
   private CreateEventResponse call(CreateEventRequest.Builder requestBuilder) {
index 9f37bae452a976bbbdb932966e12f40f2758d710..01be23ac7e22f61e8c06078db399691eb8bbd6e0 100644 (file)
@@ -130,6 +130,6 @@ public class DeleteActionTest {
   }
 
   private void logInAsProjectAdministrator(ComponentDto project) {
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
   }
 }
index 65be20d0827927d14a4c32084268b391e4116911..b298e3e799a64db264ee05fcca2afdea579e24a7 100644 (file)
@@ -156,6 +156,6 @@ public class DeleteEventActionTest {
   }
 
   private void logInAsProjectAdministrator(ComponentDto project) {
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
   }
 }
index c214937db6ea49f7c94da3c645561302257ba338..d9a22a65061ed1d014d852e1068f27769ef65013 100644 (file)
@@ -80,7 +80,7 @@ public class SearchActionTest {
   public void json_example() {
     OrganizationDto organizationDto = db.organizations().insert();
     ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto).setKey(KEY_PROJECT_EXAMPLE_001));
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
     SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setCreatedAt(parseDateTime("2016-12-11T17:12:45+0100").getTime()));
     SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setCreatedAt(parseDateTime("2016-12-12T17:12:45+0100").getTime()));
     db.events().insertEvent(newEvent(a1).setUuid("E11")
@@ -105,7 +105,7 @@ public class SearchActionTest {
   @Test
   public void return_analyses_ordered_by_analysis_date() {
     ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert()).setKey("P1"));
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
     db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setCreatedAt(1_000_000L));
     db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setCreatedAt(2_000_000L));
     db.components().insertSnapshot(newAnalysis(project).setUuid("A3").setCreatedAt(3_000_000L));
@@ -122,7 +122,7 @@ public class SearchActionTest {
   @Test
   public void return_only_processed_analyses() {
     ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization()).setKey("P1"));
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
     db.components().insertSnapshot(newAnalysis(project).setUuid("A1"));
     db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setStatus(SnapshotDto.STATUS_UNPROCESSED));
 
@@ -136,7 +136,7 @@ public class SearchActionTest {
   public void return_events() {
     OrganizationDto organizationDto = db.organizations().insert();
     ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto).setKey("P1"));
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
     SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1"));
     SnapshotDto a42 = db.components().insertSnapshot(newAnalysis(newProjectDto(organizationDto)).setUuid("A42"));
     EventDto e1 = db.events().insertEvent(newEvent(a1).setUuid("E1").setName("N1").setCategory(EventCategory.QUALITY_GATE.getLabel()).setDescription("D1"));
@@ -156,7 +156,7 @@ public class SearchActionTest {
   @Test
   public void paginate_analyses() {
     ComponentDto project = db.components().insertProject();
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
     IntStream.rangeClosed(1, 9).forEach(i -> db.components().insertSnapshot(newAnalysis(project).setCreatedAt(1_000_000L * i).setUuid("A" + i)));
 
     SearchResponse result = call(SearchRequest.builder()
@@ -172,7 +172,7 @@ public class SearchActionTest {
   @Test
   public void filter_by_category() {
     ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert()).setKey("P1"));
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
     SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1"));
     SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(project).setUuid("A2"));
     SnapshotDto a42 = db.components().insertSnapshot(newAnalysis(project).setUuid("A42"));
@@ -193,7 +193,7 @@ public class SearchActionTest {
   @Test
   public void paginate_with_filter_on_category() {
     ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert()).setKey("P1"));
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
     SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setCreatedAt(1_000_000L));
     SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setCreatedAt(2_000_000L));
     SnapshotDto a3 = db.components().insertSnapshot(newAnalysis(project).setUuid("A3").setCreatedAt(3_000_000L));
index f59583af161675d004fe93dc7b61f6f3d12d5db2..2524d7e2f3673a0081cc272e49015d0514aad45f 100644 (file)
@@ -82,6 +82,7 @@ public class UpdateEventActionTest {
 
     assertJson(result).isSimilarTo(getClass().getResource("update_event-example.json"));
   }
+
   @Test
   public void update_name_in_db() {
     SnapshotDto analysis = createAnalysisAndLogInAsProjectAdministrator("5.6");
@@ -161,7 +162,7 @@ public class UpdateEventActionTest {
     ComponentDto project = newProjectDto(db.organizations().insert());
     SnapshotDto analysis = db.components().insertProjectAndSnapshot(project);
     db.events().insertEvent(newEvent(analysis).setUuid("E1"));
-    userSession.logIn().addProjectUuidPermissions(project.uuid(), UserRole.USER);
+    userSession.logIn().addProjectPermission(UserRole.USER, project);
 
     expectedException.expect(ForbiddenException.class);
 
@@ -232,7 +233,7 @@ public class UpdateEventActionTest {
   }
 
   private void logInAsProjectAdministrator(ComponentDto project) {
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
   }
 
   private SnapshotDto createAnalysisAndLogInAsProjectAdministrator(String version) {
index 2178d69340c6c0b6a88ca7c25f7fd8308ae6d80b..81fc3651c4f20ed261536bd6969f537da73a23b7 100644 (file)
@@ -226,6 +226,6 @@ public class CreateActionTest {
   }
 
   private void logInAsProjectAdministrator(ComponentDto project) {
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
   }
 }
index 06d0a56041e7b2f333aae560bda7ec3109472e42..ad81d1daea9da860a2607f6e9ef04a5449e2c8a7 100644 (file)
@@ -100,7 +100,7 @@ public class DeleteActionTest {
     ComponentLinkDto customLink2 = insertCustomLink(project2.uuid());
     Long id1 = customLink1.getId();
     Long id2 = customLink2.getId();
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project1.uuid(), project2.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project1, project2);
 
     deleteLink(id1);
     assertLinkIsDeleted(id1);
@@ -206,6 +206,6 @@ public class DeleteActionTest {
   }
 
   private void logInAsProjectAdministrator(ComponentDto project) {
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
   }
 }
index 29ff9d0d6dc47d7a279c15ce4f244012442b6799..a48d7fa38b956d0e773f829657efac55ea3418a4 100644 (file)
@@ -166,7 +166,7 @@ public class SearchActionTest {
   @Test
   public void project_administrator_can_search_for_links() throws IOException {
     ComponentDto project = insertProject();
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     checkItWorks(project);
   }
@@ -174,7 +174,7 @@ public class SearchActionTest {
   @Test
   public void project_user_can_search_for_links() throws IOException {
     ComponentDto project = insertProject();
-    userSession.logIn().addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.USER, project);
 
     checkItWorks(project);
   }
@@ -270,6 +270,6 @@ public class SearchActionTest {
   }
 
   private void logInAsProjectAdministrator(ComponentDto project) {
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
   }
 }
index 3af5a737aac386aa170359260711f3520593e99b..086f7c18b8466f4d3a5073643ad20b9ba43126c4 100644 (file)
@@ -99,7 +99,7 @@ public class SetActionTest {
 
   @Test
   public void set_tags_as_project_admin() {
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     call(project.key(), "platform, lambda");
 
@@ -123,7 +123,7 @@ public class SetActionTest {
 
   @Test
   public void fail_if_not_project_admin() {
-    userSession.logIn().addProjectUuidPermissions(UserRole.USER, project.key());
+    userSession.logIn().addProjectPermission(UserRole.USER, project);
 
     expectedException.expect(ForbiddenException.class);
 
index 7d254e01226188f0423554c8b57f05223b572c50..8be1173c0a8d138c5e3855436cba11b0e775787b 100644 (file)
@@ -391,7 +391,7 @@ public class IndexActionTest {
 
   @Test
   public void does_not_fail_when_user_has_not_project_browse_permission() throws Exception {
-    userSession.logIn("project-admin").addProjectUuidPermissions(CODEVIEWER, project.uuid());
+    userSession.logIn("project-admin").addProjectPermission(CODEVIEWER, project);
     definitions.addComponent(PropertyDefinition.builder("foo").build());
     propertyDb.insertProperties(newComponentPropertyDto(project).setKey("foo").setValue("one"));
 
@@ -468,7 +468,7 @@ public class IndexActionTest {
   }
 
   private void logInAsProjectUser() {
-    userSession.logIn().addProjectUuidPermissions(USER, project.uuid());
+    userSession.logIn().addProjectPermission(USER, project);
   }
 
   private void logInAsSystemAdministrator() {
@@ -477,8 +477,8 @@ public class IndexActionTest {
 
   private void logInAsProjectAdmin() {
     userSession.logIn()
-      .addProjectUuidPermissions(ADMIN, project.uuid())
-      .addProjectUuidPermissions(USER, project.uuid());
+      .addProjectPermission(ADMIN, project)
+      .addProjectPermission(USER, project);
   }
 
   protected static URL resource(String s) {
index a4231ce98989cd1a80fcdc0bf8c28eb8fa40bfb6..debfee708d14b97eeef7f1cb92c6950aa0677d73 100644 (file)
@@ -117,7 +117,7 @@ public class DeselectActionTest {
     String gateId = String.valueOf(gate.getId());
     associateProjectToQualityGate(project.getId(), gateId);
 
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     callByKey(gateId, project.getKey());
 
@@ -162,7 +162,7 @@ public class DeselectActionTest {
   public void fail_when_not_project_admin() throws Exception {
     String gateId = String.valueOf(gate.getId());
 
-    userSession.logIn().addProjectUuidPermissions(UserRole.ISSUE_ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ISSUE_ADMIN, project);
 
     expectedException.expect(ForbiddenException.class);
 
index 40a633efb4b62f1c4ecc04e7076c9b08530ac8bc..522eb69c460800e1335bd50c58961e8d78d2f259 100644 (file)
@@ -40,7 +40,6 @@ import org.sonar.server.qualitygate.QualityGateFinder;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.WsActionTester;
-import org.sonarqube.ws.MediaTypes;
 import org.sonarqube.ws.WsQualityGates;
 import org.sonarqube.ws.WsQualityGates.GetByProjectWsResponse;
 
@@ -136,7 +135,7 @@ public class GetByProjectActionTest {
   @Test
   public void get_with_project_admin_permission() {
     ComponentDto project = componentDb.insertProject();
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
     QualityGateDto dbQualityGate = insertQualityGate("Sonar way");
     setDefaultQualityGate(dbQualityGate.getId());
 
@@ -148,7 +147,7 @@ public class GetByProjectActionTest {
   @Test
   public void get_with_project_user_permission() {
     ComponentDto project = componentDb.insertProject();
-    userSession.logIn().addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.USER, project);
     QualityGateDto dbQualityGate = insertQualityGate("Sonar way");
     setDefaultQualityGate(dbQualityGate.getId());
 
@@ -234,6 +233,6 @@ public class GetByProjectActionTest {
   }
 
   private void logInAsProjectUser(ComponentDto project) {
-    userSession.logIn().addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.USER, project);
   }
 }
index f169360e8b5aafa7b2d076d83cab8e3bc17f8f71..85f835eeb660392b4722c882f9568dec76e85340 100644 (file)
@@ -78,7 +78,7 @@ public class ProjectStatusActionTest {
   @Test
   public void json_example() throws IOException {
     ComponentDto project = db.components().insertProject(db.organizations().insert());
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
 
     SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project)
       .setPeriodMode("last_version")
@@ -113,7 +113,7 @@ public class ProjectStatusActionTest {
       newMeasureDto(metric, project, snapshot)
         .setData(IOUtils.toString(getClass().getResource("ProjectStatusActionTest/measure_data.json"))));
     dbSession.commit();
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
 
     String response = ws.newRequest()
       .setParam(PARAM_PROJECT_ID, project.uuid())
@@ -136,7 +136,7 @@ public class ProjectStatusActionTest {
       newMeasureDto(metric, project, snapshot)
         .setData(IOUtils.toString(getClass().getResource("ProjectStatusActionTest/measure_data.json"))));
     dbSession.commit();
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
 
     String response = ws.newRequest()
       .setParam(PARAM_PROJECT_KEY, "project-key")
@@ -150,7 +150,7 @@ public class ProjectStatusActionTest {
     ComponentDto project = db.components().insertProject(db.organizations().insert());
     SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
     dbSession.commit();
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
 
     ProjectStatusWsResponse result = call(snapshot.getUuid());
 
@@ -161,7 +161,7 @@ public class ProjectStatusActionTest {
   @Test
   public void return_undefined_status_if_snapshot_is_not_found() {
     ComponentDto project = db.components().insertProject(db.organizations().insert());
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
 
     ProjectStatusWsResponse result = callByProjectUuid(project.uuid());
 
@@ -174,7 +174,7 @@ public class ProjectStatusActionTest {
     ComponentDto project = db.components().insertProject(db.organizations().insert());
     SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
     dbSession.commit();
-    userSession.addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.addProjectPermission(UserRole.ADMIN, project);
 
     call(snapshot.getUuid());
   }
@@ -184,7 +184,7 @@ public class ProjectStatusActionTest {
     ComponentDto project = db.components().insertProject(db.organizations().insert());
     SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
     dbSession.commit();
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
 
     call(snapshot.getUuid());
   }
index 30347da369481d06cf8d66741b9c6ae14009f49a..c89cdb21347a3be4bae7fca658d62e54f690c086 100644 (file)
@@ -99,7 +99,7 @@ public class SelectActionTest {
 
   @Test
   public void project_admin() throws Exception {
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
     String gateId = String.valueOf(gate.getId());
 
     callByKey(gateId, project.getKey());
@@ -153,7 +153,7 @@ public class SelectActionTest {
   public void fail_when_not_project_admin() throws Exception {
     String gateId = String.valueOf(gate.getId());
 
-    userSession.logIn().addProjectUuidPermissions(UserRole.ISSUE_ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ISSUE_ADMIN, project);
 
     expectedException.expect(ForbiddenException.class);
     callByKey(gateId, project.getKey());
index 7c3656561db5b5e13c5e25ebf6b217cc931ae07a..d3f59227c0588b26461861e51a8c3fcc93e063d6 100644 (file)
@@ -172,7 +172,7 @@ public class AddProjectActionTest {
   public void project_administrator_can_change_profile() throws Exception {
     ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
     QualityProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     call(project, profile);
 
index 5ff0737471cebdd38350f6dc498259adddc1b373..3e9ccc3b38938e9b7cac4d19042c8397c4841436 100644 (file)
@@ -112,7 +112,7 @@ public class RemoveProjectActionTest {
     ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
     QualityProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
     db.qualityProfiles().associateProjectWithQualityProfile(project, profile);
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     call(project, profile);
 
index 8abc30b9bbd6dde680dc8f962df65f9b7db5b82d..c0b895e0995e7bfa9a899771ec3aee4b1f114dbb 100644 (file)
@@ -383,7 +383,7 @@ public class ListDefinitionsActionTest {
 
   @Test
   public void fail_when_user_has_not_project_browse_permission() throws Exception {
-    userSession.logIn("project-admin").addProjectUuidPermissions(CODEVIEWER, project.uuid());
+    userSession.logIn("project-admin").addProjectPermission(CODEVIEWER, project);
     propertyDefinitions.addComponent(PropertyDefinition.builder("foo").build());
 
     expectedException.expect(ForbiddenException.class);
@@ -469,7 +469,7 @@ public class ListDefinitionsActionTest {
   }
 
   private void logInAsProjectUser() {
-    userSession.logIn().addProjectUuidPermissions(USER, project.uuid());
+    userSession.logIn().addProjectPermission(USER, project);
   }
 
   private void logInAsAdmin(OrganizationDto org) {
@@ -478,8 +478,8 @@ public class ListDefinitionsActionTest {
 
   private void logInAsProjectAdmin() {
     userSession.logIn()
-      .addProjectUuidPermissions(ADMIN, project.uuid())
-      .addProjectUuidPermissions(USER, project.uuid());
+      .addProjectPermission(ADMIN, project)
+      .addProjectPermission(USER, project);
   }
 
 }
index 35c54e084eee5218b4460348b9ce135eba5897be..a8cfe9634caf56eaf9bbbc4f828621b43eb2f9c8 100644 (file)
@@ -230,7 +230,7 @@ public class ResetActionTest {
 
   @Test
   public void throw_ForbiddenException_if_project_setting_and_not_project_administrator() throws Exception {
-    userSession.logIn().addProjectUuidPermissions(USER, project.uuid());
+    userSession.logIn().addProjectPermission(USER, project);
     definitions.addComponent(PropertyDefinition.builder("foo").build());
 
     expectedException.expect(ForbiddenException.class);
@@ -317,7 +317,7 @@ public class ResetActionTest {
   }
 
   private void logInAsProjectAdmin() {
-    userSession.logIn().addProjectUuidPermissions(ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(ADMIN, project);
   }
 
   private void assertGlobalPropertyDoesNotExist(String key) {
index 9c33f5565370860bf853a8210faddcfd2f5f5816..06f235568614859938e6a19802197d4661ad0659 100644 (file)
@@ -901,6 +901,6 @@ public class SetActionTest {
 
   }
   private void logInAsProjectAdministrator(ComponentDto project) {
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
   }
 }
index 35e0adda7a9dbae3b0b1717d1fd58b8a864b3563..a959bbf645be351ea2a9b740222d94dfce37996d 100644 (file)
@@ -561,8 +561,8 @@ public class ValuesActionTest {
   @Test
   public void return_component_secured_settings_when_not_authenticated_but_with_scan_permission() throws Exception {
     userSession
-      .addProjectUuidPermissions(USER, project.uuid())
-      .addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
+      .addProjectPermission(USER, project)
+      .addProjectPermission(SCAN_EXECUTION, project);
     definitions.addComponents(asList(
       PropertyDefinition.builder("foo").onQualifiers(PROJECT).build(),
       PropertyDefinition.builder("global.secret.secured").build(),
@@ -586,8 +586,8 @@ public class ValuesActionTest {
   @Test
   public void return_component_secured_settings_even_if_not_defined_when_not_authenticated_but_with_scan_permission() throws Exception {
     userSession
-      .addProjectUuidPermissions(USER, project.uuid())
-      .addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
+      .addProjectPermission(USER, project)
+      .addProjectPermission(SCAN_EXECUTION, project);
     propertyDb.insertProperties(newComponentPropertyDto(project).setKey("not-defined.secured").setValue("123"));
 
     ValuesWsResponse result = executeRequestForProjectProperties("not-defined.secured");
@@ -728,7 +728,7 @@ public class ValuesActionTest {
 
   @Test
   public void fail_when_user_has_not_project_browse_permission() throws Exception {
-    userSession.logIn("project-admin").addProjectUuidPermissions(CODEVIEWER, project.uuid());
+    userSession.logIn("project-admin").addProjectPermission(CODEVIEWER, project);
     definitions.addComponent(PropertyDefinition.builder("foo").build());
 
     expectedException.expect(ForbiddenException.class);
@@ -818,7 +818,7 @@ public class ValuesActionTest {
   }
 
   private void logInAsProjectUser() {
-    userSession.logIn().addProjectUuidPermissions(USER, project.uuid());
+    userSession.logIn().addProjectPermission(USER, project);
   }
 
   private void logInAsAdmin() {
@@ -827,8 +827,8 @@ public class ValuesActionTest {
 
   private void logInAsProjectAdmin() {
     userSession.logIn()
-      .addProjectUuidPermissions(ADMIN, project.uuid())
-      .addProjectUuidPermissions(USER, project.uuid());
+      .addProjectPermission(ADMIN, project)
+      .addProjectPermission(USER, project);
   }
 
   private void assertSetting(Settings.Setting setting, String expectedKey, String expectedValue, boolean expectedInherited) {
index d63d24042a8eea93484826d8d376aa65c9d7544e..9f82b15bddbd016bbfc790d5f67a8eee93ee01eb 100644 (file)
@@ -62,7 +62,7 @@ public class HashActionTest {
   @Test
   public void show_hashes() throws Exception {
     db.prepareDbUnit(getClass(), "shared.xml");
-    userSessionRule.logIn("polop").addProjectUuidPermissions(UserRole.USER, PROJECT_UUID);
+    loginAndAddProjectPermission(PROJECT_UUID, UserRole.USER);
 
     WsTester.TestRequest request = tester.newGetRequest("api/sources", "hash").setParam("key", COMPONENT_KEY);
     assertThat(request.execute().outputAsString()).isEqualTo("987654");
@@ -71,7 +71,7 @@ public class HashActionTest {
   @Test
   public void show_hashes_on_test_file() throws Exception {
     db.prepareDbUnit(getClass(), "show_hashes_on_test_file.xml");
-    userSessionRule.logIn("polop").addProjectUuidPermissions(UserRole.USER, PROJECT_UUID);
+    loginAndAddProjectPermission(PROJECT_UUID, UserRole.USER);
 
     WsTester.TestRequest request = tester.newGetRequest("api/sources", "hash").setParam("key", "ActionTest.java");
     assertThat(request.execute().outputAsString()).isEqualTo("987654");
@@ -80,7 +80,7 @@ public class HashActionTest {
   @Test
   public void hashes_empty_if_no_source() throws Exception {
     db.prepareDbUnit(getClass(), "no_source.xml");
-    userSessionRule.logIn("polop").addProjectUuidPermissions(UserRole.USER, PROJECT_UUID);
+    loginAndAddProjectPermission(PROJECT_UUID, UserRole.USER);
 
     WsTester.TestRequest request = tester.newGetRequest("api/sources", "hash").setParam("key", COMPONENT_KEY);
     request.execute().assertNoContent();
@@ -88,7 +88,6 @@ public class HashActionTest {
 
   @Test
   public void fail_to_show_hashes_if_file_does_not_exist() {
-    userSessionRule.logIn("polop").addProjectUuidPermissions(UserRole.USER, PROJECT_UUID);
     try {
       WsTester.TestRequest request = tester.newGetRequest("api/sources", "hash").setParam("key", COMPONENT_KEY);
       request.execute();
@@ -105,4 +104,8 @@ public class HashActionTest {
     userSessionRule.logIn("polop");
     tester.newGetRequest("api/sources", "hash").setParam("key", COMPONENT_KEY).execute();
   }
+
+  private void loginAndAddProjectPermission(String componentUuid, String permission) {
+    userSessionRule.logIn("polop").addProjectPermission(permission, db.getDbClient().componentDao().selectByUuid(db.getSession(), componentUuid).get());
+  }
 }
index 1a8b0d8d0a2f4f73e5afb7415c059d18ec0ef121..43c58740d31739a4c9be80fd59b852532199c4e9 100644 (file)
@@ -59,7 +59,7 @@ public class IndexActionTest {
   @Test
   public void get_json() throws Exception {
     ComponentDto project = db.components().insertProject();
-    userSession.addProjectUuidPermissions(CODEVIEWER, project.uuid());
+    userSession.addProjectPermission(CODEVIEWER, project);
     ComponentDto file = db.components().insertComponent(newFileDto(project));
     insertFileWithData(file, newData("public class HelloWorld {", "}"));
 
@@ -78,7 +78,7 @@ public class IndexActionTest {
   @Test
   public void limit_range() throws Exception {
     ComponentDto project = db.components().insertProject();
-    userSession.addProjectUuidPermissions(CODEVIEWER, project.uuid());
+    userSession.addProjectPermission(CODEVIEWER, project);
     ComponentDto file = db.components().insertComponent(newFileDto(project));
     insertFileWithData(file, newData("/**", " */", "public class HelloWorld {", "}", "", "foo"));
 
@@ -99,7 +99,7 @@ public class IndexActionTest {
   @Test
   public void fail_when_missing_code_viewer_permission() throws Exception {
     ComponentDto project = db.components().insertProject();
-    userSession.addProjectUuidPermissions(USER, project.uuid());
+    userSession.addProjectPermission(USER, project);
     ComponentDto file = db.components().insertComponent(newFileDto(project));
 
     expectedException.expect(ForbiddenException.class);
index d7a8d1fcc9b512a907f227f912eaece44aea300b..cabdda93a8676d72c693073b5c3a475d9500cb4f 100644 (file)
@@ -63,11 +63,12 @@ public class LinesActionTest {
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
 
   SourceService sourceService;
-
   HtmlSourceDecorator htmlSourceDecorator;
-
   ComponentDao componentDao;
 
+  ComponentDto project;
+  ComponentDto file;
+
   WsTester wsTester;
 
   @Before
@@ -83,12 +84,14 @@ public class LinesActionTest {
     componentDao = new ComponentDao();
     wsTester = new WsTester(new SourcesWs(
       new LinesAction(new ComponentFinder(dbTester.getDbClient()), dbTester.getDbClient(), sourceService, htmlSourceDecorator, userSessionRule)));
+    project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), PROJECT_UUID);
+    file = ComponentTesting.newFileDto(project, null, FILE_UUID).setKey(FILE_KEY);
   }
 
   @Test
   public void show_source() throws Exception {
-    setUserWithValidPermission();
     insertFileWithData(FileSourceTesting.newFakeData(3).build());
+    setUserWithValidPermission();
 
     WsTester.TestRequest request = wsTester.newGetRequest("api/sources", "lines").setParam("uuid", FILE_UUID);
     request.execute().assertJson(getClass(), "show_source.json");
@@ -156,8 +159,8 @@ public class LinesActionTest {
 
   @Test
   public void display_deprecated_fields() throws Exception {
-    setUserWithValidPermission();
     insertFileWithData(FileSourceTesting.newFakeData(1).build());
+    setUserWithValidPermission();
 
     WsTester.TestRequest request = wsTester
       .newGetRequest("api/sources", "lines")
@@ -168,7 +171,6 @@ public class LinesActionTest {
 
   @Test
   public void use_deprecated_overall_coverage_fields_if_exists() throws Exception {
-    setUserWithValidPermission();
     DbFileSources.Data.Builder dataBuilder = DbFileSources.Data.newBuilder();
     insertFileWithData(dataBuilder.addLines(newLineBuilder()
       .setDeprecatedOverallLineHits(1)
@@ -180,6 +182,7 @@ public class LinesActionTest {
       .setDeprecatedItLineHits(1)
       .setDeprecatedItConditions(2)
       .setDeprecatedItCoveredConditions(3)).build());
+    setUserWithValidPermission();
 
     WsTester.TestRequest request = wsTester
       .newGetRequest("api/sources", "lines")
@@ -190,7 +193,6 @@ public class LinesActionTest {
 
   @Test
   public void use_deprecated_ut_coverage_fields_if_exists() throws Exception {
-    setUserWithValidPermission();
     DbFileSources.Data.Builder dataBuilder = DbFileSources.Data.newBuilder();
     insertFileWithData(dataBuilder.addLines(newLineBuilder()
       .setDeprecatedUtLineHits(1)
@@ -199,6 +201,7 @@ public class LinesActionTest {
       .setDeprecatedItLineHits(1)
       .setDeprecatedItConditions(2)
       .setDeprecatedItCoveredConditions(3)).build());
+    setUserWithValidPermission();
 
     WsTester.TestRequest request = wsTester
       .newGetRequest("api/sources", "lines")
@@ -209,12 +212,12 @@ public class LinesActionTest {
 
   @Test
   public void use_deprecated_it_coverage_fields_if_exists() throws Exception {
-    setUserWithValidPermission();
     DbFileSources.Data.Builder dataBuilder = DbFileSources.Data.newBuilder();
     insertFileWithData(dataBuilder.addLines(newLineBuilder()
       .setDeprecatedItLineHits(1)
       .setDeprecatedItConditions(2)
       .setDeprecatedItCoveredConditions(3)).build());
+    setUserWithValidPermission();
 
     WsTester.TestRequest request = wsTester
       .newGetRequest("api/sources", "lines")
@@ -233,12 +236,10 @@ public class LinesActionTest {
   }
 
   private void setUserWithValidPermission() {
-    userSessionRule.logIn("login").addProjectUuidPermissions(UserRole.CODEVIEWER, PROJECT_UUID);
+    userSessionRule.logIn("login").addProjectPermission(UserRole.CODEVIEWER, project, file);
   }
 
   private void insertFile() throws IOException {
-    ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), PROJECT_UUID);
-    ComponentDto file = ComponentTesting.newFileDto(project, null, FILE_UUID).setKey(FILE_KEY);
     componentDao.insert(dbTester.getSession(), project, file);
     dbTester.getSession().commit();
   }
index eb785d10ce7fdce42bdbc02368cbbe7ba8245bd5..e0e44c65cc6ab6c6e6ec5507e19ab96d6be7ab23 100644 (file)
@@ -76,7 +76,7 @@ public class RawActionTest {
   @Test
   public void get_txt() throws Exception {
     String fileKey = "src/Foo.java";
-    userSessionRule.addProjectUuidPermissions(UserRole.CODEVIEWER, project.uuid());
+    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project);
     when(componentDao.selectByKey(session, fileKey)).thenReturn(com.google.common.base.Optional.of(file));
 
     Iterable<String> lines = newArrayList(
index 998bbc1a21a43282f2d12145f901acffcfeec1f6..6fc112242cf9cea75a130a2c95a9b6e9270eaa77 100644 (file)
@@ -55,17 +55,23 @@ public class ScmActionTest {
   private WsTester tester;
   private DbClient dbClient = dbTester.getDbClient();
   private DbSession dbSession = dbTester.getSession();
+  private ComponentDto project;
+  private ComponentDto file;
 
   @Before
   public void setUp() {
     tester = new WsTester(
       new SourcesWs(new ScmAction(dbClient, new SourceService(dbTester.getDbClient(), new HtmlSourceDecorator()), userSessionRule, new ComponentFinder(dbClient))));
+
+    project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), PROJECT_UUID);
+    file = ComponentTesting.newFileDto(project, null, FILE_UUID).setKey(FILE_KEY);
+    dbClient.componentDao().insert(dbTester.getSession(), project, file);
+    dbTester.getSession().commit();
   }
 
   @Test
   public void show_scm() throws Exception {
-    initFile();
-    userSessionRule.addProjectUuidPermissions(UserRole.CODEVIEWER, PROJECT_UUID);
+    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
 
     dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto()
       .setProjectUuid(PROJECT_UUID)
@@ -80,8 +86,7 @@ public class ScmActionTest {
 
   @Test
   public void show_scm_from_given_range_lines() throws Exception {
-    initFile();
-    userSessionRule.addProjectUuidPermissions(UserRole.CODEVIEWER, PROJECT_UUID);
+    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
 
     dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto()
       .setProjectUuid(PROJECT_UUID)
@@ -100,8 +105,7 @@ public class ScmActionTest {
 
   @Test
   public void not_group_lines_by_commit() throws Exception {
-    initFile();
-    userSessionRule.addProjectUuidPermissions(UserRole.CODEVIEWER, PROJECT_UUID);
+    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
 
     // lines 1 and 2 are the same commit, but not 3 (different date)
     dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto()
@@ -122,8 +126,7 @@ public class ScmActionTest {
 
   @Test
   public void group_lines_by_commit() throws Exception {
-    initFile();
-    userSessionRule.addProjectUuidPermissions(UserRole.CODEVIEWER, PROJECT_UUID);
+    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
 
     // lines 1 and 2 are the same commit, but not 3 (different date)
     dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto()
@@ -144,8 +147,7 @@ public class ScmActionTest {
 
   @Test
   public void accept_negative_value_in_from_parameter() throws Exception {
-    initFile();
-    userSessionRule.addProjectUuidPermissions(UserRole.CODEVIEWER, PROJECT_UUID);
+    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
 
     dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto()
       .setProjectUuid(PROJECT_UUID)
@@ -165,8 +167,7 @@ public class ScmActionTest {
 
   @Test
   public void return_empty_value_when_no_scm() throws Exception {
-    initFile();
-    userSessionRule.addProjectUuidPermissions(UserRole.CODEVIEWER, PROJECT_UUID);
+    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
 
     dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto()
       .setProjectUuid(PROJECT_UUID)
@@ -180,19 +181,12 @@ public class ScmActionTest {
 
   @Test(expected = ForbiddenException.class)
   public void fail_without_code_viewer_permission() throws Exception {
-    initFile();
-    userSessionRule.addProjectUuidPermissions(UserRole.USER, PROJECT_UUID);
+    userSessionRule.addProjectPermission(UserRole.USER, project, file);
 
     WsTester.TestRequest request = tester.newGetRequest("api/sources", "scm").setParam("key", FILE_KEY);
     request.execute();
   }
 
-  private void initFile() {
-    ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), PROJECT_UUID);
-    dbClient.componentDao().insert(dbTester.getSession(), project, ComponentTesting.newFileDto(project, null, FILE_UUID).setKey(FILE_KEY));
-    dbTester.getSession().commit();
-  }
-
   private DbFileSources.Line newSourceLine(String author, String revision, Date date, int line) {
     return DbFileSources.Line.newBuilder()
       .setScmAuthor(author)
index f99eb8a6b48c9d6262b5a856619cef7ca4ec04f6..2d88ec0e59a60c78a7484628c1b79237d31d0f3c 100644 (file)
@@ -78,7 +78,7 @@ public class ShowActionTest {
   @Test
   public void show_source() throws Exception {
     String fileKey = "src/Foo.java";
-    userSessionRule.addProjectUuidPermissions(UserRole.CODEVIEWER, project.uuid());
+    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project);
     when(componentDao.selectByKey(session, fileKey)).thenReturn(com.google.common.base.Optional.of(file));
     when(sourceService.getLinesAsHtml(eq(session), eq(file.uuid()), anyInt(), anyInt())).thenReturn(Optional.of(newArrayList(
       "/*",
@@ -95,7 +95,7 @@ public class ShowActionTest {
   @Test
   public void show_source_with_from_and_to_params() throws Exception {
     String fileKey = "src/Foo.java";
-    userSessionRule.addProjectUuidPermissions(UserRole.CODEVIEWER, project.uuid());
+    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project);
     when(componentDao.selectByKey(session, fileKey)).thenReturn(com.google.common.base.Optional.of(file));
     when(sourceService.getLinesAsHtml(session, file.uuid(), 3, 5)).thenReturn(Optional.of(newArrayList(
       " */",
@@ -112,7 +112,7 @@ public class ShowActionTest {
   @Test
   public void show_source_accept_from_less_than_one() throws Exception {
     String fileKey = "src/Foo.java";
-    userSessionRule.addProjectUuidPermissions(UserRole.CODEVIEWER, project.uuid());
+    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project);
     when(componentDao.selectByKey(session, fileKey)).thenReturn(com.google.common.base.Optional.of(file));
     when(sourceService.getLinesAsHtml(session, file.uuid(), 1, 5)).thenReturn(Optional.of(newArrayList(
       " */",
index cc7f58e8e2902170dbdc60f31d47852d4279e23e..20dbef657aa9cd6552458fdea160dc52f89c2aaf 100644 (file)
@@ -28,6 +28,8 @@ import org.junit.rules.ExpectedException;
 import org.sonar.api.web.UserRole;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
+import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
 import org.sonar.db.organization.OrganizationDto;
 import org.sonar.db.organization.OrganizationTesting;
 import org.sonar.server.exceptions.NotFoundException;
@@ -51,17 +53,17 @@ import static org.sonar.test.JsonAssert.assertJson;
 
 public class CoveredFilesActionTest {
 
-  public static final String FILE_1_ID = "FILE1";
-  public static final String FILE_2_ID = "FILE2";
+  private static final String FILE_1_ID = "FILE1";
+  private static final String FILE_2_ID = "FILE2";
 
   @Rule
   public UserSessionRule userSessionRule = UserSessionRule.standalone();
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
-  WsActionTester ws;
-  DbClient dbClient;
-  TestIndex testIndex;
+  private WsActionTester ws;
+  private DbClient dbClient;
+  private TestIndex testIndex;
 
   @Before
   public void setUp() {
@@ -73,7 +75,9 @@ public class CoveredFilesActionTest {
 
   @Test
   public void covered_files() {
-    userSessionRule.addComponentUuidPermission(UserRole.CODEVIEWER, "SonarQube", "test-file-uuid");
+    ComponentDto project = ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto(), "SonarQube");
+    ComponentDto file = ComponentTesting.newFileDto(project, null, "test-file-uuid");
+    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
 
     when(testIndex.getNullableByTestUuid(anyString())).thenReturn(Optional.of(new TestDoc().setFileUuid("test-file-uuid")));
     when(testIndex.coveredFiles("test-uuid")).thenReturn(Arrays.asList(
@@ -92,7 +96,9 @@ public class CoveredFilesActionTest {
 
   @Test
   public void fail_when_test_uuid_is_unknown() {
-    userSessionRule.addComponentUuidPermission(UserRole.CODEVIEWER, "SonarQube", "test-file-uuid");
+    ComponentDto project = ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto(), "SonarQube");
+    ComponentDto file = ComponentTesting.newFileDto(project);
+    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
 
     when(testIndex.getNullableByTestUuid(anyString())).thenReturn(Optional.<TestDoc>absent());
     when(testIndex.coveredFiles("test-uuid")).thenReturn(Arrays.asList(
index 15acd7da0323310a346577f18c5fc7e1419e607d..208f02dbd9aba5f88416b2e1f1b35860b62a8bd0 100644 (file)
@@ -89,7 +89,7 @@ public class ListActionTest {
 
   @Test
   public void list_tests() throws Exception {
-    userSessionRule.addProjectUuidPermissions(CODEVIEWER, project.uuid());
+    userSessionRule.addProjectPermission(CODEVIEWER, project);
     DbFileSources.Test test = newTest(mainFile, 10, 11, 12, 20, 21, 25).setStatus(OK).build();
     insertTests(testFile, test);
 
@@ -111,7 +111,7 @@ public class ListActionTest {
 
   @Test
   public void list_tests_by_test_uuid() throws Exception {
-    userSessionRule.addProjectUuidPermissions(CODEVIEWER, project.uuid());
+    userSessionRule.addProjectPermission(CODEVIEWER, project);
     DbFileSources.Test test1 = newTest(mainFile, 10).build();
     DbFileSources.Test test2 = newTest(mainFile, 11).build();
     insertTests(testFile, test1, test2);
@@ -123,7 +123,7 @@ public class ListActionTest {
 
   @Test
   public void list_tests_by_test_file_uuid() throws Exception {
-    userSessionRule.addProjectUuidPermissions(CODEVIEWER, project.uuid());
+    userSessionRule.addProjectPermission(CODEVIEWER, project);
     ComponentDto anotherTestFile = db.components().insertComponent(newFileDto(project));
     DbFileSources.Test test1 = newTest(mainFile, 10).build();
     DbFileSources.Test test2 = newTest(mainFile, 11).build();
@@ -138,7 +138,7 @@ public class ListActionTest {
 
   @Test
   public void list_tests_by_test_file_key() throws Exception {
-    userSessionRule.addProjectUuidPermissions(CODEVIEWER, project.uuid());
+    userSessionRule.addProjectPermission(CODEVIEWER, project);
     ComponentDto anotherTestFile = db.components().insertComponent(newFileDto(project));
     DbFileSources.Test test1 = newTest(mainFile, 10).build();
     DbFileSources.Test test2 = newTest(mainFile, 11).build();
@@ -153,7 +153,7 @@ public class ListActionTest {
 
   @Test
   public void list_tests_by_source_file_uuid_and_line_number() throws Exception {
-    userSessionRule.addProjectUuidPermissions(CODEVIEWER, project.uuid());
+    userSessionRule.addProjectPermission(CODEVIEWER, project);
     ComponentDto anotherMainFile = db.components().insertComponent(newFileDto(project));
     DbFileSources.Test test1 = newTest(mainFile, 10, 11, 12).build();
     DbFileSources.Test test2 = newTest(mainFile, 9, 11).build();
@@ -168,7 +168,7 @@ public class ListActionTest {
 
   @Test
   public void list_tests_by_source_file_key_and_line_number() throws Exception {
-    userSessionRule.addProjectUuidPermissions(CODEVIEWER, project.uuid());
+    userSessionRule.addProjectPermission(CODEVIEWER, project);
     ComponentDto anotherMainFile = db.components().insertComponent(newFileDto(project));
     DbFileSources.Test test1 = newTest(mainFile, 10, 11, 12).build();
     DbFileSources.Test test2 = newTest(mainFile, 9, 11).build();
@@ -183,7 +183,7 @@ public class ListActionTest {
 
   @Test
   public void tests_are_paginated() throws Exception {
-    userSessionRule.addProjectUuidPermissions(CODEVIEWER, project.uuid());
+    userSessionRule.addProjectPermission(CODEVIEWER, project);
     insertTests(testFile, newTest(mainFile, 10).build(), newTest(mainFile, 11).build(), newTest(mainFile, 12).build());
 
     ListResponse request = call(ws.newRequest().setParam(TEST_FILE_ID, testFile.uuid()));
@@ -195,7 +195,7 @@ public class ListActionTest {
 
   @Test
   public void fail_when_no_argument() throws Exception {
-    userSessionRule.addProjectUuidPermissions(CODEVIEWER, project.uuid());
+    userSessionRule.addProjectPermission(CODEVIEWER, project);
 
     expectedException.expect(IllegalArgumentException.class);
     call(ws.newRequest());
@@ -203,7 +203,7 @@ public class ListActionTest {
 
   @Test
   public void fail_when_source_file_uuid_without_line_number() throws Exception {
-    userSessionRule.addProjectUuidPermissions(CODEVIEWER, project.uuid());
+    userSessionRule.addProjectPermission(CODEVIEWER, project);
 
     expectedException.expect(IllegalArgumentException.class);
     call(ws.newRequest().setParam(SOURCE_FILE_ID, mainFile.uuid()));
@@ -211,7 +211,7 @@ public class ListActionTest {
 
   @Test
   public void fail_when_not_enough_privilege_on_test_uuid() throws Exception {
-    userSessionRule.addProjectUuidPermissions(USER, project.uuid());
+    userSessionRule.addProjectPermission(USER, project);
     DbFileSources.Test test = newTest(mainFile, 10).build();
     insertTests(testFile, test);
 
@@ -221,7 +221,7 @@ public class ListActionTest {
 
   @Test
   public void fail_when_no_enough_privilege_on_test_file_id() throws Exception {
-    userSessionRule.addProjectUuidPermissions(USER, project.uuid());
+    userSessionRule.addProjectPermission(USER, project);
     insertTests(testFile, newTest(mainFile, 10).build());
 
     expectedException.expect(ForbiddenException.class);
@@ -230,7 +230,7 @@ public class ListActionTest {
 
   @Test
   public void fail_when_not_enough_privilege_on_test_file_key() throws Exception {
-    userSessionRule.addProjectUuidPermissions(USER, project.uuid());
+    userSessionRule.addProjectPermission(USER, project);
     insertTests(testFile, newTest(mainFile, 10).build());
 
     expectedException.expect(ForbiddenException.class);
@@ -239,7 +239,7 @@ public class ListActionTest {
 
   @Test
   public void fail_when_not_enough_privilege_on_main_file_uuid() throws Exception {
-    userSessionRule.addProjectUuidPermissions(USER, project.uuid());
+    userSessionRule.addProjectPermission(USER, project);
     insertTests(testFile, newTest(mainFile, 10).build());
 
     expectedException.expect(ForbiddenException.class);
index 0f0b60ef6d3bf0206d59f4b6d30c25e3fe25b59f..c4f88e935b5ab751fa487d0ca61422fea0e8529f 100644 (file)
 package org.sonar.server.tester;
 
 import com.google.common.collect.HashMultimap;
-import java.util.List;
+import java.util.Arrays;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Optional;
+import java.util.Set;
+import org.sonar.db.component.ComponentDto;
 import org.sonar.db.permission.OrganizationPermission;
 import org.sonar.server.user.AbstractUserSession;
 
-import static com.google.common.collect.Lists.newArrayList;
 import static com.google.common.collect.Maps.newHashMap;
 
 public abstract class AbstractMockUserSession<T extends AbstractMockUserSession> extends AbstractUserSession {
@@ -34,7 +36,7 @@ public abstract class AbstractMockUserSession<T extends AbstractMockUserSession>
   private HashMultimap<String, String> projectUuidByPermission = HashMultimap.create();
   private final HashMultimap<String, OrganizationPermission> permissionsByOrganizationUuid = HashMultimap.create();
   private Map<String, String> projectUuidByComponentUuid = newHashMap();
-  private List<String> projectPermissionsCheckedByUuid = newArrayList();
+  private Set<String> projectPermissionsCheckedByUuid = new HashSet<>();
   private boolean systemAdministrator = false;
 
   protected AbstractMockUserSession(Class<T> clazz) {
@@ -51,22 +53,16 @@ public abstract class AbstractMockUserSession<T extends AbstractMockUserSession>
     return permissionsByOrganizationUuid.get(organizationUuid).contains(permission);
   }
 
-
-  public T addProjectUuidPermissions(String projectPermission, String... projectUuids) {
-    this.projectPermissionsCheckedByUuid.add(projectPermission);
-    this.projectUuidByPermission.putAll(projectPermission, newArrayList(projectUuids));
-    for (String projectUuid : projectUuids) {
-      this.projectUuidByComponentUuid.put(projectUuid, projectUuid);
-    }
+  public T addProjectPermission(String permission, ComponentDto... components) {
+    this.projectPermissionsCheckedByUuid.add(permission);
+    Arrays.stream(components)
+      .forEach(component -> {
+        this.projectUuidByPermission.put(permission, component.projectUuid());
+        this.projectUuidByComponentUuid.put(component.uuid(), component.projectUuid());
+      });
     return clazz.cast(this);
   }
 
-  public T addComponentUuidPermission(String projectPermission, String projectUuid, String componentUuid) {
-    this.projectUuidByComponentUuid.put(componentUuid, projectUuid);
-    addProjectUuidPermissions(projectPermission, projectUuid);
-    return clazz.cast(this);
-  }
-  
   @Override
   protected Optional<String> componentUuidToProjectUuid(String componentUuid) {
     return Optional.ofNullable(projectUuidByComponentUuid.get(componentUuid));
index 6e58b4074b075164f9fc61f2674fdd02f4c7bd43..5e10fa044897821f3cbb4345b6b120630b1f2894 100644 (file)
@@ -28,9 +28,9 @@ import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.organization.OrganizationDto;
+import org.sonar.db.permission.OrganizationPermission;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserDto;
-import org.sonar.db.permission.OrganizationPermission;
 import org.sonar.server.user.ThreadLocalUserSession;
 import org.sonar.server.user.UserSession;
 
@@ -187,8 +187,8 @@ public class UserSessionRule implements TestRule, UserSession {
     setCurrentUserSession(userSession);
   }
 
-  public UserSessionRule addProjectUuidPermissions(String projectPermission, String... projectUuids) {
-    ensureAbstractMockUserSession().addProjectUuidPermissions(projectPermission, projectUuids);
+  public UserSessionRule addProjectPermission(String projectPermission, ComponentDto... components) {
+    ensureAbstractMockUserSession().addProjectPermission(projectPermission, components);
     return this;
   }
 
@@ -216,11 +216,6 @@ public class UserSessionRule implements TestRule, UserSession {
     return this;
   }
 
-  public UserSessionRule addComponentUuidPermission(String projectPermission, String projectUuid, String componentUuid) {
-    ensureAbstractMockUserSession().addComponentUuidPermission(projectPermission, projectUuid, componentUuid);
-    return this;
-  }
-
   public UserSessionRule setName(@Nullable String s) {
     ensureMockUserSession().setName(s);
     return this;
index e6dad613f9ee19557c0a760cda17d1197eba4401..06d4d326370b53c3d9804f92bfbd767960b0ef6d 100644 (file)
@@ -131,7 +131,7 @@ public class ComponentActionTest {
   public void return_info_if_user_has_browse_permission_on_project() throws Exception {
     init();
     componentDbTester.insertComponent(project);
-    userSession.logIn().addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.USER, project);
 
     verifySuccess(project.key());
   }
@@ -140,7 +140,7 @@ public class ComponentActionTest {
   public void return_info_if_user_has_administration_permission_on_project() throws Exception {
     init();
     componentDbTester.insertComponent(project);
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     verifySuccess(project.key());
   }
@@ -158,7 +158,7 @@ public class ComponentActionTest {
   public void return_component_info_when_anonymous_no_snapshot() throws Exception {
     init();
     componentDbTester.insertComponent(project);
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
 
     executeAndVerify(project.key(), "return_component_info_when_anonymous_no_snapshot.json");
   }
@@ -169,7 +169,7 @@ public class ComponentActionTest {
     UserDto user = dbTester.users().insertUser("obiwan");
     componentDbTester.insertComponent(project);
     propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setResourceId(project.getId()).setUserId(user.getId()));
-    userSession.logIn(user).addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.logIn(user).addProjectPermission(UserRole.USER, project);
 
     executeAndVerify(project.key(), "return_component_info_with_favourite.json");
   }
@@ -182,7 +182,7 @@ public class ComponentActionTest {
       .setCreatedAt(DateUtils.parseDateTime("2015-04-22T11:44:00+0200").getTime())
       .setVersion("3.14")
       .setLast(true));
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
 
     executeAndVerify(project.key(), "return_component_info_when_snapshot.json");
   }
@@ -195,7 +195,7 @@ public class ComponentActionTest {
     addQualityProfiles(project, analysis,
       createQProfile("qp1", "Sonar Way Java", "java"),
       createQProfile("qp2", "Sonar Way Xoo", "xoo"));
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
 
     executeAndVerify(project.key(), "return_quality_profiles.json");
   }
@@ -204,7 +204,7 @@ public class ComponentActionTest {
   public void return_empty_quality_profiles_when_no_measure() throws Exception {
     init();
     componentDbTester.insertComponent(project);
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
 
     executeAndVerify(project.key(), "return_empty_quality_profiles_when_no_measure.json");
   }
@@ -215,7 +215,7 @@ public class ComponentActionTest {
     componentDbTester.insertComponent(project);
     QualityGateDto qualityGateDto = dbTester.qualityGates().insertQualityGate("Sonar way");
     dbTester.qualityGates().associateProjectToQualityGate(project, qualityGateDto);
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
 
     executeAndVerify(project.key(), "return_quality_gate.json");
   }
@@ -225,7 +225,7 @@ public class ComponentActionTest {
     init();
     componentDbTester.insertComponent(project);
     dbTester.qualityGates().createDefaultQualityGate("Sonar way");
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
 
     executeAndVerify(project.key(), "return_default_quality_gate.json");
   }
@@ -234,7 +234,7 @@ public class ComponentActionTest {
   public void return_no_quality_gate_when_not_defined_on_project_and_no_default_one() throws Exception {
     init();
     componentDbTester.insertComponent(project);
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
 
     String json = execute(project.key());
     assertThat(json).doesNotContain("qualityGate");
@@ -244,7 +244,7 @@ public class ComponentActionTest {
   public void return_extensions() throws Exception {
     init(createPages());
     componentDbTester.insertComponent(project);
-    userSession.anonymous().addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.anonymous().addProjectPermission(UserRole.USER, project);
 
     executeAndVerify(project.key(), "return_extensions.json");
   }
@@ -254,8 +254,8 @@ public class ComponentActionTest {
     init(createPages());
     componentDbTester.insertComponent(project);
     userSession.anonymous()
-      .addProjectUuidPermissions(UserRole.USER, project.uuid())
-      .addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+      .addProjectPermission(UserRole.USER, project)
+      .addProjectPermission(UserRole.ADMIN, project);
 
     executeAndVerify(project.key(), "return_extensions_for_admin.json");
   }
@@ -265,8 +265,8 @@ public class ComponentActionTest {
     UserDto user = dbTester.users().insertUser();
     componentDbTester.insertComponent(project);
     userSession.logIn(user)
-      .addProjectUuidPermissions(UserRole.USER, "abcd")
-      .addProjectUuidPermissions(UserRole.ADMIN, "abcd");
+      .addProjectPermission(UserRole.USER, project)
+      .addProjectPermission(UserRole.ADMIN, project);
 
     Page page1 = Page.builder("my_plugin/first_page")
       .setName("First Page")
@@ -290,8 +290,8 @@ public class ComponentActionTest {
     init();
     componentDbTester.insertComponent(project);
     userSession.anonymous()
-      .addProjectUuidPermissions(UserRole.USER, "abcd")
-      .addProjectUuidPermissions(UserRole.ADMIN, "abcd");
+      .addProjectPermission(UserRole.USER, project)
+      .addProjectPermission(UserRole.ADMIN, project);
 
     ResourceType projectResourceType = ResourceType.builder(project.qualifier())
       .setProperty("comparable", true)
@@ -313,8 +313,8 @@ public class ComponentActionTest {
     ComponentDto project = componentDbTester.insertComponent(this.project);
     ComponentDto module = componentDbTester.insertComponent(newModuleDto("bcde", project).setKey("palap").setName("Palap"));
     userSession.anonymous()
-      .addProjectUuidPermissions(UserRole.USER, "abcd")
-      .addProjectUuidPermissions(UserRole.ADMIN, "abcd");
+      .addProjectPermission(UserRole.USER, project)
+      .addProjectPermission(UserRole.ADMIN, project);
 
     executeAndVerify(module.key(), "return_breadcrumbs_on_module.json");
   }
@@ -324,7 +324,7 @@ public class ComponentActionTest {
     init();
     componentDbTester.insertComponent(project);
     userSession.logIn()
-      .addProjectUuidPermissions(UserRole.USER, project.uuid())
+      .addProjectPermission(UserRole.USER, project)
       .addPermission(ADMINISTER_QUALITY_PROFILES, project.getOrganizationUuid());
 
     executeAndVerify(project.key(), "return_configuration_for_quality_profile_admin.json");
@@ -335,7 +335,7 @@ public class ComponentActionTest {
     init();
     componentDbTester.insertComponent(project);
     userSession.logIn()
-      .addProjectUuidPermissions(UserRole.USER, project.uuid())
+      .addProjectPermission(UserRole.USER, project)
       .addPermission(ADMINISTER_QUALITY_GATES, project.getOrganizationUuid());
 
     executeAndVerify(project.key(), "return_configuration_for_quality_gate_admin.json");
@@ -350,7 +350,7 @@ public class ComponentActionTest {
     ComponentDto file = componentDbTester.insertComponent(newFileDto(directory, directory, "cdef").setName("Source.xoo")
       .setKey("palap:src/main/xoo/Source.xoo")
       .setPath(directory.path()));
-    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.addProjectPermission(UserRole.USER, project);
 
     executeAndVerify(file.key(), "return_bread_crumbs_on_several_levels.json");
   }
@@ -359,7 +359,7 @@ public class ComponentActionTest {
   public void project_administrator_is_allowed_to_get_information() throws Exception {
     init(createPages());
     componentDbTester.insertProjectAndSnapshot(project);
-    userSession.addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.addProjectPermission(UserRole.ADMIN, project);
 
     execute(project.key());
   }
@@ -387,8 +387,8 @@ public class ComponentActionTest {
     QualityGateDto qualityGateDto = dbTester.qualityGates().insertQualityGate("Sonar way");
     dbTester.qualityGates().associateProjectToQualityGate(project, qualityGateDto);
     userSession.logIn(user)
-      .addProjectUuidPermissions(UserRole.USER, project.uuid())
-      .addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+      .addProjectPermission(UserRole.USER, project)
+      .addProjectPermission(UserRole.ADMIN, project);
 
     String result = execute(project.key());
     assertJson(result).ignoreFields("snapshotDate", "key", "qualityGate.key").isSimilarTo(ws.getDef().responseExampleAsString());
@@ -401,12 +401,12 @@ public class ComponentActionTest {
     ComponentDto project = dbTester.components().insertProject(org);
 
     userSession.logIn()
-      .addProjectUuidPermissions(UserRole.ADMIN, project.uuid())
+      .addProjectPermission(UserRole.ADMIN, project)
       .addPermission(OrganizationPermission.ADMINISTER, org);
     assertJson(execute(project.key())).isSimilarTo("{\"configuration\": {\"canApplyPermissionTemplate\": true}}");
 
     userSession.logIn()
-      .addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+      .addProjectPermission(UserRole.ADMIN, project);
 
     assertJson(execute(project.key())).isSimilarTo("{\"configuration\": {\"canApplyPermissionTemplate\": false}}");
   }
index 776af78a28ef4041781b454e6a8f4d6c3b1510d9..ba7bd3f157a0dbd37fc88976f3bbcfacf3ec87c9 100644 (file)
@@ -82,7 +82,7 @@ public class WebhookDeliveriesActionTest {
 
   @Test
   public void search_by_component_and_return_no_records() throws Exception {
-    userSession.logIn().addProjectUuidPermissions(project.uuid(), UserRole.ADMIN);
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     Webhooks.DeliveriesWsResponse response = ws.newRequest()
       .setParam("componentKey", project.getKey())
@@ -93,7 +93,7 @@ public class WebhookDeliveriesActionTest {
 
   @Test
   public void search_by_task_and_return_no_records() throws Exception {
-    userSession.logIn().addProjectUuidPermissions(project.uuid(), UserRole.ADMIN);
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     Webhooks.DeliveriesWsResponse response = ws.newRequest()
       .setParam("ceTaskId", "t1")
@@ -116,7 +116,7 @@ public class WebhookDeliveriesActionTest {
       .setHttpStatus(200);
     dbClient.webhookDeliveryDao().insert(db.getSession(), dto);
     db.commit();
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     String json = ws.newRequest()
       .setParam("componentKey", project.getKey())
@@ -135,7 +135,7 @@ public class WebhookDeliveriesActionTest {
     dbClient.webhookDeliveryDao().insert(db.getSession(), dto2);
     dbClient.webhookDeliveryDao().insert(db.getSession(), dto3);
     db.commit();
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     Webhooks.DeliveriesWsResponse response = ws.newRequest()
       .setParam("ceTaskId", "t1")
@@ -150,7 +150,7 @@ public class WebhookDeliveriesActionTest {
       .setComponentUuid(project.uuid());
     dbClient.webhookDeliveryDao().insert(db.getSession(), dto);
     db.commit();
-    userSession.logIn().addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.USER, project);
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
@@ -166,7 +166,7 @@ public class WebhookDeliveriesActionTest {
       .setComponentUuid(project.uuid());
     dbClient.webhookDeliveryDao().insert(db.getSession(), dto);
     db.commit();
-    userSession.logIn().addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.USER, project);
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");
index 353ebe1773cdd3884ebeea35af52c505f4f392b9..0c3bf8881fbcebabebb6b14c16347ec9d8e6a3a7 100644 (file)
@@ -112,7 +112,7 @@ public class WebhookDeliveryActionTest {
       .setPayload("{\"status\"=\"SUCCESS\"}");
     dbClient.webhookDeliveryDao().insert(db.getSession(), dto);
     db.commit();
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     String json = ws.newRequest()
       .setParam("deliveryId", dto.getUuid())
@@ -132,7 +132,7 @@ public class WebhookDeliveryActionTest {
       .setErrorStacktrace("IOException -> can not connect");
     dbClient.webhookDeliveryDao().insert(db.getSession(), dto);
     db.commit();
-    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     Webhooks.DeliveryWsResponse response = ws.newRequest()
       .setParam("deliveryId", dto.getUuid())
@@ -150,7 +150,7 @@ public class WebhookDeliveryActionTest {
       .setComponentUuid(project.uuid());
     dbClient.webhookDeliveryDao().insert(db.getSession(), dto);
     db.commit();
-    userSession.logIn().addProjectUuidPermissions(UserRole.USER, project.uuid());
+    userSession.logIn().addProjectPermission(UserRole.USER, project);
 
     expectedException.expect(ForbiddenException.class);
     expectedException.expectMessage("Insufficient privileges");