%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page import="org.crosswire.utils.Sessions" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Regularization.RegularizationRule" %>
<%@ page import="org.crosswire.xml.XMLBlock" %>
<%@ page import="org.crosswire.webtools.annotation.*" %>
<%@ page import="org.crosswire.webtools.*" %>
<%@ page import="javax.validation.constraints.NotNull" %>
<%!
@Description(value = "Delete a regulzation rule.", name = "regularization/delete")
public static class MyParameters extends Parameters {
@NotNull
@Description(value = "regularization id to delete", example = "2")
public Integer regID = null;
@Override
protected void customValidation() {
if (getUser() == null) {
addError(-5, "Must be logged in to delete a regularization rule.");
return;
}
}
}
%>
<%
MyParameters params = new MyParameters().loadFromRequest(request, response, false);
if (params.getErrors().size() == 0) {
String role = "VMR Administrator";
boolean admin = params.getUser().hasRole(role);
RegularizationRule reg = RegularizationRule.getRegularizationRule(params.regID);
if (reg == null) {
params.addError(-5, "regID: " + params.regID + " not found.");
}
/* TODO add permission here for site admins and managing editors
else if (!admin && !params.getUser().getUserName().equals(reg.getUserID())) {
params.addError(-7, "User does not have role: " + role + ". Cannot delete another user's regularization rule.");
}
*/
else {
RegularizationRule.deleteRegularizationRule(params.regID);
Serializer.output(response, out, params, XMLBlock.createXMLBlock(""));
return;
}
}
else params.format = "html";
Serializer.reportErrors(request, response, out, params, true);
%>