%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Feature" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Feature.FeatureDefinition" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Transcription" %>
<%@ 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 feature definition.", name = "feature/definition/delete")
public static class MyParameters extends Parameters {
@NotNull
@Description(value = "feature code to delete", example = "MyCoolFeature")
public String featureCode = null;
@Description(value = "if this feature is scoped local to the creator of the feature", example = "true", defaultValue = "false")
public Boolean isUserFeature = true;
@Description(value = "feature is owned by this user", example = "joe")
public String userName = null;
protected void afterLoad() {
featureCode = Transcription.assureUnicode(featureCode);
// right now, only VMR Administrators can change features owned by other users
// TODO: allow site admins to change site member group features
if (userName != null && (getUser() == null || !getUser().hasRole("VMR Administrator"))) {
userName = getUser() == null ? null : getUser().getUserName();
}
if (userName == null) userName = getUser() != null ? getUser().getUserName() : null;
if (isUserFeature && featureCode!= null && userName != null && !featureCode.startsWith(userName + "-")) {
featureCode = userName + "-" + featureCode;
}
else userName = null;
}
@Override
protected void customValidation() {
if (getUser() == null) {
addError(-5, "Must be logged in to delete feature definitions.");
return;
}
}
}
%>
<%
MyParameters params = new MyParameters().loadFromRequest(request, response, false);
if (params.getErrors().size() == 0) {
boolean privileged = params.getUser().hasRole("VMR Administrator");
FeatureDefinition featureDefinition = null;
featureDefinition = Feature.getFeatureDefinitions(params.userName).get(params.featureCode);
// more error checks. These are returned in requested format
if (featureDefinition == null) {
params.addError(-6, "No feature definition found with code: "+params.featureCode+".");
}
else if (!params.isUserFeature && !privileged) {
params.addError(-7, "No permission to delete global feature definitions. Must be a VMR Administrator.");
}
else if ((params.userName == null || !params.userName.equals(featureDefinition.userID)) && !privileged) {
params.addError(-8, "No permission to delete feature definitions of other users. Must be a VMR Administrator.");
}
// success, let's delete
else {
Feature.deleteFeatureDefinition(params.featureCode, params.userName);
Serializer.output(response, out, params, XMLBlock.createXMLBlock(""));
return;
}
}
else params.format = "html";
Serializer.reportErrors(request, response, out, params, true);
%>