[Rapforums-developer] src/source/edu/fullcoll/uportal/channels/rap/forum/commands AdminModeCommand.j
Status: Beta
Brought to you by:
brippe
|
From: Brad R. <br...@us...> - 2004-07-21 17:14:54
|
Update of /cvsroot/rapforums/src/source/edu/fullcoll/uportal/channels/rap/forum/commands In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5009 Modified Files: AdminModeCommand.java Log Message: no message Index: AdminModeCommand.java =================================================================== RCS file: /cvsroot/rapforums/src/source/edu/fullcoll/uportal/channels/rap/forum/commands/AdminModeCommand.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AdminModeCommand.java 26 Jan 2004 18:49:27 -0000 1.3 --- AdminModeCommand.java 21 Jul 2004 17:14:45 -0000 1.4 *************** *** 23,32 **** package edu.fullcoll.uportal.channels.rap.forum.commands; - import org.jasig.portal.ChannelRuntimeData; import org.jasig.portal.utils.XSLT; import org.xml.sax.ContentHandler; import org.jasig.portal.PortalException; - import org.jasig.portal.groups.IEntityGroup; import org.jasig.portal.groups.IGroupMember; import org.jasig.portal.services.GroupService; import org.jasig.portal.services.LogService; --- 23,32 ---- package edu.fullcoll.uportal.channels.rap.forum.commands; import org.jasig.portal.utils.XSLT; import org.xml.sax.ContentHandler; import org.jasig.portal.PortalException; import org.jasig.portal.groups.IGroupMember; + import org.jasig.portal.security.IAuthorizationPrincipal; + import org.jasig.portal.security.IPermission; import org.jasig.portal.services.GroupService; import org.jasig.portal.services.LogService; *************** *** 40,50 **** import edu.fullcoll.uportal.channels.rap.forum.xml.RAPViewXML; import edu.fullcoll.uportal.channels.rap.forum.xml.ViewXMLFactory; - import org.jdom.Document; - import org.jdom.Element; import org.jdom.output.XMLOutputter; import java.io.StringWriter; ! import java.io.OutputStream; ! import edu.fullcoll.uportal.channels.rap.forum.database.RAPDBException; /** --- 40,49 ---- import edu.fullcoll.uportal.channels.rap.forum.xml.RAPViewXML; import edu.fullcoll.uportal.channels.rap.forum.xml.ViewXMLFactory; + import edu.fullcoll.uportal.channels.rap.forum.database.RAPDBException; + import edu.fullcoll.uportal.channels.rap.forum.ForumSessionData; import org.jdom.output.XMLOutputter; import java.io.StringWriter; ! /** *************** *** 62,66 **** * @param out - the output object for sending user responses */ ! public void execute(CForum forum, ContentHandler out) throws PortalException { final int INITITAL_BUFFER_SIZE = 5000; String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; --- 61,65 ---- * @param out - the output object for sending user responses */ ! public void execute(CForum forum, ForumSessionData session, ContentHandler out) throws PortalException { final int INITITAL_BUFFER_SIZE = 5000; String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; *************** *** 70,85 **** try { ! String username = (String) forum.getStaticData().getPerson().getAttribute("displayName"); if(username == null) ! username = (String) forum.getStaticData().getPerson().getAttribute(forum.getStaticData().getPerson().USERNAME); xml += "<rap>"; writer.write("<username>" + username + "</username>"); ! writer.write("<userid>" + forum.getStaticData().getPerson().getAttribute("username") + "</userid>"); ! String type = forum.getRuntimeData().getParameter("type"); //authenticate the user ! int id = forum.getStaticData().getPerson().getID(); ! IGroupMember myGroups = GroupService.getEntity((String) forum.getStaticData().getPerson().getAttribute(forum.getStaticData().getPerson().USERNAME), Class.forName("org.jasig.portal.security.IPerson")); --- 69,84 ---- try { ! String username = (String) (session.staticData).getPerson().getAttribute("displayName"); if(username == null) ! username = (String) (session.staticData).getPerson().getAttribute((session.staticData).getPerson().USERNAME); xml += "<rap>"; writer.write("<username>" + username + "</username>"); ! writer.write("<userid>" + (session.staticData).getPerson().getAttribute("username") + "</userid>"); ! String type = (session.runtimeData).getParameter("type"); //authenticate the user ! int id = (session.staticData).getPerson().getID(); ! IGroupMember myGroups = GroupService.getEntity((String) (session.staticData).getPerson().getAttribute((session.staticData).getPerson().USERNAME), Class.forName("org.jasig.portal.security.IPerson")); *************** *** 99,120 **** if (type.equals("createForum")) { if (isAdmin || isManager) { ! writer.write("<type>createForum</type>"); RAPViewXML viewXML = ViewXMLFactory.createRAPViewXML(); XMLOutputter outputter = new XMLOutputter(); ! outputter.output(viewXML.getCategoryXML().detachRootElement(), writer); } else { writer.write("<type>noAccess</type>"); } ! } else if (type.equals("doForum")) { if (isAdmin || isManager) { //create the forum ! String name = forum.getRuntimeData().getParameter("name"); ! String description = forum.getRuntimeData().getParameter("description"); ! validateInsert(forum, writer, name, description, IDManager.FORUM_TYPE); } else { --- 98,174 ---- if (type.equals("createForum")) { + + IAuthorizationPrincipal ap = session.staticData.getAuthorizationPrincipal(); + IPermission[] perms = ap.getAllPermissions(forum.getOwnerToken(), "Create", (session.runtimeData).getParameter("forum") ); + + for(int i = 0; i < perms.length; i++) { + if(perms[i].getType().equals("GRANT")) { + if (isAdmin || isManager) { + writer.write("<type>createForum</type>"); + RAPViewXML viewXML = ViewXMLFactory.createRAPViewXML(); + XMLOutputter outputter = new XMLOutputter(); + outputter.output(viewXML.getCategoryXML().detachRootElement(), writer); + } else { + writer.write("<type>noAccess</type>"); + } + } else { + // Unauthorized access to post + UnAuthorizedModeCommand command = new UnAuthorizedModeCommand(); + session.unauthorizedMsg = "Sorry, you do not have appropriate permission to create new forums.<br/><br/>"+ + "Please contact your forum administrator for appropriate access.<br/><br/>Thank you!"; + command.execute(forum, session, out); + break; + } + } + + } else if (type.equals("prePerm")) { + IAuthorizationPrincipal ap = session.staticData.getAuthorizationPrincipal(); + IPermission[] perms = ap.getAllPermissions(forum.getOwnerToken(), "Create", (session.runtimeData).getParameter("forum") ); + + for(int i = 0; i < perms.length; i++) { + if(perms[i].getType().equals("GRANT")) { + if (isAdmin || isManager) { + //go to select forum to assign permissions to + //fix xml here + //need to get a list of forum names here to add to the xml + writer.write("<type>prePerm</type>"); + RAPViewXML viewXML = ViewXMLFactory.createRAPViewXML(); + XMLOutputter outputter = new XMLOutputter(); + outputter.output(viewXML.getCategoryXML().detachRootElement(), writer); + RAPDB dbCon = new RAPDB(); + outputter.output(viewXML.getForumsXML(1, dbCon.getForumCount()).detachRootElement(), writer); + } else { + writer.write("<type>noAccess</type>"); + } + } else { + // Unauthorized access to post + UnAuthorizedModeCommand command = new UnAuthorizedModeCommand(); + session.unauthorizedMsg = "Sorry, you do not have appropriate permission to assign permissions to forums.<br/><br/>"+ + "Please contact your forum administrator for appropriate access.<br/><br/>Thank you!"; + command.execute(forum, session, out); + break; + } + } + + } else if (type.equals("adminForum")) { if (isAdmin || isManager) { ! //display main administration view ! writer.write("<type>adminForum</type>"); RAPViewXML viewXML = ViewXMLFactory.createRAPViewXML(); XMLOutputter outputter = new XMLOutputter(); ! outputter.output(viewXML.getCategoryXML().detachRootElement(), writer); } else { writer.write("<type>noAccess</type>"); } ! } else if (type.equals("doForum")) { if (isAdmin || isManager) { //create the forum ! String name = (session.runtimeData).getParameter("name"); ! String description = (session.runtimeData).getParameter("description"); ! validateInsert(forum, writer, name, description, IDManager.FORUM_TYPE, session); } else { *************** *** 124,140 **** } else if (type.equals("deleteForum")) { ! if (isAdmin || isManager) { ! writer.write("<type>deleteForum</type>"); ! //delete forum ! RAPViewXML rapViewXML = ViewXMLFactory.createRAPViewXML(); ! XMLOutputter outputter = new XMLOutputter(); ! outputter.output(rapViewXML.getCategoryXML().detachRootElement(), writer); ! RAPDB dbCon = new RAPDB(); ! outputter.output(rapViewXML.getForumsXML(1, dbCon.getForumCount()).detachRootElement(), writer); ! String name = forum.getRuntimeData().getParameter("name"); ! //validateInsert(forum, writer, name, description, IDManager.FORUM_TYPE); ! } else { ! writer.write("<type>noAccess</type>"); ! } } else if (type.equals("doDeleteForum")) { --- 178,210 ---- } else if (type.equals("deleteForum")) { ! IAuthorizationPrincipal ap = session.staticData.getAuthorizationPrincipal(); ! IPermission[] perms = ap.getAllPermissions(forum.getOwnerToken(), "Delete", (session.runtimeData).getParameter("forum") ); ! ! for(int i = 0; i < perms.length; i++) { ! if(perms[i].getType().equals("GRANT")) { ! ! if (isAdmin || isManager) { ! writer.write("<type>deleteForum</type>"); ! //delete forum ! RAPViewXML rapViewXML = ViewXMLFactory.createRAPViewXML(); ! XMLOutputter outputter = new XMLOutputter(); ! outputter.output(rapViewXML.getCategoryXML().detachRootElement(), writer); ! RAPDB dbCon = new RAPDB(); ! outputter.output(rapViewXML.getForumsXML(1, dbCon.getForumCount()).detachRootElement(), writer); ! String name = (session.runtimeData).getParameter("name"); ! //validateInsert(forum, writer, name, description, IDManager.FORUM_TYPE); ! } else { ! writer.write("<type>noAccess</type>"); ! } ! ! } else { ! // Unauthorized access to post ! UnAuthorizedModeCommand command = new UnAuthorizedModeCommand(); ! session.unauthorizedMsg = "Sorry, you do not have appropriate permission to delete forums.<br/><br/>"+ ! "Please contact your forum administrator for appropriate access.<br/><br/>Thank you!"; ! command.execute(forum, session, out); ! break; ! } ! } } else if (type.equals("doDeleteForum")) { *************** *** 143,148 **** //delete category writer.write("<type>doDeleteForum</type>"); ! String catID = forum.getRuntimeData().getParameter("categoryid"); ! String forumID = forum.getRuntimeData().getParameter("forumid"); if(catID != null && forumID != null) { --- 213,218 ---- //delete category writer.write("<type>doDeleteForum</type>"); ! String catID = (session.runtimeData).getParameter("categoryid"); ! String forumID = (session.runtimeData).getParameter("forumid"); if(catID != null && forumID != null) { *************** *** 172,179 **** if (isAdmin || isManager) { ! String name = forum.getRuntimeData().getParameter("name"); ! String description = forum.getRuntimeData().getParameter("description"); ! validateInsert(forum, writer, name, description, IDManager.CATEGORY_TYPE); } else { --- 242,249 ---- if (isAdmin || isManager) { ! String name = (session.runtimeData).getParameter("name"); ! String description = (session.runtimeData).getParameter("description"); ! validateInsert(forum, writer, name, description, IDManager.CATEGORY_TYPE, session); } else { *************** *** 199,203 **** //delete category writer.write("<type>doDeleteCat</type>"); ! String catID = forum.getRuntimeData().getParameter("categoryid"); if(catID != null) { --- 269,273 ---- //delete category writer.write("<type>doDeleteCat</type>"); ! String catID = (session.runtimeData).getParameter("categoryid"); if(catID != null) { *************** *** 223,233 **** xml += "</rap>"; ! //System.out.println("Admin "+xml); // Transform xml XSLT xslt = new XSLT(forum); xslt.setXML(xml); ! xslt.setXSL("CForum.ssl", stylesheet, forum.getRuntimeData().getBrowserInfo()); ! xslt.setStylesheetParameter("baseActionURL", forum.getRuntimeData().getBaseActionURL()); xslt.setTarget(out); xslt.transform(); --- 293,303 ---- xml += "</rap>"; ! //System.out.println("Admin "+xml); // Transform xml XSLT xslt = new XSLT(forum); xslt.setXML(xml); ! xslt.setXSL("CForum.ssl", stylesheet, (session.runtimeData).getBrowserInfo()); ! xslt.setStylesheetParameter("baseActionURL", (session.runtimeData).getBaseActionURL()); xslt.setTarget(out); xslt.transform(); *************** *** 237,241 **** * Validates description and name, then inserts new category into the database */ ! private void validateInsert(CForum forum, StringWriter writer, String name, String description, int type) throws RAPDBException { String paramType= "createForum"; if(type == IDManager.CATEGORY_TYPE) --- 307,311 ---- * Validates description and name, then inserts new category into the database */ ! private void validateInsert(CForum forum, StringWriter writer, String name, String description, int type, ForumSessionData session) throws RAPDBException { String paramType= "createForum"; if(type == IDManager.CATEGORY_TYPE) *************** *** 262,266 **** writer.write("<type>doForum</type>"); ! int categoryID = Integer.parseInt(forum.getRuntimeData().getParameter("category")); IForum newForum = new RAPForumsManager().createForum(name, description, categoryID); int forumID = newForum.getForumID(); --- 332,336 ---- writer.write("<type>doForum</type>"); ! int categoryID = Integer.parseInt((session.runtimeData).getParameter("category")); IForum newForum = new RAPForumsManager().createForum(name, description, categoryID); int forumID = newForum.getForumID(); |