]> source.dussan.org Git - sonarqube.git/commitdiff
Rename WsGroup and WsProject to WsGroupRef and WsProjectRef
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 1 Sep 2015 06:07:49 +0000 (08:07 +0200)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Wed, 2 Sep 2015 14:36:19 +0000 (16:36 +0200)
35 files changed:
server/sonar-server/src/main/java/org/sonar/server/permission/ApplyPermissionTemplateQuery.java
server/sonar-server/src/main/java/org/sonar/server/permission/PermissionService.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/AddGroupToTemplateAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/AddUserAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/AddUserToTemplateAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/GroupsAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/Parameters.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/PermissionDependenciesFinder.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/PermissionRequest.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/PermissionRequestValidator.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/RemoveGroupAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/RemoveGroupFromTemplateAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/RemoveUserAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/RemoveUserFromTemplateAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsDataLoader.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/UsersAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/WsProjectRef.java
server/sonar-server/src/test/java/org/sonar/server/permission/ApplyPermissionTemplateQueryTest.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/AddGroupToTemplateActionTest.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/AddUserToTemplateActionTest.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/PermissionRequestValidatorTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/RemoveGroupFromTemplateActionTest.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/RemoveUserFromTemplateActionTest.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/UpdateTemplateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/UsersActionTest.java
sonar-db/src/main/java/org/sonar/db/permission/PermissionRepository.java
sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDto.java

index 21bec0156542507c17d323e468ecc9582175bfdd..2ff9b702368181ddeeb2df9ef84c08f8cbc8318e 100644 (file)
 
 package org.sonar.server.permission;
 
-import org.apache.commons.lang.StringUtils;
-import org.picocontainer.annotations.Nullable;
+import java.util.List;
+import java.util.Map;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.util.RubyUtils;
 
-import java.util.List;
-import java.util.Map;
+import static com.google.common.base.CharMatcher.WHITESPACE;
 
 public class ApplyPermissionTemplateQuery {
 
   private static final String TEMPLATE_KEY = "template_key";
   private static final String COMPONENTS_KEY = "components";
 
-  private final String templateKey;
-  private List<String> selectedComponents;
+  private final String templateUuid;
+  private List<String> componentKeys;
 
-  private ApplyPermissionTemplateQuery(@Nullable String templateKey) {
-    this.templateKey = templateKey;
+  private ApplyPermissionTemplateQuery(String templateUuid, List<String> componentKeys) {
+    this.templateUuid = templateUuid;
+    this.componentKeys = componentKeys;
+    validate();
   }
 
-  public static ApplyPermissionTemplateQuery buildFromParams(Map<String, Object> params) {
-    ApplyPermissionTemplateQuery query = new ApplyPermissionTemplateQuery((String)params.get(TEMPLATE_KEY));
-    query.setSelectedComponents(RubyUtils.toStrings(params.get(COMPONENTS_KEY)));
-    return query;
+  public static ApplyPermissionTemplateQuery createFromMap(Map<String, Object> params) {
+    String templateUuid = (String) params.get(TEMPLATE_KEY);
+    List<String> componentKeys = RubyUtils.toStrings(params.get(COMPONENTS_KEY));
+    return new ApplyPermissionTemplateQuery(templateUuid, componentKeys);
   }
 
-  public String getTemplateKey() {
-    return templateKey;
+  public static ApplyPermissionTemplateQuery create(String templateUuid, List<String> componentKeys) {
+    return new ApplyPermissionTemplateQuery(templateUuid, componentKeys);
   }
 
-  public List<String> getSelectedComponents() {
-    return selectedComponents;
+  public String getTemplateUuid() {
+    return templateUuid;
   }
 
-  public void validate() {
-    if(StringUtils.isBlank(templateKey)) {
+  public List<String> getComponentKeys() {
+    return componentKeys;
+  }
+
+  private void validate() {
+    if (templateUuid == null || WHITESPACE.trimFrom(templateUuid).isEmpty()) {
       throw new BadRequestException("Permission template is mandatory");
     }
-    if(selectedComponents == null || selectedComponents.isEmpty()) {
-      throw new BadRequestException("Please provide at least one entry to which the permission template should be applied");
+    if (componentKeys == null || componentKeys.isEmpty()) {
+      throw new BadRequestException("No project provided. Please provide at least one project.");
     }
   }
-
-  private void setSelectedComponents(List<String> selectedComponents) {
-    this.selectedComponents = selectedComponents;
-  }
 }
index 3777076e03bcf67ef6cd75d668b3ca78e893f155..4849b402f0190a62e6d5ca77af807f7b32f2c99f 100644 (file)
@@ -41,6 +41,9 @@ import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.issue.index.IssueAuthorizationIndexer;
 import org.sonar.server.user.UserSession;
 
+import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdminUser;
+import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdminUserByComponentKey;
+
 /**
  * Used by ruby code <pre>Internal.permissions</pre>
  */
@@ -160,40 +163,34 @@ public class PermissionService {
     indexProjectPermissions();
   }
 
+  /**
+   * @deprecated since 5.2 – to be deleted once Permission Template page does not rely on Ruby
+   */
+  @Deprecated
   public void applyPermissionTemplate(Map<String, Object> params) {
-    userSession.checkLoggedIn();
-    ApplyPermissionTemplateQuery query = ApplyPermissionTemplateQuery.buildFromParams(params);
+    ApplyPermissionTemplateQuery query = ApplyPermissionTemplateQuery.createFromMap(params);
     applyPermissionTemplate(query);
   }
 
-  void applyPermissionTemplate(ApplyPermissionTemplateQuery query) {
-    query.validate();
-
-    boolean projectsChanged = false;
-    DbSession session = dbClient.openSession(false);
+  public void applyPermissionTemplate(ApplyPermissionTemplateQuery query) {
+    DbSession dbSession = dbClient.openSession(false);
     try {
-      // If only one project is selected, check user has admin permission on it, otherwise we are in the case of a bulk change and only
-      // system
-      // admin has permission to do it
-      if (query.getSelectedComponents().size() == 1) {
-        checkProjectAdminPermission(query.getSelectedComponents().get(0));
+      if (query.getComponentKeys().size() == 1) {
+        checkProjectAdminUserByComponentKey(userSession, query.getComponentKeys().get(0));
       } else {
-        checkProjectAdminPermission(null);
-        userSession.checkGlobalPermission(GlobalPermissions.SYSTEM_ADMIN);
+        checkGlobalAdminUser(userSession);
       }
 
-      for (String componentKey : query.getSelectedComponents()) {
-        ComponentDto component = componentFinder.getByKey(session, componentKey);
-        permissionRepository.applyPermissionTemplate(session, query.getTemplateKey(), component.getId());
-        projectsChanged = true;
+      for (String componentKey : query.getComponentKeys()) {
+        ComponentDto component = componentFinder.getByKey(dbSession, componentKey);
+        permissionRepository.applyPermissionTemplate(dbSession, query.getTemplateUuid(), component.getId());
       }
-      session.commit();
+      dbSession.commit();
     } finally {
-      session.close();
-    }
-    if (projectsChanged) {
-      indexProjectPermissions();
+      dbClient.closeSession(dbSession);
     }
+
+    indexProjectPermissions();
   }
 
   private void applyChange(Operation operation, PermissionChange change, DbSession session) {
index cec958a2ebd2d1b943c40efca968778eef8c20d0..8d6e381d631e17487cf51541b4fc34f2537b0a4a 100644 (file)
@@ -32,8 +32,7 @@ import org.sonar.server.permission.ws.PermissionRequest.Builder;
 import static org.sonar.server.permission.ws.Parameters.createGroupIdParameter;
 import static org.sonar.server.permission.ws.Parameters.createGroupNameParameter;
 import static org.sonar.server.permission.ws.Parameters.createPermissionParameter;
-import static org.sonar.server.permission.ws.Parameters.createProjectKeyParameter;
-import static org.sonar.server.permission.ws.Parameters.createProjectUuidParameter;
+import static org.sonar.server.permission.ws.Parameters.createProjectParameter;
 
 public class AddGroupAction implements PermissionsWsAction {
 
@@ -63,8 +62,7 @@ public class AddGroupAction implements PermissionsWsAction {
     createPermissionParameter(action);
     createGroupNameParameter(action);
     createGroupIdParameter(action);
-    createProjectUuidParameter(action);
-    createProjectKeyParameter(action);
+    createProjectParameter(action);
   }
 
   @Override
index 658f9fb555b143928f538db2b1cb83646d686dfc..e48bb2232d4816a8a64d2a35b5a91e09a01444a8 100644 (file)
@@ -37,11 +37,11 @@ import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobal
 import static org.sonar.server.permission.ws.PermissionRequestValidator.validateNotAnyoneAndAdminPermission;
 import static org.sonar.server.permission.ws.PermissionRequestValidator.validateProjectPermission;
 import static org.sonar.server.permission.ws.Parameters.PARAM_PERMISSION;
-import static org.sonar.server.permission.ws.Parameters.PARAM_LONG_TEMPLATE_ID;
+import static org.sonar.server.permission.ws.Parameters.PARAM_TEMPLATE_ID_EXPLICIT;
 import static org.sonar.server.permission.ws.Parameters.createGroupIdParameter;
 import static org.sonar.server.permission.ws.Parameters.createGroupNameParameter;
 import static org.sonar.server.permission.ws.Parameters.createProjectPermissionParameter;
-import static org.sonar.server.permission.ws.Parameters.createTemplateKeyParameterToAddRemoveUserOrGroup;
+import static org.sonar.server.permission.ws.Parameters.createExplicitTemplateId;
 
 public class AddGroupToTemplateAction implements PermissionsWsAction {
   private final DbClient dbClient;
@@ -65,7 +65,7 @@ public class AddGroupToTemplateAction implements PermissionsWsAction {
         "It requires administration permissions to access.")
       .setHandler(this);
 
-    createTemplateKeyParameterToAddRemoveUserOrGroup(action);
+    createExplicitTemplateId(action);
     createProjectPermissionParameter(action);
     createGroupIdParameter(action);
     createGroupNameParameter(action);
@@ -75,7 +75,7 @@ public class AddGroupToTemplateAction implements PermissionsWsAction {
   public void handle(Request wsRequest, Response wsResponse) throws Exception {
     checkGlobalAdminUser(userSession);
 
-    String templateKey = wsRequest.mandatoryParam(PARAM_LONG_TEMPLATE_ID);
+    String templateKey = wsRequest.mandatoryParam(PARAM_TEMPLATE_ID_EXPLICIT);
     String permission = wsRequest.mandatoryParam(PARAM_PERMISSION);
     WsGroupRef group = WsGroupRef.fromRequest(wsRequest);
 
index 7812f82795bb248eb0e5db2d35cfcf767d80ddf5..612789bef85e1365b2bc69942b6a7a8d69d4d114 100644 (file)
@@ -30,8 +30,7 @@ import org.sonar.server.permission.PermissionUpdater;
 import org.sonar.server.permission.ws.PermissionRequest.Builder;
 
 import static org.sonar.server.permission.ws.Parameters.createPermissionParameter;
-import static org.sonar.server.permission.ws.Parameters.createProjectKeyParameter;
-import static org.sonar.server.permission.ws.Parameters.createProjectUuidParameter;
+import static org.sonar.server.permission.ws.Parameters.createProjectParameter;
 import static org.sonar.server.permission.ws.Parameters.createUserLoginParameter;
 
 public class AddUserAction implements PermissionsWsAction {
@@ -60,8 +59,7 @@ public class AddUserAction implements PermissionsWsAction {
 
     createPermissionParameter(action);
     createUserLoginParameter(action);
-    createProjectUuidParameter(action);
-    createProjectKeyParameter(action);
+    createProjectParameter(action);
   }
 
   @Override
index eb1e3197693ba92774e54ffc437fb815ccbf6ee7..7cb65ba0be5ce163114ce01b04089d5958f59ca7 100644 (file)
@@ -38,10 +38,10 @@ import static org.sonar.db.user.GroupMembershipQuery.IN;
 import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdminUser;
 import static org.sonar.server.permission.ws.PermissionRequestValidator.validateProjectPermission;
 import static org.sonar.server.permission.ws.Parameters.PARAM_PERMISSION;
-import static org.sonar.server.permission.ws.Parameters.PARAM_LONG_TEMPLATE_ID;
+import static org.sonar.server.permission.ws.Parameters.PARAM_TEMPLATE_ID_EXPLICIT;
 import static org.sonar.server.permission.ws.Parameters.PARAM_USER_LOGIN;
 import static org.sonar.server.permission.ws.Parameters.createProjectPermissionParameter;
-import static org.sonar.server.permission.ws.Parameters.createTemplateKeyParameterToAddRemoveUserOrGroup;
+import static org.sonar.server.permission.ws.Parameters.createExplicitTemplateId;
 import static org.sonar.server.permission.ws.Parameters.createUserLoginParameter;
 
 public class AddUserToTemplateAction implements PermissionsWsAction {
@@ -65,7 +65,7 @@ public class AddUserToTemplateAction implements PermissionsWsAction {
         "It requires administration permissions to access.")
       .setHandler(this);
 
-    createTemplateKeyParameterToAddRemoveUserOrGroup(action);
+    createExplicitTemplateId(action);
     createProjectPermissionParameter(action);
     createUserLoginParameter(action);
   }
@@ -74,7 +74,7 @@ public class AddUserToTemplateAction implements PermissionsWsAction {
   public void handle(Request wsRequest, Response wsResponse) throws Exception {
     checkGlobalAdminUser(userSession);
 
-    String templateKey = wsRequest.mandatoryParam(PARAM_LONG_TEMPLATE_ID);
+    String templateKey = wsRequest.mandatoryParam(PARAM_TEMPLATE_ID_EXPLICIT);
     String permission = wsRequest.mandatoryParam(PARAM_PERMISSION);
     final String userLogin = wsRequest.mandatoryParam(PARAM_USER_LOGIN);
 
index e41c6dda984d3592f1b988c21befb1e42fb5abf5..7f0b4dc98eeeb339f068e17e8b916719a173b4f9 100644 (file)
@@ -44,8 +44,7 @@ import static com.google.common.base.Objects.firstNonNull;
 import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdminUserByComponentDto;
 import static org.sonar.server.permission.PermissionQueryParser.toMembership;
 import static org.sonar.server.permission.ws.Parameters.createPermissionParameter;
-import static org.sonar.server.permission.ws.Parameters.createProjectKeyParameter;
-import static org.sonar.server.permission.ws.Parameters.createProjectUuidParameter;
+import static org.sonar.server.permission.ws.Parameters.createProjectParameter;
 import static org.sonar.server.ws.WsUtils.writeProtobuf;
 
 public class GroupsAction implements PermissionsWsAction {
@@ -78,8 +77,7 @@ public class GroupsAction implements PermissionsWsAction {
       .setHandler(this);
 
     createPermissionParameter(action);
-    createProjectUuidParameter(action);
-    createProjectKeyParameter(action);
+    createProjectParameter(action);
   }
 
   @Override
index 211b4f61d042c13b7af77375b7ea8784b1ae111b..b008c1577c76aa3ac5690b41c7f7318d6981c292 100644 (file)
@@ -24,29 +24,31 @@ import org.sonar.api.server.ws.WebService.NewAction;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.core.permission.ProjectPermissions;
 
+import static java.lang.String.format;
+
 class Parameters {
 
   static final String PARAM_PERMISSION = "permission";
   static final String PARAM_GROUP_NAME = "groupName";
   static final String PARAM_GROUP_ID = "groupId";
-  static final String PARAM_PROJECT_UUID = "projectId";
+  static final String PARAM_PROJECT_ID = "projectId";
   static final String PARAM_PROJECT_KEY = "projectKey";
   static final String PARAM_USER_LOGIN = "login";
-  static final String PARAM_LONG_TEMPLATE_ID = "templateId";
+  static final String PARAM_TEMPLATE_ID_EXPLICIT = "templateId";
 
   static final String PARAM_TEMPLATE_ID = "id";
   static final String PARAM_TEMPLATE_NAME = "name";
   static final String PARAM_TEMPLATE_DESCRIPTION = "description";
   static final String PARAM_TEMPLATE_PATTERN = "projectKeyPattern";
 
-  private static final String PERMISSION_PARAM_DESCRIPTION = String.format("Permission" +
+  private static final String PERMISSION_PARAM_DESCRIPTION = format("Permission" +
     "<ul>" +
     "<li>Possible values for global permissions: %s</li>" +
     "<li>Possible values for project permissions %s</li>" +
     "</ul>",
     GlobalPermissions.ALL_ON_ONE_LINE,
     ProjectPermissions.ALL_ON_ONE_LINE);
-  private static final String PROJECT_PERMISSION_PARAM_DESCRIPTION = String.format("Permission" +
+  private static final String PROJECT_PERMISSION_PARAM_DESCRIPTION = format("Permission" +
     "<ul>" +
     "<li>Possible values for project permissions %s</li>" +
     "</ul>",
@@ -80,13 +82,18 @@ class Parameters {
       .setExampleValue("42");
   }
 
-  static void createProjectUuidParameter(NewAction action) {
-    action.createParam(PARAM_PROJECT_UUID)
+  static void createProjectParameter(NewAction action) {
+    createProjectIdParameter(action);
+    createProjectKeyParameter(action);
+  }
+
+  private static void createProjectIdParameter(NewAction action) {
+    action.createParam(PARAM_PROJECT_ID)
       .setDescription("Project id")
       .setExampleValue("ce4c03d6-430f-40a9-b777-ad877c00aa4d");
   }
 
-  static void createProjectKeyParameter(NewAction action) {
+  private static void createProjectKeyParameter(NewAction action) {
     action.createParam(PARAM_PROJECT_KEY)
       .setDescription("Project key")
       .setExampleValue("org.apache.hbas:hbase");
@@ -99,11 +106,11 @@ class Parameters {
       .setExampleValue("g.hopper");
   }
 
-  static void createTemplateKeyParameterToAddRemoveUserOrGroup(NewAction action) {
-    action.createParam(PARAM_LONG_TEMPLATE_ID)
+  static void createExplicitTemplateId(NewAction action) {
+    action.createParam(PARAM_TEMPLATE_ID_EXPLICIT)
       .setRequired(true)
-      .setDescription("Template key")
-      .setExampleValue("developer_template_20150820_170218");
+      .setDescription("Template id")
+      .setExampleValue("617f3501-3d32-41bd-a7ac-18315d2e3c7a");
   }
 
   static void createTemplateProjectKeyPatternParameter(NewAction action) {
index 9c78a4e4d091130d1f6e75fe2fa24ba0b563634b..9825d1f34ad0038846b5b91cfdbd0fb89d6ca09a 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.permission.ws;
 
 import com.google.common.base.Optional;
 import javax.annotation.CheckForNull;
+import org.sonar.api.server.ws.Request;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.component.ComponentDto;
@@ -34,6 +35,7 @@ import static java.lang.String.format;
 import static org.sonar.api.security.DefaultGroups.ANYONE;
 import static org.sonar.api.security.DefaultGroups.isAnyone;
 import static org.sonar.server.ws.WsUtils.checkFound;
+import static org.sonar.server.ws.WsUtils.checkRequest;
 
 public class PermissionDependenciesFinder {
   private final DbClient dbClient;
@@ -56,6 +58,13 @@ public class PermissionDependenciesFinder {
     return Optional.of(componentFinder.getProjectByUuidOrKey(dbSession, wsProjectRef.uuid(), wsProjectRef.key()));
   }
 
+  public ComponentDto getProject(DbSession dbSession, Request wsRequest) {
+    Optional<WsProjectRef> projectRef = WsProjectRef.optionalFromRequest(wsRequest);
+    checkRequest(projectRef.isPresent(), "The project id or the project key must be provided.");
+
+    return componentFinder.getProjectByUuidOrKey(dbSession, projectRef.get().uuid(), projectRef.get().key());
+  }
+
   String getGroupName(DbSession dbSession, PermissionRequest request) {
     GroupDto group = getGroup(dbSession, request.group());
 
@@ -63,7 +72,7 @@ public class PermissionDependenciesFinder {
   }
 
   /**
-   * 
+   *
    * @return null if it's the anyone group
    */
   @CheckForNull
index 05336525510c95e4673a5602e156fc964b8a4241..bc42c1d69dff5c97505fd21ec4a469c71d08191e 100644 (file)
@@ -139,7 +139,7 @@ class PermissionRequest {
     }
 
     private void setProject(Request request) {
-      this.project = WsProjectRef.fromRequest(request);
+      this.project = WsProjectRef.optionalFromRequest(request);
     }
 
     private void checkPermissionParameter() {
index 1f7d1b94ee46b018bd7e47a1f372737d28bcf455..287547487884966df5b6332b9579da76466539d4 100644 (file)
@@ -27,9 +27,9 @@ import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.core.permission.ProjectPermissions;
 import org.sonar.server.exceptions.BadRequestException;
 
-import static com.google.common.base.CharMatcher.WHITESPACE;
 import static com.google.common.base.Strings.isNullOrEmpty;
 import static java.lang.String.format;
+import static org.apache.commons.lang.StringUtils.isBlank;
 import static org.sonar.api.security.DefaultGroups.isAnyone;
 import static org.sonar.server.permission.ws.Parameters.PARAM_PERMISSION;
 import static org.sonar.server.permission.ws.Parameters.PARAM_TEMPLATE_PATTERN;
@@ -59,8 +59,7 @@ public class PermissionRequestValidator {
   }
 
   public static void validateTemplateNameFormat(String name) {
-    String nameWithoutWhitespaces = WHITESPACE.trimFrom(name);
-    checkRequest(!nameWithoutWhitespaces.isEmpty(), MSG_TEMPLATE_NAME_NOT_BLANK);
+    checkRequest(!isBlank(name), MSG_TEMPLATE_NAME_NOT_BLANK);
   }
 
   public static void validateProjectPattern(@Nullable String projectPattern) {
index 8f9e9cfe77659cbecc57006d69c70e69b622d785..7c18ae20ede1a7ed1085083574c2788ee61281df 100644 (file)
@@ -32,8 +32,7 @@ import org.sonar.server.permission.ws.PermissionRequest.Builder;
 import static org.sonar.server.permission.ws.Parameters.createGroupIdParameter;
 import static org.sonar.server.permission.ws.Parameters.createGroupNameParameter;
 import static org.sonar.server.permission.ws.Parameters.createPermissionParameter;
-import static org.sonar.server.permission.ws.Parameters.createProjectKeyParameter;
-import static org.sonar.server.permission.ws.Parameters.createProjectUuidParameter;
+import static org.sonar.server.permission.ws.Parameters.createProjectParameter;
 
 public class RemoveGroupAction implements PermissionsWsAction {
 
@@ -63,8 +62,7 @@ public class RemoveGroupAction implements PermissionsWsAction {
     createPermissionParameter(action);
     createGroupNameParameter(action);
     createGroupIdParameter(action);
-    createProjectUuidParameter(action);
-    createProjectKeyParameter(action);
+    createProjectParameter(action);
   }
 
   @Override
index 4beea58427f9252490a4bfd9ba884328593723be..84fcf01fe183c3c3aea2fd6e9cb6eca7d8d44a00 100644 (file)
@@ -32,11 +32,11 @@ import org.sonar.server.user.UserSession;
 import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdminUser;
 import static org.sonar.server.permission.ws.PermissionRequestValidator.validateProjectPermission;
 import static org.sonar.server.permission.ws.Parameters.PARAM_PERMISSION;
-import static org.sonar.server.permission.ws.Parameters.PARAM_LONG_TEMPLATE_ID;
+import static org.sonar.server.permission.ws.Parameters.PARAM_TEMPLATE_ID_EXPLICIT;
 import static org.sonar.server.permission.ws.Parameters.createGroupIdParameter;
 import static org.sonar.server.permission.ws.Parameters.createGroupNameParameter;
 import static org.sonar.server.permission.ws.Parameters.createProjectPermissionParameter;
-import static org.sonar.server.permission.ws.Parameters.createTemplateKeyParameterToAddRemoveUserOrGroup;
+import static org.sonar.server.permission.ws.Parameters.createExplicitTemplateId;
 
 public class RemoveGroupFromTemplateAction implements PermissionsWsAction {
   private final DbClient dbClient;
@@ -60,7 +60,7 @@ public class RemoveGroupFromTemplateAction implements PermissionsWsAction {
         "It requires administration permissions to access.")
       .setHandler(this);
 
-    createTemplateKeyParameterToAddRemoveUserOrGroup(action);
+    createExplicitTemplateId(action);
     createProjectPermissionParameter(action);
     createGroupIdParameter(action);
     createGroupNameParameter(action);
@@ -70,7 +70,7 @@ public class RemoveGroupFromTemplateAction implements PermissionsWsAction {
   public void handle(Request wsRequest, Response wsResponse) throws Exception {
     checkGlobalAdminUser(userSession);
 
-    String templateKey = wsRequest.mandatoryParam(PARAM_LONG_TEMPLATE_ID);
+    String templateKey = wsRequest.mandatoryParam(PARAM_TEMPLATE_ID_EXPLICIT);
     String permission = wsRequest.mandatoryParam(PARAM_PERMISSION);
     WsGroupRef group = WsGroupRef.fromRequest(wsRequest);
 
index 0a50c443ed2b488c602c5cf30df85933862891d0..03ff653fa6d7a4a66bed7279224587181a98690e 100644 (file)
@@ -30,8 +30,7 @@ import org.sonar.server.permission.PermissionUpdater;
 import org.sonar.server.permission.ws.PermissionRequest.Builder;
 
 import static org.sonar.server.permission.ws.Parameters.createPermissionParameter;
-import static org.sonar.server.permission.ws.Parameters.createProjectKeyParameter;
-import static org.sonar.server.permission.ws.Parameters.createProjectUuidParameter;
+import static org.sonar.server.permission.ws.Parameters.createProjectParameter;
 import static org.sonar.server.permission.ws.Parameters.createUserLoginParameter;
 
 public class RemoveUserAction implements PermissionsWsAction {
@@ -60,8 +59,7 @@ public class RemoveUserAction implements PermissionsWsAction {
 
     createPermissionParameter(action);
     createUserLoginParameter(action);
-    createProjectUuidParameter(action);
-    createProjectKeyParameter(action);
+    createProjectParameter(action);
   }
 
   @Override
index fa58616c86473018446d5b8d46a07f248137668d..fe81fd2938661c932df9b3e277272c68b5476a53 100644 (file)
@@ -32,10 +32,10 @@ import org.sonar.server.user.UserSession;
 import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdminUser;
 import static org.sonar.server.permission.ws.PermissionRequestValidator.validateProjectPermission;
 import static org.sonar.server.permission.ws.Parameters.PARAM_PERMISSION;
-import static org.sonar.server.permission.ws.Parameters.PARAM_LONG_TEMPLATE_ID;
+import static org.sonar.server.permission.ws.Parameters.PARAM_TEMPLATE_ID_EXPLICIT;
 import static org.sonar.server.permission.ws.Parameters.PARAM_USER_LOGIN;
 import static org.sonar.server.permission.ws.Parameters.createProjectPermissionParameter;
-import static org.sonar.server.permission.ws.Parameters.createTemplateKeyParameterToAddRemoveUserOrGroup;
+import static org.sonar.server.permission.ws.Parameters.createExplicitTemplateId;
 import static org.sonar.server.permission.ws.Parameters.createUserLoginParameter;
 
 public class RemoveUserFromTemplateAction implements PermissionsWsAction {
@@ -59,7 +59,7 @@ public class RemoveUserFromTemplateAction implements PermissionsWsAction {
         "It requires administration permissions to access.")
       .setHandler(this);
 
-    createTemplateKeyParameterToAddRemoveUserOrGroup(action);
+    createExplicitTemplateId(action);
     createProjectPermissionParameter(action);
     createUserLoginParameter(action);
   }
@@ -68,7 +68,7 @@ public class RemoveUserFromTemplateAction implements PermissionsWsAction {
   public void handle(Request wsRequest, Response wsResponse) throws Exception {
     checkGlobalAdminUser(userSession);
 
-    String templateKey = wsRequest.mandatoryParam(PARAM_LONG_TEMPLATE_ID);
+    String templateKey = wsRequest.mandatoryParam(PARAM_TEMPLATE_ID_EXPLICIT);
     String permission = wsRequest.mandatoryParam(PARAM_PERMISSION);
     String userLogin = wsRequest.mandatoryParam(PARAM_USER_LOGIN);
 
index 58a4126ed89f59c95ae61fd5f63d1c6d29148fa8..0276ab8d8a10b0593541443d571fba0b0c297058 100644 (file)
@@ -39,8 +39,7 @@ import org.sonarqube.ws.Permissions.SearchProjectPermissionsResponse.Project;
 import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdminUser;
 import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdminUserByComponentKey;
 import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdminUserByComponentUuid;
-import static org.sonar.server.permission.ws.Parameters.createProjectKeyParameter;
-import static org.sonar.server.permission.ws.Parameters.createProjectUuidParameter;
+import static org.sonar.server.permission.ws.Parameters.createProjectParameter;
 import static org.sonar.server.ws.WsUtils.writeProtobuf;
 
 public class SearchProjectPermissionsAction implements PermissionsWsAction {
@@ -70,8 +69,7 @@ public class SearchProjectPermissionsAction implements PermissionsWsAction {
       .addSearchQuery("sonarq", "project names", "project keys")
       .setHandler(this);
 
-    createProjectUuidParameter(action);
-    createProjectKeyParameter(action);
+    createProjectParameter(action);
   }
 
   @Override
@@ -89,7 +87,7 @@ public class SearchProjectPermissionsAction implements PermissionsWsAction {
   }
 
   private void checkRequestAndPermissions(Request wsRequest) {
-    Optional<WsProjectRef> project = WsProjectRef.fromRequest(wsRequest);
+    Optional<WsProjectRef> project = WsProjectRef.optionalFromRequest(wsRequest);
     boolean hasProject = project.isPresent();
     boolean hasProjectUuid = hasProject && project.get().uuid() != null;
     boolean hasProjectKey = hasProject && project.get().key() != null;
index fa2e5949359171a4e6ac8559500bb51ef8dbffff..208171d34f0d966a5ce197430b5b649e3a248fb0 100644 (file)
@@ -90,7 +90,7 @@ public class SearchProjectPermissionsDataLoader {
 
   private List<ComponentDto> searchRootComponents(DbSession dbSession, Request wsRequest, Paging paging) {
     String query = wsRequest.param(TEXT_QUERY);
-    Optional<WsProjectRef> project = WsProjectRef.fromRequest(wsRequest);
+    Optional<WsProjectRef> project = WsProjectRef.optionalFromRequest(wsRequest);
 
     if (project.isPresent()) {
       return singletonList(componentFinder.getProjectByUuidOrKey(dbSession, project.get().uuid(), project.get().key()));
index ef2f92555961ab01c6edf2ef35420a6be89a2648..b8359e3f33c17deaab2958b3a1c3fb86be0eec67 100644 (file)
@@ -44,8 +44,7 @@ import static com.google.common.base.Strings.nullToEmpty;
 import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdminUserByComponentDto;
 import static org.sonar.server.permission.PermissionQueryParser.toMembership;
 import static org.sonar.server.permission.ws.Parameters.createPermissionParameter;
-import static org.sonar.server.permission.ws.Parameters.createProjectKeyParameter;
-import static org.sonar.server.permission.ws.Parameters.createProjectUuidParameter;
+import static org.sonar.server.permission.ws.Parameters.createProjectParameter;
 import static org.sonar.server.ws.WsUtils.writeProtobuf;
 
 public class UsersAction implements PermissionsWsAction {
@@ -79,8 +78,7 @@ public class UsersAction implements PermissionsWsAction {
       .setHandler(this);
 
     createPermissionParameter(action);
-    createProjectUuidParameter(action);
-    createProjectKeyParameter(action);
+    createProjectParameter(action);
   }
 
   @Override
index 1f88281585137e798713728c1f1cbc0dc78ee74a..f83c6d210cac5098fa0df00ecc987e4d6d446aad 100644 (file)
@@ -22,11 +22,10 @@ package org.sonar.server.permission.ws;
 
 import com.google.common.base.Optional;
 import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
 import org.sonar.api.server.ws.Request;
 
+import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_ID;
 import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_KEY;
-import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_UUID;
 import static org.sonar.server.ws.WsUtils.checkRequest;
 
 /**
@@ -36,22 +35,25 @@ class WsProjectRef {
   private final String uuid;
   private final String key;
 
-  private WsProjectRef(@Nullable String uuid, @Nullable String key) {
+  private WsProjectRef(Request wsRequest) {
+    String uuid = wsRequest.param(PARAM_PROJECT_ID);
+    String key = wsRequest.param(PARAM_PROJECT_KEY);
     checkRequest(uuid != null ^ key != null, "Project id or project key can be provided, not both.");
 
     this.uuid = uuid;
     this.key = key;
   }
 
-  static Optional<WsProjectRef> fromRequest(Request wsRequest) {
+  static Optional<WsProjectRef> optionalFromRequest(Request wsRequest) {
     if (hasNoProjectParam(wsRequest)) {
       return Optional.absent();
     }
 
-    return Optional.of(new WsProjectRef(
-      wsRequest.param(PARAM_PROJECT_UUID),
-      wsRequest.param(PARAM_PROJECT_KEY))
-      );
+    return Optional.of(new WsProjectRef(wsRequest));
+  }
+
+  static WsProjectRef fromRequest(Request wsRequest) {
+    return new WsProjectRef(wsRequest);
   }
 
   @CheckForNull
@@ -65,6 +67,6 @@ class WsProjectRef {
   }
 
   private static boolean hasNoProjectParam(Request wsRequest) {
-    return !wsRequest.hasParam(PARAM_PROJECT_UUID) && !wsRequest.hasParam(PARAM_PROJECT_KEY);
+    return !wsRequest.hasParam(PARAM_PROJECT_ID) && !wsRequest.hasParam(PARAM_PROJECT_KEY);
   }
 }
index 817bd23cce3114da159ce9c73b64a336a257bb99..840fd55d86f612413fcc7d81a165c097551b6cdf 100644 (file)
@@ -22,14 +22,13 @@ package org.sonar.server.permission;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
+import java.util.Collections;
+import java.util.Map;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.server.exceptions.BadRequestException;
 
-import java.util.Collections;
-import java.util.Map;
-
 import static org.assertj.core.api.Assertions.assertThat;
 
 public class ApplyPermissionTemplateQueryTest {
@@ -44,10 +43,10 @@ public class ApplyPermissionTemplateQueryTest {
     params.put("template_key", "my_template_key");
     params.put("components", Lists.newArrayList("1", "2", "3"));
 
-    ApplyPermissionTemplateQuery query = ApplyPermissionTemplateQuery.buildFromParams(params);
+    ApplyPermissionTemplateQuery query = ApplyPermissionTemplateQuery.createFromMap(params);
 
-    assertThat(query.getTemplateKey()).isEqualTo("my_template_key");
-    assertThat(query.getSelectedComponents()).containsOnly("1", "2", "3");
+    assertThat(query.getTemplateUuid()).isEqualTo("my_template_key");
+    assertThat(query.getComponentKeys()).containsOnly("1", "2", "3");
   }
 
   @Test
@@ -60,21 +59,19 @@ public class ApplyPermissionTemplateQueryTest {
     params.put("template_key", "");
     params.put("components", Lists.newArrayList("1", "2", "3"));
 
-    ApplyPermissionTemplateQuery query = ApplyPermissionTemplateQuery.buildFromParams(params);
-    query.validate();
+    ApplyPermissionTemplateQuery.createFromMap(params);
   }
 
   @Test
   public void should_invalidate_query_with_no_components() {
 
     throwable.expect(BadRequestException.class);
-    throwable.expectMessage("Please provide at least one entry to which the permission template should be applied");
+    throwable.expectMessage("No project provided. Please provide at least one project.");
 
     Map<String, Object> params = Maps.newHashMap();
     params.put("template_key", "my_template_key");
     params.put("components", Collections.EMPTY_LIST);
 
-    ApplyPermissionTemplateQuery query = ApplyPermissionTemplateQuery.buildFromParams(params);
-    query.validate();
+    ApplyPermissionTemplateQuery.createFromMap(params);
   }
 }
index 5243d1d1fcc998fd903ad0216ab1840e3294eec6..221c7985d39dc3cf61257286ddc85ed49a7b8983 100644 (file)
@@ -53,7 +53,7 @@ import static org.sonar.server.permission.ws.Parameters.PARAM_GROUP_ID;
 import static org.sonar.server.permission.ws.Parameters.PARAM_GROUP_NAME;
 import static org.sonar.server.permission.ws.Parameters.PARAM_PERMISSION;
 import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_KEY;
-import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_UUID;
+import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_ID;
 import static org.sonar.server.permission.ws.PermissionsWs.ENDPOINT;
 
 @Category(DbTests.class)
@@ -118,7 +118,7 @@ public class AddGroupActionTest {
 
     newRequest()
       .setParam(PARAM_GROUP_NAME, "sonar-administrators")
-      .setParam(PARAM_PROJECT_UUID, "project-uuid")
+      .setParam(PARAM_PROJECT_ID, "project-uuid")
       .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
       .execute();
 
@@ -156,7 +156,7 @@ public class AddGroupActionTest {
 
     newRequest()
       .setParam(PARAM_GROUP_NAME, "sonar-administrators")
-      .setParam(PARAM_PROJECT_UUID, "unknown-project-uuid")
+      .setParam(PARAM_PROJECT_ID, "unknown-project-uuid")
       .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
       .execute();
   }
@@ -186,7 +186,7 @@ public class AddGroupActionTest {
 
     newRequest()
       .setParam(PARAM_GROUP_NAME, "sonar-administrators")
-      .setParam(PARAM_PROJECT_UUID, "file-uuid")
+      .setParam(PARAM_PROJECT_ID, "file-uuid")
       .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
       .execute();
   }
@@ -230,7 +230,7 @@ public class AddGroupActionTest {
     newRequest()
       .setParam(PARAM_GROUP_NAME, "sonar-administrators")
       .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
-      .setParam(PARAM_PROJECT_UUID, "project-uuid")
+      .setParam(PARAM_PROJECT_ID, "project-uuid")
       .setParam(PARAM_PROJECT_KEY, "project-key")
       .execute();
   }
index 16c4e5ea5935e67c6f5d7937461f9a1658ecf304..be155cbf5ccdb389cee7fe06c1080e08ed8992e0 100644 (file)
@@ -59,7 +59,7 @@ import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTem
 import static org.sonar.db.user.GroupMembershipQuery.IN;
 import static org.sonar.db.user.GroupTesting.newGroupDto;
 import static org.sonar.server.permission.ws.Parameters.PARAM_GROUP_ID;
-import static org.sonar.server.permission.ws.Parameters.PARAM_LONG_TEMPLATE_ID;
+import static org.sonar.server.permission.ws.Parameters.PARAM_TEMPLATE_ID_EXPLICIT;
 import static org.sonar.server.permission.ws.Parameters.PARAM_PERMISSION;
 
 @Category(DbTests.class)
@@ -103,7 +103,7 @@ public class AddGroupToTemplateActionTest {
   @Test
   public void add_with_group_id() {
     ws.newRequest()
-      .setParam(PARAM_LONG_TEMPLATE_ID, permissionTemplate.getKee())
+      .setParam(PARAM_TEMPLATE_ID_EXPLICIT, permissionTemplate.getKee())
       .setParam(PARAM_PERMISSION, CODEVIEWER)
       .setParam(PARAM_GROUP_ID, String.valueOf(group.getId()))
       .execute();
@@ -200,7 +200,7 @@ public class AddGroupToTemplateActionTest {
       request.setParam(Parameters.PARAM_GROUP_NAME, groupName);
     }
     if (templateKey != null) {
-      request.setParam(PARAM_LONG_TEMPLATE_ID, templateKey);
+      request.setParam(PARAM_TEMPLATE_ID_EXPLICIT, templateKey);
     }
     if (permission != null) {
       request.setParam(Parameters.PARAM_PERMISSION, permission);
index 69f9523beddc77e1aaadc9c80d02950315c5e742..2d9f96bdd316d757c262e754b6b0eb1c1896d1bf 100644 (file)
@@ -51,7 +51,7 @@ import static org.sonar.db.component.ComponentTesting.newProjectDto;
 import static org.sonar.server.permission.ws.AddUserAction.ACTION;
 import static org.sonar.server.permission.ws.Parameters.PARAM_PERMISSION;
 import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_KEY;
-import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_UUID;
+import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_ID;
 import static org.sonar.server.permission.ws.Parameters.PARAM_USER_LOGIN;
 import static org.sonar.server.permission.ws.PermissionsWs.ENDPOINT;
 
@@ -99,7 +99,7 @@ public class AddUserActionTest {
 
     ws.newPostRequest(ENDPOINT, ACTION)
       .setParam(PARAM_USER_LOGIN, "ray.bradbury")
-      .setParam(PARAM_PROJECT_UUID, "project-uuid")
+      .setParam(PARAM_PROJECT_ID, "project-uuid")
       .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
       .execute();
 
@@ -130,7 +130,7 @@ public class AddUserActionTest {
 
     ws.newPostRequest(ENDPOINT, ACTION)
       .setParam(PARAM_USER_LOGIN, "ray.bradbury")
-      .setParam(PARAM_PROJECT_UUID, "unknown-project-uuid")
+      .setParam(PARAM_PROJECT_ID, "unknown-project-uuid")
       .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
       .execute();
   }
@@ -153,7 +153,7 @@ public class AddUserActionTest {
 
     ws.newPostRequest(ENDPOINT, ACTION)
       .setParam(PARAM_USER_LOGIN, "ray.bradbury")
-      .setParam(PARAM_PROJECT_UUID, "file-uuid")
+      .setParam(PARAM_PROJECT_ID, "file-uuid")
       .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
       .execute();
   }
@@ -196,7 +196,7 @@ public class AddUserActionTest {
     ws.newPostRequest(ENDPOINT, ACTION)
       .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
       .setParam(PARAM_USER_LOGIN, "ray.bradbury")
-      .setParam(PARAM_PROJECT_UUID, "project-uuid")
+      .setParam(PARAM_PROJECT_ID, "project-uuid")
       .setParam(PARAM_PROJECT_KEY, "project-key")
       .execute();
   }
index 023da2d085424b205cd1f3500fdb912f6ebb0147..ee2cfdd764e28544aa31b22f57d289e1aa805b85 100644 (file)
@@ -168,7 +168,7 @@ public class AddUserToTemplateActionTest {
       request.setParam(Parameters.PARAM_USER_LOGIN, userLogin);
     }
     if (templateKey != null) {
-      request.setParam(Parameters.PARAM_LONG_TEMPLATE_ID, templateKey);
+      request.setParam(Parameters.PARAM_TEMPLATE_ID_EXPLICIT, templateKey);
     }
     if (permission != null) {
       request.setParam(Parameters.PARAM_PERMISSION, permission);
index bd7a9e20629981a6d3000e9139f31a43f136a292..707ce4eb5c41c239dae890fc61a99d0b7146e4af 100644 (file)
@@ -55,7 +55,7 @@ import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
 import static org.sonar.db.component.ComponentTesting.newProjectDto;
 import static org.sonar.server.permission.ws.Parameters.PARAM_PERMISSION;
 import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_KEY;
-import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_UUID;
+import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_ID;
 import static org.sonar.test.JsonAssert.assertJson;
 
 @Category(DbTests.class)
@@ -160,7 +160,7 @@ public class GroupsActionTest {
 
     String result = ws.newRequest()
       .setParam(PARAM_PERMISSION, ISSUE_ADMIN)
-      .setParam(PARAM_PROJECT_UUID, "project-uuid")
+      .setParam(PARAM_PROJECT_ID, "project-uuid")
       .execute().getInput();
 
     assertThat(result).contains("project-group-name")
@@ -209,12 +209,11 @@ public class GroupsActionTest {
   @Test
   public void fail_if_project_uuid_and_project_key_are_provided() {
     expectedException.expect(BadRequestException.class);
-    expectedException.expectMessage("Project id or project key can be provided, not both.");
     dbClient.componentDao().insert(dbSession, newProjectDto("project-uuid").setKey("project-key"));
 
     ws.newRequest()
       .setParam(PARAM_PERMISSION, SCAN_EXECUTION)
-      .setParam(PARAM_PROJECT_UUID, "project-uuid")
+      .setParam(PARAM_PROJECT_ID, "project-uuid")
       .setParam(PARAM_PROJECT_KEY, "project-key")
       .execute();
   }
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/PermissionRequestValidatorTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/PermissionRequestValidatorTest.java
deleted file mode 100644 (file)
index ea19efd..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.ws;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.server.exceptions.BadRequestException;
-
-import static org.sonar.server.permission.ws.PermissionRequestValidator.MSG_TEMPLATE_NAME_NOT_BLANK;
-
-public class PermissionRequestValidatorTest {
-  @Rule
-  public ExpectedException expectedException = ExpectedException.none();
-
-  @Test
-  public void validate_template_name() {
-    PermissionRequestValidator.validateTemplateNameFormat("  text \r\n");
-    expectedException.expect(BadRequestException.class);
-    expectedException.expectMessage(MSG_TEMPLATE_NAME_NOT_BLANK);
-
-    PermissionRequestValidator.validateTemplateNameFormat("   \r\n");
-  }
-}
index 4e85fdb1efe636e867466b481eef22e27986b510..0fadbf6a91c22790a2a9ea2094c365e4d6b86145 100644 (file)
@@ -53,7 +53,7 @@ import static org.sonar.server.permission.ws.Parameters.PARAM_GROUP_ID;
 import static org.sonar.server.permission.ws.Parameters.PARAM_GROUP_NAME;
 import static org.sonar.server.permission.ws.Parameters.PARAM_PERMISSION;
 import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_KEY;
-import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_UUID;
+import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_ID;
 import static org.sonar.server.permission.ws.RemoveGroupAction.ACTION;
 
 @Category(DbTests.class)
@@ -117,7 +117,7 @@ public class RemoveGroupActionTest {
 
     newRequest()
       .setParam(PARAM_GROUP_NAME, "sonar-administrators")
-      .setParam(PARAM_PROJECT_UUID, "project-uuid")
+      .setParam(PARAM_PROJECT_ID, "project-uuid")
       .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
       .execute();
 
@@ -149,7 +149,7 @@ public class RemoveGroupActionTest {
 
     newRequest()
       .setParam(PARAM_GROUP_NAME, "sonar-administrators")
-      .setParam(PARAM_PROJECT_UUID, "unknown-project-uuid")
+      .setParam(PARAM_PROJECT_ID, "unknown-project-uuid")
       .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
       .execute();
   }
@@ -173,7 +173,7 @@ public class RemoveGroupActionTest {
 
     newRequest()
       .setParam(PARAM_GROUP_NAME, "sonar-administrators")
-      .setParam(PARAM_PROJECT_UUID, "file-uuid")
+      .setParam(PARAM_PROJECT_ID, "file-uuid")
       .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
       .execute();
   }
@@ -227,7 +227,7 @@ public class RemoveGroupActionTest {
     newRequest()
       .setParam(PARAM_GROUP_NAME, "sonar-administrators")
       .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
-      .setParam(PARAM_PROJECT_UUID, "project-uuid")
+      .setParam(PARAM_PROJECT_ID, "project-uuid")
       .setParam(PARAM_PROJECT_KEY, "project-key")
       .execute();
   }
index 9d2da24e995a27565bb8295349f6e8d36b7dc48d..7b880d69a8f7601d6138207c3b9c9dd112d79232 100644 (file)
@@ -57,7 +57,7 @@ import static org.sonar.db.user.GroupMembershipQuery.IN;
 import static org.sonar.db.user.GroupTesting.newGroupDto;
 import static org.sonar.server.permission.ws.Parameters.PARAM_GROUP_ID;
 import static org.sonar.server.permission.ws.Parameters.PARAM_PERMISSION;
-import static org.sonar.server.permission.ws.Parameters.PARAM_LONG_TEMPLATE_ID;
+import static org.sonar.server.permission.ws.Parameters.PARAM_TEMPLATE_ID_EXPLICIT;
 
 @Category(DbTests.class)
 public class RemoveGroupFromTemplateActionTest {
@@ -108,7 +108,7 @@ public class RemoveGroupFromTemplateActionTest {
     commit();
 
     ws.newRequest()
-      .setParam(PARAM_LONG_TEMPLATE_ID, permissionTemplate.getKee())
+      .setParam(PARAM_TEMPLATE_ID_EXPLICIT, permissionTemplate.getKee())
       .setParam(PARAM_PERMISSION, PERMISSION)
       .setParam(PARAM_GROUP_ID, String.valueOf(group.getId()))
       .execute();
@@ -200,7 +200,7 @@ public class RemoveGroupFromTemplateActionTest {
       request.setParam(Parameters.PARAM_GROUP_NAME, groupName);
     }
     if (templateKey != null) {
-      request.setParam(PARAM_LONG_TEMPLATE_ID, templateKey);
+      request.setParam(PARAM_TEMPLATE_ID_EXPLICIT, templateKey);
     }
     if (permission != null) {
       request.setParam(Parameters.PARAM_PERMISSION, permission);
index 4970e7912108967679b0449540e444fcbf532eae..bfdb74c7c47f0965b215ffeb16d05fe3ca02dba7 100644 (file)
@@ -50,7 +50,7 @@ import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.component.ComponentTesting.newProjectDto;
 import static org.sonar.server.permission.ws.Parameters.PARAM_PERMISSION;
 import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_KEY;
-import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_UUID;
+import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_ID;
 import static org.sonar.server.permission.ws.Parameters.PARAM_USER_LOGIN;
 import static org.sonar.server.permission.ws.PermissionsWs.ENDPOINT;
 import static org.sonar.server.permission.ws.RemoveUserAction.ACTION;
@@ -98,7 +98,7 @@ public class RemoveUserActionTest {
 
     ws.newPostRequest(PermissionsWs.ENDPOINT, ACTION)
       .setParam(PARAM_USER_LOGIN, "ray.bradbury")
-      .setParam(PARAM_PROJECT_UUID, "project-uuid")
+      .setParam(PARAM_PROJECT_ID, "project-uuid")
       .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
       .execute();
 
@@ -128,7 +128,7 @@ public class RemoveUserActionTest {
 
     ws.newPostRequest(PermissionsWs.ENDPOINT, ACTION)
       .setParam(PARAM_USER_LOGIN, "ray.bradbury")
-      .setParam(PARAM_PROJECT_UUID, "unknown-project-uuid")
+      .setParam(PARAM_PROJECT_ID, "unknown-project-uuid")
       .setParam(PARAM_PERMISSION, UserRole.ISSUE_ADMIN)
       .execute();
   }
@@ -150,7 +150,7 @@ public class RemoveUserActionTest {
 
     ws.newPostRequest(PermissionsWs.ENDPOINT, ACTION)
       .setParam(PARAM_USER_LOGIN, "ray.bradbury")
-      .setParam(PARAM_PROJECT_UUID, "file-uuid")
+      .setParam(PARAM_PROJECT_ID, "file-uuid")
       .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
       .execute();
   }
@@ -192,7 +192,7 @@ public class RemoveUserActionTest {
     ws.newPostRequest(ENDPOINT, ACTION)
       .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
       .setParam(PARAM_USER_LOGIN, "ray.bradbury")
-      .setParam(PARAM_PROJECT_UUID, "project-uuid")
+      .setParam(PARAM_PROJECT_ID, "project-uuid")
       .setParam(PARAM_PROJECT_KEY, "project-key")
       .execute();
   }
index 08ffe9ca61bb018c46c7fcc75d12e303070d689f..1b7187e335e90d9409b7eb3ff53e43b32d74a2ea 100644 (file)
@@ -192,7 +192,7 @@ public class RemoveUserFromTemplateActionTest {
       request.setParam(Parameters.PARAM_USER_LOGIN, userLogin);
     }
     if (templateKey != null) {
-      request.setParam(Parameters.PARAM_LONG_TEMPLATE_ID, templateKey);
+      request.setParam(Parameters.PARAM_TEMPLATE_ID_EXPLICIT, templateKey);
     }
     if (permission != null) {
       request.setParam(Parameters.PARAM_PERMISSION, permission);
index 8a6b7c2967d6c9a025335242ca6d4fb5f7514a04..86db252ba226dcfdf957ccdbc5d37c55677ec268 100644 (file)
@@ -59,7 +59,7 @@ import static org.sonar.db.component.ComponentTesting.newProjectDto;
 import static org.sonar.db.component.ComponentTesting.newView;
 import static org.sonar.db.user.GroupTesting.newGroupDto;
 import static org.sonar.db.user.UserTesting.newUserDto;
-import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_UUID;
+import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_ID;
 import static org.sonar.test.JsonAssert.assertJson;
 
 public class SearchProjectPermissionsActionTest {
@@ -147,7 +147,7 @@ public class SearchProjectPermissionsActionTest {
     commit();
 
     String result = ws.newRequest()
-      .setParam(PARAM_PROJECT_UUID, "project-uuid")
+      .setParam(PARAM_PROJECT_ID, "project-uuid")
       .execute().getInput();
 
     assertThat(result).contains("project-uuid");
index 684f96ed564f4363fc188f0260db1642a218f737..cb467bcd7a16b1401d8badd8dc81515db0e7d1d4 100644 (file)
@@ -32,6 +32,7 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.user.GroupDto;
 import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
@@ -208,6 +209,10 @@ public class UpdateTemplateActionTest {
     return dbClient.permissionTemplateDao().insert(dbSession, template);
   }
 
+  private GroupDto insertGroup(GroupDto group) {
+    return dbClient.groupDao().insert(db.getSession(), group);
+  }
+
   private void commit() {
     dbSession.commit();
   }
index 56c679584154f76b7f3fa44ea9ca4597f1f4ee6a..f6bb2642ce174764d61a3be16933a81b4cef2995 100644 (file)
@@ -52,7 +52,7 @@ import static org.sonar.db.component.ComponentTesting.newProjectDto;
 import static org.sonar.db.user.UserTesting.newUserDto;
 import static org.sonar.server.permission.ws.Parameters.PARAM_PERMISSION;
 import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_KEY;
-import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_UUID;
+import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_ID;
 import static org.sonar.test.JsonAssert.assertJson;
 
 @Category(DbTests.class)
@@ -120,7 +120,7 @@ public class UsersActionTest {
 
     String result = ws.newRequest()
       .setParam(PARAM_PERMISSION, ISSUE_ADMIN)
-      .setParam(PARAM_PROJECT_UUID, "project-uuid")
+      .setParam(PARAM_PROJECT_ID, "project-uuid")
       .execute().getInput();
 
     assertThat(result).contains("project-user-login")
@@ -195,7 +195,7 @@ public class UsersActionTest {
 
     ws.newRequest()
       .setParam(PARAM_PERMISSION, SYSTEM_ADMIN)
-      .setParam(PARAM_PROJECT_UUID, "project-uuid")
+      .setParam(PARAM_PROJECT_ID, "project-uuid")
       .setParam(PARAM_PROJECT_KEY, "project-key")
       .execute();
   }
index 24d39bc3d414e01c7f397899f0c992d56314d12c..91deb4473e1e1e24cc40b72633e786e0252bec45 100644 (file)
@@ -134,17 +134,19 @@ public class PermissionRepository {
     }
   }
 
-  public void applyPermissionTemplate(DbSession session, String templateKey, Long resourceId) {
-    PermissionTemplateDto permissionTemplate = dbClient.permissionTemplateDao().selectPermissionTemplateWithPermissions(session, templateKey);
+  public void applyPermissionTemplate(DbSession session, String templateUuid, long resourceId) {
+    PermissionTemplateDto permissionTemplate = dbClient.permissionTemplateDao().selectPermissionTemplateWithPermissions(session, templateUuid);
     updateProjectAuthorizationDate(session, resourceId);
     dbClient.roleDao().removeAllPermissions(session, resourceId);
     List<PermissionTemplateUserDto> usersPermissions = permissionTemplate.getUsersPermissions();
+    //TODO should return an empty list if there's no user permissions
     if (usersPermissions != null) {
       for (PermissionTemplateUserDto userPermission : usersPermissions) {
         insertUserPermission(resourceId, userPermission.getUserId(), userPermission.getPermission(), false, session);
       }
     }
     List<PermissionTemplateGroupDto> groupsPermissions = permissionTemplate.getGroupsPermissions();
+    //TODO should return an empty list if there's no group permission
     if (groupsPermissions != null) {
       for (PermissionTemplateGroupDto groupPermission : groupsPermissions) {
         Long groupId = groupPermission.getGroupId() == null ? null : groupPermission.getGroupId();
@@ -153,7 +155,7 @@ public class PermissionRepository {
     }
   }
 
-  public void grantDefaultRoles(DbSession session, Long componentId, String qualifier) {
+  public void grantDefaultRoles(DbSession session, long componentId, String qualifier) {
     ResourceDto resource = dbClient.resourceDao().selectResource(componentId, session);
     String applicablePermissionTemplateKey = getApplicablePermissionTemplateKey(session, resource.getKey(), qualifier);
     applyPermissionTemplate(session, applicablePermissionTemplateKey, componentId);
index 9e4b0e806fd9a47c7c0b90da3c974f8d3887b164..e79376bd24ce371fb9ded7b4781dea23135f0b1b 100644 (file)
@@ -66,11 +66,26 @@ public class PermissionTemplateDto {
     return kee;
   }
 
+  /**
+   * @since 5.2 the kee column is a proper uuid. Before that it was build on the name + timestamp
+   */
+  public String getUuid() {
+    return kee;
+  }
+
   public PermissionTemplateDto setKee(String kee) {
     this.kee = kee;
     return this;
   }
 
+  /**
+   * @since 5.2 the kee column is a proper uuid. Before it was build on the name + timestamp
+   */
+  public PermissionTemplateDto setUuid(String uuid) {
+    this.kee = uuid;
+    return this;
+  }
+
   @CheckForNull
   public String getDescription() {
     return description;