aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-11-12 17:19:38 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-11-17 13:41:02 +0100
commit3682b11b6704b11688bdf435159c7f8eb651e03c (patch)
tree1dbb341bca58e60ad7f87ee5f49d59a537bc3550 /server/sonar-server
parentf0f35839eba2256b1166b21f683c1cba67eef6be (diff)
downloadsonarqube-3682b11b6704b11688bdf435159c7f8eb651e03c.tar.gz
sonarqube-3682b11b6704b11688bdf435159c7f8eb651e03c.zip
SONAR-6947 api/permissions/remove_user_from_template use RemoveUserFromTemplateWsRequest
Diffstat (limited to 'server/sonar-server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/RemoveUserFromTemplateAction.java30
1 files changed, 22 insertions, 8 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/RemoveUserFromTemplateAction.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/RemoveUserFromTemplateAction.java
index 3a1254cd483..18e125af5e6 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/RemoveUserFromTemplateAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/RemoveUserFromTemplateAction.java
@@ -31,14 +31,17 @@ import org.sonar.server.permission.ws.PermissionDependenciesFinder;
import org.sonar.server.permission.ws.PermissionsWsAction;
import org.sonar.server.permission.ws.WsTemplateRef;
import org.sonar.server.user.UserSession;
+import org.sonarqube.ws.client.permission.RemoveUserFromTemplateWsRequest;
import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdminUser;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_USER_LOGIN;
+import static org.sonar.server.permission.ws.PermissionRequestValidator.validateProjectPermission;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createProjectPermissionParameter;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createTemplateParameters;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createUserLoginParameter;
-import static org.sonar.server.permission.ws.PermissionRequestValidator.validateProjectPermission;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_USER_LOGIN;
public class RemoveUserFromTemplateAction implements PermissionsWsAction {
private final DbClient dbClient;
@@ -67,16 +70,21 @@ public class RemoveUserFromTemplateAction implements PermissionsWsAction {
}
@Override
- public void handle(Request wsRequest, Response wsResponse) throws Exception {
+ public void handle(Request request, Response response) throws Exception {
+ doHandle(toRemoveUserFromTemplateWsRequest(request));
+ response.noContent();
+ }
+
+ private void doHandle(RemoveUserFromTemplateWsRequest request) {
checkGlobalAdminUser(userSession);
- String permission = wsRequest.mandatoryParam(PARAM_PERMISSION);
- String userLogin = wsRequest.mandatoryParam(PARAM_USER_LOGIN);
+ String permission = request.getPermission();
+ String userLogin = request.getLogin();
DbSession dbSession = dbClient.openSession(false);
try {
validateProjectPermission(permission);
- PermissionTemplateDto template = dependenciesFinder.getTemplate(dbSession, WsTemplateRef.fromRequest(wsRequest));
+ PermissionTemplateDto template = dependenciesFinder.getTemplate(dbSession, WsTemplateRef.newTemplateRef(request.getTemplateId(), request.getTemplateName()));
UserDto user = dependenciesFinder.getUser(dbSession, userLogin);
dbClient.permissionTemplateDao().deleteUserPermission(dbSession, template.getId(), user.getId(), permission);
@@ -84,7 +92,13 @@ public class RemoveUserFromTemplateAction implements PermissionsWsAction {
} finally {
dbClient.closeSession(dbSession);
}
+ }
- wsResponse.noContent();
+ private static RemoveUserFromTemplateWsRequest toRemoveUserFromTemplateWsRequest(Request request) {
+ return new RemoveUserFromTemplateWsRequest()
+ .setPermission(request.mandatoryParam(PARAM_PERMISSION))
+ .setLogin(request.mandatoryParam(PARAM_USER_LOGIN))
+ .setTemplateId(request.param(PARAM_TEMPLATE_ID))
+ .setTemplateName(request.param(PARAM_TEMPLATE_NAME));
}
}