]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8134 rename PermissionService
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 20 Oct 2016 17:19:58 +0000 (19:19 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 21 Oct 2016 13:58:39 +0000 (15:58 +0200)
It's only about templates, so class is renamed
PermissionTemplateService.

12 files changed:
server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
server/sonar-server/src/main/java/org/sonar/server/component/DefaultRubyComponentService.java
server/sonar-server/src/main/java/org/sonar/server/computation/queue/ReportSubmitter.java
server/sonar-server/src/main/java/org/sonar/server/permission/PermissionService.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateService.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/ApplyTemplateAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/BulkApplyTemplateAction.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
server/sonar-server/src/test/java/org/sonar/server/component/DefaultRubyComponentServiceTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/queue/ReportSubmitterTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/ApplyTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/BulkApplyTemplateActionTest.java

index 547008af67625a34f138cbc61bb9c0d9677be45f..b4a72714b08831ddf01fcc19cbd783e34158556a 100644 (file)
@@ -97,7 +97,7 @@ import org.sonar.server.notification.email.AlertsEmailTemplate;
 import org.sonar.server.notification.email.EmailNotificationChannel;
 import org.sonar.server.organization.DefaultOrganizationProviderImpl;
 import org.sonar.server.permission.GroupPermissionChanger;
-import org.sonar.server.permission.PermissionService;
+import org.sonar.server.permission.PermissionTemplateService;
 import org.sonar.server.permission.PermissionUpdater;
 import org.sonar.server.permission.UserPermissionChanger;
 import org.sonar.server.permission.index.PermissionIndexer;
@@ -320,7 +320,7 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer {
 
       // permissions
       PermissionRepository.class,
-      PermissionService.class,
+      PermissionTemplateService.class,
       PermissionUpdater.class,
       UserPermissionChanger.class,
       GroupPermissionChanger.class,
index 26aceab58c664950c99c7f6bfcaa29cfd866e5e0..9c4343aff3dd9f3b1bc5eb9718e6ee3d489bbac2 100644 (file)
@@ -31,7 +31,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ResourceDao;
 import org.sonar.db.component.ResourceDto;
-import org.sonar.server.permission.PermissionService;
+import org.sonar.server.permission.PermissionTemplateService;
 import org.sonar.server.util.RubyUtils;
 
 public class DefaultRubyComponentService implements RubyComponentService {
@@ -39,13 +39,13 @@ public class DefaultRubyComponentService implements RubyComponentService {
   private final DbClient dbClient;
   private final ResourceDao resourceDao;
   private final ComponentService componentService;
-  private final PermissionService permissionService;
+  private final PermissionTemplateService permissionTemplateService;
 
-  public DefaultRubyComponentService(DbClient dbClient, ResourceDao resourceDao, ComponentService componentService, PermissionService permissionService) {
+  public DefaultRubyComponentService(DbClient dbClient, ResourceDao resourceDao, ComponentService componentService, PermissionTemplateService permissionTemplateService) {
     this.dbClient = dbClient;
     this.resourceDao = resourceDao;
     this.componentService = componentService;
-    this.permissionService = permissionService;
+    this.permissionTemplateService = permissionTemplateService;
   }
 
   @Override
@@ -80,7 +80,7 @@ public class DefaultRubyComponentService implements RubyComponentService {
 
   public long createComponent(DbSession dbSession, String key, @Nullable String branch, String name, @Nullable String qualifier) {
     ComponentDto provisionedComponent = componentService.create(dbSession, NewComponent.create(key, name).setQualifier(qualifier).setBranch(branch));
-    permissionService.applyDefaultPermissionTemplate(dbSession, provisionedComponent.getKey());
+    permissionTemplateService.applyDefaultPermissionTemplate(dbSession, provisionedComponent.getKey());
     return provisionedComponent.getId();
   }
 
index 778913995f42557e885794a4dc57432488c00780..b8f448b3cacbb4443e9c878be9c34f942610160b 100644 (file)
@@ -36,7 +36,7 @@ import org.sonar.db.ce.CeTaskTypes;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.server.component.ComponentService;
 import org.sonar.server.component.NewComponent;
-import org.sonar.server.permission.PermissionService;
+import org.sonar.server.permission.PermissionTemplateService;
 import org.sonar.server.user.UserSession;
 
 import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION;
@@ -48,11 +48,11 @@ public class ReportSubmitter {
   private final CeQueue queue;
   private final UserSession userSession;
   private final ComponentService componentService;
-  private final PermissionService permissionTemplateService;
+  private final PermissionTemplateService permissionTemplateService;
   private final DbClient dbClient;
 
   public ReportSubmitter(CeQueue queue, UserSession userSession,
-                         ComponentService componentService, PermissionService permissionTemplateService, DbClient dbClient) {
+    ComponentService componentService, PermissionTemplateService permissionTemplateService, DbClient dbClient) {
     this.queue = queue;
     this.userSession = userSession;
     this.componentService = componentService;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionService.java b/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionService.java
deleted file mode 100644 (file)
index 7778a8a..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.permission;
-
-import java.util.Collection;
-import java.util.List;
-import javax.annotation.Nullable;
-import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.server.ServerSide;
-import org.sonar.core.component.ComponentKeys;
-import org.sonar.core.permission.GlobalPermissions;
-import org.sonar.core.util.stream.Collectors;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.ResourceDto;
-import org.sonar.db.permission.PermissionRepository;
-import org.sonar.db.permission.template.PermissionTemplateDto;
-import org.sonar.server.permission.index.PermissionIndexer;
-import org.sonar.server.user.UserSession;
-
-import static java.util.Arrays.asList;
-import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdminUserByComponentKey;
-import static org.sonar.server.ws.WsUtils.checkFoundWithOptional;
-
-@ServerSide
-public class PermissionService {
-
-  private final DbClient dbClient;
-  private final PermissionRepository permissionRepository;
-  private final PermissionIndexer permissionIndexer;
-  private final UserSession userSession;
-
-  public PermissionService(DbClient dbClient, PermissionRepository permissionRepository, PermissionIndexer permissionIndexer, UserSession userSession) {
-    this.dbClient = dbClient;
-    this.permissionRepository = permissionRepository;
-    this.permissionIndexer = permissionIndexer;
-    this.userSession = userSession;
-  }
-
-  public void applyDefaultPermissionTemplate(String componentKey) {
-    DbSession session = dbClient.openSession(false);
-    try {
-      applyDefaultPermissionTemplate(session, componentKey);
-    } finally {
-      session.close();
-    }
-  }
-
-  /**
-   * @deprecated replaced by {@link #applyDefault(DbSession, ComponentDto, Long)}, which <b>does not
-   * verify that user is authorized to administrate the component</b>.
-   */
-  @Deprecated
-  public void applyDefaultPermissionTemplate(DbSession session, String componentKey) {
-    ComponentDto component = checkFoundWithOptional(dbClient.componentDao().selectByKey(session, componentKey), "Component key '%s' not found", componentKey);
-    ResourceDto provisioned = dbClient.resourceDao().selectProvisionedProject(session, componentKey);
-    if (provisioned == null) {
-      checkProjectAdminUserByComponentKey(userSession, componentKey);
-    } else {
-      userSession.checkPermission(GlobalPermissions.PROVISIONING);
-    }
-
-    Integer currentUserId = userSession.getUserId();
-    Long userId = Qualifiers.PROJECT.equals(component.qualifier()) && currentUserId != null ? currentUserId.longValue() : null;
-    permissionRepository.applyDefaultPermissionTemplate(session, component, userId);
-    session.commit();
-    indexProjectPermissions(session, asList(component.uuid()));
-  }
-
-  public boolean wouldCurrentUserHavePermissionWithDefaultTemplate(DbSession dbSession, String permission, @Nullable String branch, String projectKey, String qualifier) {
-    if (userSession.hasPermission(permission)) {
-      return true;
-    }
-
-    String effectiveKey = ComponentKeys.createKey(projectKey, branch);
-
-    Long userId = userSession.getUserId() == null ? null : userSession.getUserId().longValue();
-    return permissionRepository.wouldUserHavePermissionWithDefaultTemplate(dbSession, userId, permission, effectiveKey, qualifier);
-  }
-
-  public void apply(DbSession dbSession, PermissionTemplateDto template, Collection<ComponentDto> projects) {
-    if (projects.isEmpty()) {
-      return;
-    }
-
-    for (ComponentDto project : projects) {
-      permissionRepository.apply(dbSession, template, project, null);
-    }
-    dbSession.commit();
-    indexProjectPermissions(dbSession, projects.stream().map(ComponentDto::uuid).collect(Collectors.toList()));
-  }
-
-  /**
-   * Apply the default permission template to component, whatever it already exists (and has permissions) or if it's
-   * provisioned (and has no permissions yet).
-   *
-   * @param dbSession
-   * @param component
-   * @param projectCreatorUserId id of the user who creates the project, only if project is provisioned. He will
-   *                             benefit from the permissions defined in the template for "project creator".
-   */
-  public void applyDefault(DbSession dbSession, ComponentDto component, @Nullable Long projectCreatorUserId) {
-    permissionRepository.applyDefaultPermissionTemplate(dbSession, component, projectCreatorUserId);
-    dbSession.commit();
-    indexProjectPermissions(dbSession, asList(component.uuid()));
-  }
-
-  private void indexProjectPermissions(DbSession dbSession, List<String> projectUuids) {
-    permissionIndexer.index(dbSession, projectUuids);
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateService.java b/server/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateService.java
new file mode 100644 (file)
index 0000000..bcfbeea
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.permission;
+
+import java.util.Collection;
+import java.util.List;
+import javax.annotation.Nullable;
+import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.server.ServerSide;
+import org.sonar.core.component.ComponentKeys;
+import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.core.util.stream.Collectors;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ResourceDto;
+import org.sonar.db.permission.PermissionRepository;
+import org.sonar.db.permission.template.PermissionTemplateDto;
+import org.sonar.server.permission.index.PermissionIndexer;
+import org.sonar.server.user.UserSession;
+
+import static java.util.Arrays.asList;
+import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdminUserByComponentKey;
+import static org.sonar.server.ws.WsUtils.checkFoundWithOptional;
+
+@ServerSide
+public class PermissionTemplateService {
+
+  private final DbClient dbClient;
+  private final PermissionRepository permissionRepository;
+  private final PermissionIndexer permissionIndexer;
+  private final UserSession userSession;
+
+  public PermissionTemplateService(DbClient dbClient, PermissionRepository permissionRepository, PermissionIndexer permissionIndexer, UserSession userSession) {
+    this.dbClient = dbClient;
+    this.permissionRepository = permissionRepository;
+    this.permissionIndexer = permissionIndexer;
+    this.userSession = userSession;
+  }
+
+  /**
+   * @deprecated replaced by {@link #applyDefault(DbSession, ComponentDto, Long)}, which <b>does not
+   * verify that user is authorized to administrate the component</b>.
+   */
+  @Deprecated
+  public void applyDefaultPermissionTemplate(String componentKey) {
+    DbSession session = dbClient.openSession(false);
+    try {
+      applyDefaultPermissionTemplate(session, componentKey);
+    } finally {
+      session.close();
+    }
+  }
+
+  /**
+   * @deprecated replaced by {@link #applyDefault(DbSession, ComponentDto, Long)}, which <b>does not
+   * verify that user is authorized to administrate the component</b>.
+   */
+  @Deprecated
+  public void applyDefaultPermissionTemplate(DbSession session, String componentKey) {
+    ComponentDto component = checkFoundWithOptional(dbClient.componentDao().selectByKey(session, componentKey), "Component key '%s' not found", componentKey);
+    ResourceDto provisioned = dbClient.resourceDao().selectProvisionedProject(session, componentKey);
+    if (provisioned == null) {
+      checkProjectAdminUserByComponentKey(userSession, componentKey);
+    } else {
+      userSession.checkPermission(GlobalPermissions.PROVISIONING);
+    }
+
+    Integer currentUserId = userSession.getUserId();
+    Long userId = Qualifiers.PROJECT.equals(component.qualifier()) && currentUserId != null ? currentUserId.longValue() : null;
+    permissionRepository.applyDefaultPermissionTemplate(session, component, userId);
+    session.commit();
+    indexProjectPermissions(session, asList(component.uuid()));
+  }
+
+  public boolean wouldCurrentUserHavePermissionWithDefaultTemplate(DbSession dbSession, String permission, @Nullable String branch, String projectKey, String qualifier) {
+    if (userSession.hasPermission(permission)) {
+      return true;
+    }
+
+    String effectiveKey = ComponentKeys.createKey(projectKey, branch);
+
+    Long userId = userSession.getUserId() == null ? null : userSession.getUserId().longValue();
+    return permissionRepository.wouldUserHavePermissionWithDefaultTemplate(dbSession, userId, permission, effectiveKey, qualifier);
+  }
+
+  /**
+   * Apply a permission template to a set of projects. Authorization to administrate these projects
+   * is not verified. The projects must exist, so the "project creator" permissions defined in the
+   * template are ignored.
+   */
+  public void apply(DbSession dbSession, PermissionTemplateDto template, Collection<ComponentDto> projects) {
+    if (projects.isEmpty()) {
+      return;
+    }
+
+    for (ComponentDto project : projects) {
+      permissionRepository.apply(dbSession, template, project, null);
+    }
+    dbSession.commit();
+    indexProjectPermissions(dbSession, projects.stream().map(ComponentDto::uuid).collect(Collectors.toList()));
+  }
+
+  /**
+   * Apply the default permission template to project. The project can already exist (so it has permissions) or
+   * can be provisioned (so has no permissions yet).
+   *
+   * @param dbSession
+   * @param component
+   * @param projectCreatorUserId id of the user who creates the project, only if project is provisioned. He will
+   *                             benefit from the permissions defined in the template for "project creator".
+   */
+  public void applyDefault(DbSession dbSession, ComponentDto component, @Nullable Long projectCreatorUserId) {
+    permissionRepository.applyDefaultPermissionTemplate(dbSession, component, projectCreatorUserId);
+    dbSession.commit();
+    indexProjectPermissions(dbSession, asList(component.uuid()));
+  }
+
+  private void indexProjectPermissions(DbSession dbSession, List<String> projectUuids) {
+    permissionIndexer.index(dbSession, projectUuids);
+  }
+}
index ac2215fe45b4f91cbc0e36bbc63c79cf65ec55d0..9018b0f6f692492cb080fedd08d268d4dc0fda19 100644 (file)
@@ -28,7 +28,7 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.permission.template.PermissionTemplateDto;
-import org.sonar.server.permission.PermissionService;
+import org.sonar.server.permission.PermissionTemplateService;
 import org.sonar.server.permission.ProjectId;
 import org.sonar.server.permission.ws.PermissionWsSupport;
 import org.sonar.server.permission.ws.PermissionsWsAction;
@@ -48,14 +48,14 @@ import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_T
 public class ApplyTemplateAction implements PermissionsWsAction {
   private final DbClient dbClient;
   private final UserSession userSession;
-  private final PermissionService permissionService;
+  private final PermissionTemplateService permissionTemplateService;
   private final PermissionWsSupport wsSupport;
 
-  public ApplyTemplateAction(DbClient dbClient, UserSession userSession, PermissionService permissionService,
+  public ApplyTemplateAction(DbClient dbClient, UserSession userSession, PermissionTemplateService permissionTemplateService,
     PermissionWsSupport wsSupport) {
     this.dbClient = dbClient;
     this.userSession = userSession;
-    this.permissionService = permissionService;
+    this.permissionTemplateService = permissionTemplateService;
     this.wsSupport = wsSupport;
   }
 
@@ -89,7 +89,7 @@ public class ApplyTemplateAction implements PermissionsWsAction {
       ProjectId projectId = new ProjectId(project);
       checkProjectAdmin(userSession, template.getOrganizationUuid(), Optional.of(projectId));
 
-      permissionService.apply(dbSession, template, Collections.singletonList(project));
+      permissionTemplateService.apply(dbSession, template, Collections.singletonList(project));
     }
   }
 
index ac1777a8a9b62365afe91e49ef82ae3e7ac24bd2..8d3845775353daf69af9aaeb700462f36fb5301a 100644 (file)
@@ -35,7 +35,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentQuery;
 import org.sonar.db.permission.template.PermissionTemplateDto;
-import org.sonar.server.permission.PermissionService;
+import org.sonar.server.permission.PermissionTemplateService;
 import org.sonar.server.permission.ProjectId;
 import org.sonar.server.permission.ws.PermissionWsSupport;
 import org.sonar.server.permission.ws.PermissionsWsAction;
@@ -57,16 +57,16 @@ public class BulkApplyTemplateAction implements PermissionsWsAction {
 
   private final DbClient dbClient;
   private final UserSession userSession;
-  private final PermissionService permissionService;
+  private final PermissionTemplateService permissionTemplateService;
   private final PermissionWsSupport wsSupport;
   private final I18n i18n;
   private final ResourceTypes resourceTypes;
 
-  public BulkApplyTemplateAction(DbClient dbClient, UserSession userSession, PermissionService permissionService, PermissionWsSupport wsSupport, I18n i18n,
+  public BulkApplyTemplateAction(DbClient dbClient, UserSession userSession, PermissionTemplateService permissionTemplateService, PermissionWsSupport wsSupport, I18n i18n,
     ResourceTypes resourceTypes) {
     this.dbClient = dbClient;
     this.userSession = userSession;
-    this.permissionService = permissionService;
+    this.permissionTemplateService = permissionTemplateService;
     this.wsSupport = wsSupport;
     this.i18n = i18n;
     this.resourceTypes = resourceTypes;
@@ -112,7 +112,7 @@ public class BulkApplyTemplateAction implements PermissionsWsAction {
         ProjectId projectId = new ProjectId(project);
         checkProjectAdmin(userSession, template.getOrganizationUuid(), Optional.of(projectId));
       }
-      permissionService.apply(dbSession, template, projects);
+      permissionTemplateService.apply(dbSession, template, projects);
     }
   }
 
index 7ce7034056ef8fa05c6ec11ed933e4a3f94cf9d7..0de4247ce5f08c14d57c84765f42498e42da64dc 100644 (file)
@@ -137,7 +137,7 @@ import org.sonar.server.notification.email.AlertsEmailTemplate;
 import org.sonar.server.notification.email.EmailNotificationChannel;
 import org.sonar.server.organization.ws.OrganizationsWsModule;
 import org.sonar.server.permission.GroupPermissionChanger;
-import org.sonar.server.permission.PermissionService;
+import org.sonar.server.permission.PermissionTemplateService;
 import org.sonar.server.permission.PermissionUpdater;
 import org.sonar.server.permission.UserPermissionChanger;
 import org.sonar.server.permission.index.PermissionIndexer;
@@ -432,7 +432,7 @@ public class PlatformLevel4 extends PlatformLevel {
       // permissions
       PermissionsWsModule.class,
       PermissionRepository.class,
-      PermissionService.class,
+      PermissionTemplateService.class,
       PermissionUpdater.class,
       UserPermissionChanger.class,
       GroupPermissionChanger.class,
index edfd797db251ec93eed8e240a381efec3e93a475..f75f6814fa08dfcf3f27577a6d3136cf7cf3d12a 100644 (file)
@@ -38,7 +38,7 @@ import org.sonar.server.component.es.ProjectMeasuresIndexer;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.i18n.I18nRule;
-import org.sonar.server.permission.PermissionService;
+import org.sonar.server.permission.PermissionTemplateService;
 import org.sonar.server.tester.UserSessionRule;
 
 import static com.google.common.collect.Lists.newArrayList;
@@ -69,11 +69,11 @@ public class DefaultRubyComponentServiceTest {
   ResourceDao resourceDao = dbClient.resourceDao();
   ComponentService componentService = new ComponentService(dbClient, i18n, userSession, System2.INSTANCE, new ComponentFinder(dbClient),
     new ProjectMeasuresIndexer(dbClient, es.client()));
-  PermissionService permissionService = mock(PermissionService.class);
+  PermissionTemplateService permissionTemplateService = mock(PermissionTemplateService.class);
 
   ComponentDbTester componentDb = new ComponentDbTester(db);
 
-  DefaultRubyComponentService service = new DefaultRubyComponentService(dbClient, resourceDao, componentService, permissionService);
+  DefaultRubyComponentService service = new DefaultRubyComponentService(dbClient, resourceDao, componentService, permissionTemplateService);
 
   @Test
   public void find_by_key() {
@@ -110,7 +110,7 @@ public class DefaultRubyComponentServiceTest {
     assertThat(project.name()).isEqualTo(componentName);
     assertThat(project.qualifier()).isEqualTo(qualifier);
     assertThat(project.getId()).isEqualTo(result);
-    verify(permissionService).applyDefaultPermissionTemplate(any(DbSession.class), eq(componentKey));
+    verify(permissionTemplateService).applyDefaultPermissionTemplate(any(DbSession.class), eq(componentKey));
   }
 
   @Test(expected = BadRequestException.class)
index 5544076684e006ddd264b19407577421b1621c58..645e8928c50d55131ac10ce1d8d081017fd8ae01 100644 (file)
@@ -38,7 +38,7 @@ import org.sonar.db.component.ComponentDto;
 import org.sonar.server.component.ComponentService;
 import org.sonar.server.component.NewComponent;
 import org.sonar.server.exceptions.ForbiddenException;
-import org.sonar.server.permission.PermissionService;
+import org.sonar.server.permission.PermissionTemplateService;
 import org.sonar.server.tester.UserSessionRule;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -72,8 +72,8 @@ public class ReportSubmitterTest {
 
   private CeQueue queue = mock(CeQueueImpl.class);
   private ComponentService componentService = mock(ComponentService.class);
-  private PermissionService permissionService = mock(PermissionService.class);
-  private ReportSubmitter underTest = new ReportSubmitter(queue, userSession, componentService, permissionService, db.getDbClient());
+  private PermissionTemplateService permissionTemplateService = mock(PermissionTemplateService.class);
+  private ReportSubmitter underTest = new ReportSubmitter(queue, userSession, componentService, permissionTemplateService, db.getDbClient());
 
   @Test
   public void submit_a_report_on_existing_project() {
@@ -85,7 +85,7 @@ public class ReportSubmitterTest {
     underTest.submit(project.getKey(), null, project.name(), IOUtils.toInputStream("{binary}"));
 
     verifyReportIsPersisted(TASK_UUID);
-    verifyZeroInteractions(permissionService);
+    verifyZeroInteractions(permissionTemplateService);
     verify(queue).submit(argThat(new TypeSafeMatcher<CeTaskSubmit>() {
       @Override
       protected boolean matchesSafely(CeTaskSubmit submit) {
@@ -107,13 +107,13 @@ public class ReportSubmitterTest {
     when(queue.prepareSubmit()).thenReturn(new CeTaskSubmit.Builder(TASK_UUID));
     ComponentDto createdProject = new ComponentDto().setUuid(PROJECT_UUID).setKey(PROJECT_KEY);
     when(componentService.create(any(DbSession.class), any(NewComponent.class))).thenReturn(createdProject);
-    when(permissionService.wouldCurrentUserHavePermissionWithDefaultTemplate(any(DbSession.class), eq(SCAN_EXECUTION), anyString(), eq(PROJECT_KEY), eq(Qualifiers.PROJECT)))
+    when(permissionTemplateService.wouldCurrentUserHavePermissionWithDefaultTemplate(any(DbSession.class), eq(SCAN_EXECUTION), anyString(), eq(PROJECT_KEY), eq(Qualifiers.PROJECT)))
       .thenReturn(true);
 
     underTest.submit(PROJECT_KEY, null, PROJECT_NAME, IOUtils.toInputStream("{binary}"));
 
     verifyReportIsPersisted(TASK_UUID);
-    verify(permissionService).applyDefault(any(DbSession.class), eq(createdProject), anyLong());
+    verify(permissionTemplateService).applyDefault(any(DbSession.class), eq(createdProject), anyLong());
     verify(queue).submit(argThat(new TypeSafeMatcher<CeTaskSubmit>() {
       @Override
       protected boolean matchesSafely(CeTaskSubmit submit) {
@@ -134,7 +134,7 @@ public class ReportSubmitterTest {
 
     when(queue.prepareSubmit()).thenReturn(new CeTaskSubmit.Builder(TASK_UUID));
     when(componentService.create(any(DbSession.class), any(NewComponent.class))).thenReturn(new ComponentDto().setUuid(PROJECT_UUID).setKey(PROJECT_KEY));
-    when(permissionService.wouldCurrentUserHavePermissionWithDefaultTemplate(any(DbSession.class), eq(SCAN_EXECUTION), anyString(), eq(PROJECT_KEY), eq(Qualifiers.PROJECT)))
+    when(permissionTemplateService.wouldCurrentUserHavePermissionWithDefaultTemplate(any(DbSession.class), eq(SCAN_EXECUTION), anyString(), eq(PROJECT_KEY), eq(Qualifiers.PROJECT)))
       .thenReturn(true);
 
     underTest.submit(PROJECT_KEY, null, PROJECT_NAME, IOUtils.toInputStream("{binary}"));
index 20cb9cf0cd225a7f2aff3fdeb411a25ab13cf9cf..8a7fff304a3124140b7fcb0ba05fbfb00c4e2a2f 100644 (file)
@@ -35,14 +35,13 @@ import org.sonar.db.permission.PermissionRepository;
 import org.sonar.db.permission.template.PermissionTemplateDto;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserDto;
-import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.component.es.ProjectMeasuresIndexDefinition;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.issue.index.IssueIndexDefinition;
-import org.sonar.server.permission.PermissionService;
+import org.sonar.server.permission.PermissionTemplateService;
 import org.sonar.server.permission.index.PermissionIndexer;
 import org.sonar.server.permission.index.PermissionIndexerTester;
 import org.sonar.server.permission.ws.BasePermissionWsTest;
@@ -78,8 +77,8 @@ public class ApplyTemplateActionTest extends BasePermissionWsTest<ApplyTemplateA
   @Override
   protected ApplyTemplateAction buildWsAction() {
     PermissionRepository repository = new PermissionRepository(db.getDbClient(), new MapSettings());
-    PermissionService permissionService = new PermissionService(db.getDbClient(), repository, permissionIndexer, userSession);
-    return new ApplyTemplateAction(db.getDbClient(), userSession, permissionService, newPermissionWsSupport());
+    PermissionTemplateService permissionTemplateService = new PermissionTemplateService(db.getDbClient(), repository, permissionIndexer, userSession);
+    return new ApplyTemplateAction(db.getDbClient(), userSession, permissionTemplateService, newPermissionWsSupport());
   }
 
   @Before
index 5d201f5e1339e1d15a81d2fed904f62c1312c9d8..f6acc7fb450518ec51458eacbc5539b8a249fc41 100644 (file)
@@ -35,7 +35,7 @@ import org.sonar.db.user.UserDto;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.i18n.I18nRule;
-import org.sonar.server.permission.PermissionService;
+import org.sonar.server.permission.PermissionTemplateService;
 import org.sonar.server.permission.index.PermissionIndexer;
 import org.sonar.server.permission.ws.BasePermissionWsTest;
 
@@ -61,8 +61,8 @@ public class BulkApplyTemplateActionTest extends BasePermissionWsTest<BulkApplyT
   @Override
   protected BulkApplyTemplateAction buildWsAction() {
     PermissionRepository repository = new PermissionRepository(db.getDbClient(), new MapSettings());
-    PermissionService permissionService = new PermissionService(db.getDbClient(), repository, issuePermissionIndexer, userSession);
-    return new BulkApplyTemplateAction(db.getDbClient(), userSession, permissionService, newPermissionWsSupport(), new I18nRule(), newRootResourceTypes());
+    PermissionTemplateService permissionTemplateService = new PermissionTemplateService(db.getDbClient(), repository, issuePermissionIndexer, userSession);
+    return new BulkApplyTemplateAction(db.getDbClient(), userSession, permissionTemplateService, newPermissionWsSupport(), new I18nRule(), newRootResourceTypes());
   }
 
   @Before