import org.sonar.db.user.GroupDto;
import org.sonar.server.permission.ws.PermissionDependenciesFinder;
import org.sonar.server.permission.ws.PermissionsWsAction;
-import org.sonar.server.usergroups.ws.WsGroupRef;
-import org.sonar.server.permission.ws.WsTemplateRef;
import org.sonar.server.user.UserSession;
+import org.sonar.server.usergroups.ws.WsGroupRef;
+import org.sonarqube.ws.client.permission.RemoveGroupFromTemplateWsRequest;
import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdminUser;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
+import static org.sonar.server.permission.ws.PermissionRequestValidator.validateProjectPermission;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createGroupIdParameter;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createGroupNameParameter;
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.PermissionRequestValidator.validateProjectPermission;
+import static org.sonar.server.permission.ws.WsTemplateRef.newTemplateRef;
+import static org.sonar.server.usergroups.ws.WsGroupRef.newWsGroupRef;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_ID;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_NAME;
+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;
public class RemoveGroupFromTemplateAction implements PermissionsWsAction {
private final DbClient dbClient;
}
@Override
- public void handle(Request wsRequest, Response wsResponse) throws Exception {
+ public void handle(Request request, Response response) throws Exception {
checkGlobalAdminUser(userSession);
+ doHandle(toRemoveGroupFromTemplateWsRequest(request));
+ response.noContent();
+ }
- String permission = wsRequest.mandatoryParam(PARAM_PERMISSION);
- WsGroupRef group = WsGroupRef.newWsGroupRefFromPermissionRequest(wsRequest);
+ private void doHandle(RemoveGroupFromTemplateWsRequest request) {
+ String permission = request.getPermission();
+ Long groupIdInRequest = request.getGroupId() == null ? null : Long.valueOf(request.getGroupId());
+ WsGroupRef group = newWsGroupRef(groupIdInRequest, request.getGroupName());
DbSession dbSession = dbClient.openSession(false);
try {
validateProjectPermission(permission);
-
- PermissionTemplateDto template = dependenciesFinder.getTemplate(dbSession, WsTemplateRef.fromRequest(wsRequest));
+ PermissionTemplateDto template = dependenciesFinder.getTemplate(dbSession, newTemplateRef(request.getTemplateId(), request.getTemplateName()));
GroupDto groupDto = dependenciesFinder.getGroup(dbSession, group);
Long groupId = groupDto == null ? null : groupDto.getId();
} finally {
dbClient.closeSession(dbSession);
}
+ }
- wsResponse.noContent();
+ private static RemoveGroupFromTemplateWsRequest toRemoveGroupFromTemplateWsRequest(Request request) {
+ return new RemoveGroupFromTemplateWsRequest()
+ .setPermission(request.mandatoryParam(PARAM_PERMISSION))
+ .setGroupId(request.param(PARAM_GROUP_ID))
+ .setGroupName(request.param(PARAM_GROUP_NAME))
+ .setTemplateId(request.param(PARAM_TEMPLATE_ID))
+ .setTemplateName(request.param(PARAM_TEMPLATE_NAME));
}
}
.setParam(PARAM_PROJECT_KEY, request.getProjectKey()));
}
+ public void removeGroupFromTemplate(RemoveGroupFromTemplateWsRequest request) {
+ wsClient.execute(newPostRequest(action("remove_group_from_template"))
+ .setParam(PARAM_PERMISSION, request.getPermission())
+ .setParam(PARAM_GROUP_ID, request.getGroupId())
+ .setParam(PARAM_GROUP_NAME, request.getGroupName())
+ .setParam(PARAM_TEMPLATE_ID, request.getTemplateId())
+ .setParam(PARAM_TEMPLATE_NAME, request.getTemplateName()));
+ }
+
private static String action(String action) {
return PermissionsWsParameters.ENDPOINT + "/" + action;
}
--- /dev/null
+/*
+ * 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.sonarqube.ws.client.permission;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+import static java.util.Objects.requireNonNull;
+
+public class RemoveGroupFromTemplateWsRequest {
+ private String permission;
+ private String groupId;
+ private String groupName;
+ private String templateId;
+ private String templateName;
+
+ public String getPermission() {
+ return permission;
+ }
+
+ public RemoveGroupFromTemplateWsRequest setPermission(String permission) {
+ this.permission = requireNonNull(permission);
+ return this;
+ }
+
+ @CheckForNull
+ public String getGroupId() {
+ return groupId;
+ }
+
+ public RemoveGroupFromTemplateWsRequest setGroupId(@Nullable String groupId) {
+ this.groupId = groupId;
+ return this;
+ }
+
+ @CheckForNull
+ public String getGroupName() {
+ return groupName;
+ }
+
+ public RemoveGroupFromTemplateWsRequest setGroupName(@Nullable String groupName) {
+ this.groupName = groupName;
+ return this;
+ }
+
+ @CheckForNull
+ public String getTemplateId() {
+ return templateId;
+ }
+
+ public RemoveGroupFromTemplateWsRequest setTemplateId(@Nullable String templateId) {
+ this.templateId = templateId;
+ return this;
+ }
+
+ @CheckForNull
+ public String getTemplateName() {
+ return templateName;
+ }
+
+ public RemoveGroupFromTemplateWsRequest setTemplateName(@Nullable String templateName) {
+ this.templateName = templateName;
+ return this;
+ }
+}