aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-11-12 17:08:52 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-11-17 13:41:01 +0100
commitf0f35839eba2256b1166b21f683c1cba67eef6be (patch)
treef73dbf54319393eb7a3f71bb5b71c03dc12198ec /server
parenta000d18795598ee8c666dc7b90aa57eb3904bdd1 (diff)
downloadsonarqube-f0f35839eba2256b1166b21f683c1cba67eef6be.tar.gz
sonarqube-f0f35839eba2256b1166b21f683c1cba67eef6be.zip
SONAR-6947 api/permissions/remove_user use RemoveUserWsRequest
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/permission/ws/RemoveUserAction.java32
1 files changed, 26 insertions, 6 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/RemoveUserAction.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/RemoveUserAction.java
index 14b71ec299a..136ce829b24 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/RemoveUserAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/RemoveUserAction.java
@@ -20,6 +20,7 @@
package org.sonar.server.permission.ws;
+import com.google.common.base.Optional;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
@@ -27,11 +28,17 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.server.permission.PermissionChange;
import org.sonar.server.permission.PermissionUpdater;
-import org.sonar.server.permission.ws.PermissionRequest.Builder;
+import org.sonarqube.ws.client.permission.RemoveUserWsRequest;
+import static org.sonar.server.permission.ws.PermissionRequestValidator.validatePermission;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createPermissionParameter;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createProjectParameter;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createUserLoginParameter;
+import static org.sonar.server.permission.ws.WsProjectRef.newOptionalWsProjectRef;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_ID;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_USER_LOGIN;
public class RemoveUserAction implements PermissionsWsAction {
@@ -64,19 +71,32 @@ public class RemoveUserAction implements PermissionsWsAction {
@Override
public void handle(Request request, Response response) throws Exception {
+ doHandle(toRemoveUserWsRequest(request));
+ response.noContent();
+ }
+
+ private void doHandle(RemoveUserWsRequest request) {
DbSession dbSession = dbClient.openSession(false);
try {
- PermissionRequest permissionRequest = new Builder(request).withUser().build();
+ Optional<WsProjectRef> projectRef = newOptionalWsProjectRef(request.getProjectId(), request.getProjectKey());
+ validatePermission(request.getPermission(), projectRef);
PermissionChange permissionChange = permissionChangeBuilder.buildUserPermissionChange(
dbSession,
- permissionRequest.permission(),
- permissionRequest.project(),
- permissionRequest.userLogin());
+ request.getPermission(),
+ projectRef,
+ request.getLogin());
permissionUpdater.removePermission(permissionChange);
- response.noContent();
} finally {
dbClient.closeSession(dbSession);
}
}
+
+ private static RemoveUserWsRequest toRemoveUserWsRequest(Request request) {
+ return new RemoveUserWsRequest()
+ .setPermission(request.mandatoryParam(PARAM_PERMISSION))
+ .setLogin(request.mandatoryParam(PARAM_USER_LOGIN))
+ .setProjectId(request.param(PARAM_PROJECT_ID))
+ .setProjectKey(request.param(PARAM_PROJECT_KEY));
+ }
}