diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-11-12 17:08:52 +0100 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-11-17 13:41:01 +0100 |
commit | f0f35839eba2256b1166b21f683c1cba67eef6be (patch) | |
tree | f73dbf54319393eb7a3f71bb5b71c03dc12198ec /server | |
parent | a000d18795598ee8c666dc7b90aa57eb3904bdd1 (diff) | |
download | sonarqube-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.java | 32 |
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)); + } } |