NIHVIVO-155 Put fake self-edit testing form on a regular site page with header, footer, theme, etc.

This commit is contained in:
rjy7 2010-03-09 20:30:34 +00:00
parent 89919ccb2f
commit 7cbbd2eafd
3 changed files with 131 additions and 49 deletions

View file

@ -258,6 +258,15 @@
<url-pattern>/about</url-pattern> <url-pattern>/about</url-pattern>
</servlet-mapping> </servlet-mapping>
<servlet>
<servlet-name>FakeSelfEditController</servlet-name>
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.FakeSelfEditController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FakeSelfEditController</servlet-name>
<url-pattern>/admin/fakeselfedit</url-pattern>
</servlet-mapping>
<servlet> <servlet>
<servlet-name>SiteAdminController</servlet-name> <servlet-name>SiteAdminController</servlet-name>
<servlet-class>edu.cornell.mannlib.vitro.webapp.controller.edit.SiteAdminController</servlet-class> <servlet-class>edu.cornell.mannlib.vitro.webapp.controller.edit.SiteAdminController</servlet-class>

View file

@ -0,0 +1,114 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller;
import java.util.Enumeration;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vedit.beans.LoginFormBean;
//import edu.cornell.mannlib.vedit.controller.BaseEditController;
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.FakeSelfEditingIdentifierFactory;
public class FakeSelfEditController extends VitroHttpServlet {
private static final Log log = LogFactory.getLog(FakeSelfEditController.class.getName());
public void doGet( HttpServletRequest request, HttpServletResponse response )
throws IOException, ServletException {
// if (!checkLoginStatus(request, response)) {
// return;
// }
String redirectUrl = null;
try {
super.doGet(request,response);
VitroRequest vreq = new VitroRequest(request);
HttpSession session = request.getSession(true);
Object obj = vreq.getSession().getAttribute("loginHandler");
LoginFormBean loginHandler = null;
if( obj != null && obj instanceof LoginFormBean )
loginHandler = ((LoginFormBean)obj);
if( loginHandler == null ||
! "authenticated".equalsIgnoreCase(loginHandler.getLoginStatus()) ||
Integer.parseInt(loginHandler.getLoginRole()) <= LoginFormBean.CURATOR ){
session.setAttribute("postLoginRequest",
vreq.getRequestURI()); //+( vreq.getQueryString()!=null?('?' + vreq.getQueryString()):"" ));
redirectUrl=request.getContextPath() + Controllers.LOGIN + "?login=block";
response.sendRedirect(redirectUrl);
return;
}
String netid = null;
String msg = null;
// Form to use netid submitted
if( vreq.getParameter("force") != null ){
VitroRequestPrep.forceToSelfEditing(request);
netid = request.getParameter("netid");
msg = "You are using the netid '" + netid + "' to test self-editing."
; FakeSelfEditingIdentifierFactory.clearFakeIdInSession( session );
FakeSelfEditingIdentifierFactory.putFakeIdInSession( netid , session );
//redirectUrl = request.getContextPath() + "/admin/fakeselfedit" + "?netid=" + netid;
}
else {
// Form to stop using netid submitted
if ( request.getParameter("stopfaking") != null){
VitroRequestPrep.forceOutOfSelfEditing(request);
FakeSelfEditingIdentifierFactory.clearFakeIdInSession( session );
}
netid = (String)session.getAttribute(FakeSelfEditingIdentifierFactory.FAKE_SELF_EDIT_NETID);
msg = "You have not configured a netid to test self-editing.";
if( netid != null ) {
msg = "You are testing self-editing as '" + netid + "'.";
//redirectUrl = request.getContextPath() + "/admin/fakeselfedit" + "?netid=" + netid;
}
else {
netid = "";
}
}
if (redirectUrl != null) {
response.sendRedirect(redirectUrl);
return;
}
request.setAttribute("msg", msg);
request.setAttribute("netid", netid);
request.setAttribute("title", "Self-Edit Test");
request.setAttribute("bodyJsp", "/admin/fakeselfedit.jsp");
RequestDispatcher rd =
request.getRequestDispatcher(Controllers.BASIC_JSP);
rd.forward(request, response);
} catch (Throwable e) {
log.error("FakeSelfEditController could not forward to view.");
log.error(e.getMessage());
log.error(e.getStackTrace());
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}

View file

@ -1,62 +1,21 @@
<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> <%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%>
<%@ page import="edu.cornell.mannlib.vedit.beans.LoginFormBean" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.filters.VitroRequestPrep" %>
<%@ page import="java.util.Enumeration" %>
<%@ page import="edu.cornell.mannlib.vitro.webapp.auth.identifier.FakeSelfEditingIdentifierFactory" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<% <div id="content">
if(session == null || !LoginFormBean.loggedIn(request, LoginFormBean.CURATOR)) {
%><c:redirect url="<%= Controllers.LOGIN %>" /><%
}
if( request.getParameter("force") != null ){
VitroRequestPrep.forceToSelfEditing(request);
String netid = request.getParameter("netid");
FakeSelfEditingIdentifierFactory.clearFakeIdInSession( session );
FakeSelfEditingIdentifierFactory.putFakeIdInSession( netid , session );%>
<c:redirect url="/entity">
<c:param name="netid" value="<%=netid%>" />
</c:redirect>
<% }
if( request.getParameter("stopfaking") != null){
VitroRequestPrep.forceOutOfSelfEditing(request);
FakeSelfEditingIdentifierFactory.clearFakeIdInSession( session );
}
String netid = (String)session.getAttribute(FakeSelfEditingIdentifierFactory.FAKE_SELF_EDIT_NETID);
String msg = "You have not configured a netid for testing self-editing. ";
if( netid != null ) {
msg = "You have are testing self-editing as '" + netid + "'.";%>
<c:redirect url="/entity">
<c:param name="netid" value="<%=netid%>"/>
</c:redirect>
<% } else {
netid = "";
}
%>
<html>
<title>Test Self-Edit</title>
<body>
<h2>Configure Self-Edit Testing</h2> <h2>Configure Self-Edit Testing</h2>
<p><%=msg %></p> <p>${msg}</p>
<form action="<c:url value="fakeselfedit.jsp"/>" > <form action="<c:url value="/admin/fakeselfedit"/>" >
<input type="text" name="netid" value="<%= netid %>"/> <input type="text" name="netid" value="${netid}"/>
<input type="hidden" name="force" value="1"/> <input type="hidden" name="force" value="1"/>
<input type="submit" value="use a netid for testing"/> <input type="submit" value="use this netid for testing"/>
</form> </form>
<p/>
<form action="<c:url value="fakeselfedit.jsp"/>" > <form action="<c:url value="fakeselfedit"/>" >
<input type="hidden" name="stopfaking" value="1"/> <input type="hidden" name="stopfaking" value="1"/>
<input type="submit" value="stop usng netid for testing"/> <input type="submit" value="stop using netid for testing"/>
</form> </form>
</body> </div> <!-- content -->
</html>