import org.sonar.server.user.UserSession;
import org.sonarqube.ws.client.permission.RemoveProjectCreatorFromTemplateWsRequest;
-import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdminUser;
+import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdmin;
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.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_ORGANIZATION_KEY;
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;
@Override
public void handle(Request request, Response response) throws Exception {
- checkGlobalAdminUser(userSession);
doHandle(toWsRequest(request));
response.noContent();
}
private void doHandle(RemoveProjectCreatorFromTemplateWsRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
- PermissionTemplateDto template = wsSupport.findTemplate(dbSession, WsTemplateRef.newTemplateRef(request.getTemplateId(), request.getTemplateName()));
+ PermissionTemplateDto template = wsSupport.findTemplate(dbSession, WsTemplateRef.newTemplateRef(
+ request.getTemplateId(), request.getOrganization(), request.getTemplateName()));
+ checkProjectAdmin(userSession, template.getOrganizationUuid(), Optional.empty());
+
PermissionTemplateCharacteristicDao dao = dbClient.permissionTemplateCharacteristicDao();
Optional<PermissionTemplateCharacteristicDto> templatePermission = dao.selectByPermissionAndTemplateId(dbSession, request.getPermission(), template.getId());
if (templatePermission.isPresent()) {
RemoveProjectCreatorFromTemplateWsRequest wsRequest = RemoveProjectCreatorFromTemplateWsRequest.builder()
.setPermission(request.mandatoryParam(PARAM_PERMISSION))
.setTemplateId(request.param(PARAM_TEMPLATE_ID))
+ .setOrganization(request.param(PARAM_ORGANIZATION_KEY))
.setTemplateName(request.param(PARAM_TEMPLATE_NAME))
.build();
validateProjectPermission(wsRequest.getPermission());
public class RemoveProjectCreatorFromTemplateWsRequest {
private final String templateId;
+ private final String organization;
private final String templateName;
private final String permission;
private RemoveProjectCreatorFromTemplateWsRequest(Builder builder) {
this.templateId = builder.templateId;
+ this.organization = builder.organization;
this.templateName = builder.templateName;
this.permission = requireNonNull(builder.permission);
}
return templateId;
}
+ @CheckForNull
+ public String getOrganization() {
+ return organization;
+ }
+
@CheckForNull
public String getTemplateName() {
return templateName;
public static class Builder {
private String templateId;
+ private String organization;
private String templateName;
private String permission;
return this;
}
+ public Builder setOrganization(String s) {
+ this.organization = s;
+ return this;
+ }
+
public Builder setTemplateName(String templateName) {
this.templateName = templateName;
return this;