implemented SIG membership control, Delete SIG, and the "shell" for the

System Administration menu; also added "Post & Go Topics" as an option for the
post box in conferencing
This commit is contained in:
Eric J. Bowersox
2001-02-23 07:49:42 +00:00
parent e23de5dae6
commit 680b84b9d8
33 changed files with 1517 additions and 31 deletions

View File

@@ -109,9 +109,11 @@ public class PostMessage extends VeniceServlet
request.getParameter("next"),getPostNumber(request,on_error),
yes.equals(request.getParameter("attach")));
if (isImageButtonClicked(request,"post") || isImageButtonClicked(request,"postnext"))
if ( isImageButtonClicked(request,"post") || isImageButtonClicked(request,"postnext")
|| isImageButtonClicked(request,"posttopics"))
{ // post the message, and then either go back to the same topic or on to the next one
boolean go_next = isImageButtonClicked(request,"postnext");
boolean go_topics = isImageButtonClicked(request,"posttopics");
int pn = getPostNumber(request,on_error);
try
@@ -124,6 +126,9 @@ public class PostMessage extends VeniceServlet
// post the darn thing!
TopicMessageContext msg = topic.postNewMessage(0,request.getParameter("pseud"),raw_postdata);
if (go_topics) // jump back to the topic list, puhleaze
throw new RedirectResult("confdisp?sig=" + sig.getSIGID() + "&conf=" + conf.getConfID());
short next;
try
{ // attempt to get the value of the "next topic" parameter

View File

@@ -18,6 +18,7 @@
package com.silverwrist.venice.servlets;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.log4j.*;
@@ -33,6 +34,9 @@ public class SIGAdmin extends VeniceServlet
*--------------------------------------------------------------------------------
*/
private static final String DELETE_CONFIRM_ATTR = "servlets.SIGAdmin.delete.confirm";
private static final String DELETE_CONFIRM_PARAM = "confirm";
private static Category logger = Category.getInstance(SIGAdmin.class.getName());
/*--------------------------------------------------------------------------------
@@ -94,7 +98,7 @@ public class SIGAdmin extends VeniceServlet
protected VeniceContent doVeniceGet(HttpServletRequest request, VeniceEngine engine,
UserContext user, RenderData rdat)
throws ServletException, IOException, VeniceServletResult
throws ServletException, IOException, VeniceServletResult
{
// get the SIG context
SIGContext sig = getSIGParameter(request,user,true,"top");
@@ -224,6 +228,76 @@ public class SIGAdmin extends VeniceServlet
} // end if ("T" command)
if (cmd.equals("M"))
{ // "M" = Set Membership
if (!(sig.canModifyProfile()))
{ // no access - sorry man
logger.error("tried to call up membership set screen without access...naughty naughty!");
return new ErrorBox("Unauthorized","You do not have access to modify this SIG's membership.",on_error);
} // end else
try
{ // display the conference member list!
SIGMembership m = new SIGMembership(engine,sig);
m.doSIGMemberList();
setMyLocation(request,"sigadmin?sig=" + sig.getSIGID() + "&cmd=M");
return m;
} // end try
catch (DataException de)
{ // something wrong in the database
return new ErrorBox("Database Error","Database error listing SIG members: " + de.getMessage(),
on_error);
} // end catch
} // end if ("M" command)
if (cmd.equals("DEL"))
{ // "DEL" = "Delete SIG" (requires a confirmation)
if (!(sig.canDelete()))
{ // we can't delete the SIG, so what are we doing here?
logger.error("you can't delete the SIG - not gonna do it, wouldn't be prudent");
return new ErrorBox("Access Error","You do not have permission to delete this SIG.",on_error);
} // end if
if (ConfirmBox.isConfirmed(request,DELETE_CONFIRM_ATTR,DELETE_CONFIRM_PARAM))
{ // we are confirmed - delete the SIG!
try
{ // delete the SIG!
sig.delete();
} // end try
catch (DataException de)
{ // something wrong in the database
logger.error("Database error deleting SIG: " + de.getMessage(),de);
return new ErrorBox("Database Error","Database error deleting SIG: " + de.getMessage(),on_error);
} // end catch
catch (AccessError ae)
{ // access error changing the SIG values
logger.error("Access error deleting SIG: " + ae.getMessage(),ae);
return new ErrorBox("Access Error",ae.getMessage(),on_error);
} // end catch
// the SIG is now GONE - there's noplace else to go but back to the Top page
throw new RedirectResult("top");
} // end if
else
{ // throw up a confirm box to let the user think it over
String message = "You are about to permanently delete the \"" + sig.getName() + "\" SIG, including "
+ "all conferences and other resources it contains! Are you sure you want to do this?";
return new ConfirmBox(request,DELETE_CONFIRM_ATTR,DELETE_CONFIRM_PARAM,"Delete Conference",message,
on_error + "&cmd=DEL",on_error);
} // end else
} // end if ("DEL" command)
// all unknown requests get turned into menu display requests
if (!(sig.canAdministerSIG()))
{ // no access - sorry buddy
@@ -316,6 +390,149 @@ public class SIGAdmin extends VeniceServlet
} // end if ("P" command)
if (cmd.equals("M"))
{ // "M" = Modify SIG Membership
on_error += "&cmd=M";
setMyLocation(request,on_error);
if (!(sig.canModifyProfile()))
{ // no access - sorry, dude
logger.error("tried to call up SIG membership screen without access...naughty naughty!");
return new ErrorBox("Unauthorized","You do not have access to modify this SIG's membership.",on_error);
} // end if
if (isImageButtonClicked(request,"update"))
{ // the "update" command that changes all the security levels
HashMap org_vals = new HashMap();
HashMap new_vals = new HashMap();
try
{ // retrieve all parameters and filter them for the levels
Enumeration p_names = request.getParameterNames();
while (p_names.hasMoreElements())
{ // examine each parameter name in turn
String p_name = (String)(p_names.nextElement());
if (p_name.startsWith("zxcur_"))
{ // this is a current value (from a hidden field)
int uid = Integer.parseInt(p_name.substring(6));
int level = Integer.parseInt(request.getParameter(p_name));
org_vals.put(new Integer(uid),new Integer(level));
} // end if
else if (p_name.startsWith("zxnew_"))
{ // this is a new value (from a dropdown list box)
int uid = Integer.parseInt(p_name.substring(6));
int level = Integer.parseInt(request.getParameter(p_name));
new_vals.put(new Integer(uid),new Integer(level));
} // end else if
} // end while
if (org_vals.size()!=new_vals.size())
{ // we read the wrong number of parameters - this is bad
logger.error("level parameters mismatch (" + org_vals.size() + " old, " + new_vals.size()
+ " new)");
return new ErrorBox(null,"Invalid parameters.",on_error);
} // end if
} // end try
catch (NumberFormatException nfe)
{ // error converting the parameters
logger.error("got number format exception parsing a level parameter");
return new ErrorBox(null,"Invalid parameter conversion.",on_error);
} // end catch
try
{ // loop through the hashmaps and set the value
Iterator it = org_vals.keySet().iterator();
while (it.hasNext())
{ // extract the UID, old level, and new level
Integer uid = (Integer)(it.next());
Integer org_level = (Integer)(org_vals.get(uid));
Integer new_level = (Integer)(new_vals.get(uid));
if (new_level==null)
{ // whoops
logger.error("new SIG level not found for uid " + uid.intValue());
return new ErrorBox(null,"Invalid new level parameter.",on_error);
} // end if
int new_level_x = new_level.intValue();
if (new_level_x==0)
new_level_x = -1;
// call down to set the membership level
if (org_level.intValue()!=new_level_x)
{ // we need to reset the SIG membership
if (logger.isDebugEnabled())
logger.debug("resetting SIG member level for uid " + uid.intValue() + "(old = "
+ org_level.intValue() + ", new = " + new_level_x + ")");
sig.setMembership(uid.intValue(),new_level_x);
} // end if
} // end while
} // end try
catch (AccessError ae)
{ // some sort of access error - display an error dialog
logger.error("AccessError on sig.setMembership: " + ae.getMessage(),ae);
return new ErrorBox("Access Error",ae.getMessage(),on_error);
} // end catch
catch (DataException de)
{ // database error creating the conference
logger.error("DataException on sig.setMembership: " + de.getMessage(),de);
return new ErrorBox("Database Error","Database error setting memberships: " + de.getMessage(),
on_error);
} // end catch
// trap back to the SIG membership display
throw new RedirectResult(on_error);
} // end if ("update" clicked)
if ( isImageButtonClicked(request,"search") || isImageButtonClicked(request,"previous")
|| isImageButtonClicked(request,"next"))
{ // create the new dialog box
SIGMembership m = new SIGMembership(engine,sig);
try
{ // perform the search!
m.doSearch(request);
} // end try
catch (ValidationException ve)
{ // validation error - throw it back to the user
return new ErrorBox(null,ve.getMessage() + " Please try again.",on_error);
} // end catch
catch (AccessError ae)
{ // some sort of access error - display an error dialog
return new ErrorBox("Access Error",ae.getMessage(),on_error);
} // end catch
catch (DataException de)
{ // database error creating the conference
return new ErrorBox("Database Error","Database error searching for users: " + de.getMessage(),
on_error);
} // end catch
return m;
} // end if (search function clicked)
// we don't know what button was pressed
logger.error("no known button click on SIGAdmin.doPost, cmd=M");
return new ErrorBox("Internal Error","Unknown command button pressed",on_error);
} // end if ("M" command)
// on unknown command, redirect to the GET function
return doVeniceGet(request,engine,user,rdat);

View File

@@ -0,0 +1,95 @@
/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.servlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.log4j.*;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.servlets.format.*;
public class SystemAdmin extends VeniceServlet
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
private static Category logger = Category.getInstance(SIGAdmin.class.getName());
/*--------------------------------------------------------------------------------
* Internal functions
*--------------------------------------------------------------------------------
*/
private SystemAdminTop makeSystemAdminTop() throws ServletException
{
final String desired_name = "SystemAdminTop";
MenuPanelCache cache = MenuPanelCache.getMenuPanelCache(getServletContext());
if (!(cache.isCached(desired_name)))
{ // create a template and save it off
SystemAdminTop template = new SystemAdminTop();
cache.saveTemplate(template);
} // end if
// return a new copy
return (SystemAdminTop)(cache.getNewMenuPanel(desired_name));
} // end makeSystemAdminTop
/*--------------------------------------------------------------------------------
* Overrides from class HttpServlet
*--------------------------------------------------------------------------------
*/
public String getServletInfo()
{
String rc = "SystemAdmin servlet - Administrative functions for the entire system\n"
+ "Part of the Venice Web Communities System\n";
return rc;
} // end getServletInfo
/*--------------------------------------------------------------------------------
* Overrides from class VeniceServlet
*--------------------------------------------------------------------------------
*/
protected VeniceContent doVeniceGet(HttpServletRequest request, VeniceEngine engine,
UserContext user, RenderData rdat)
throws ServletException, IOException, VeniceServletResult
{
// decide what to do based on the "cmd" parameter
String cmd = getStandardCommandParam(request);
if (logger.isDebugEnabled())
logger.debug("SystemAdmin/doGet command value = " + cmd);
// TODO: command handling
if (!(user.hasAdminAccess()))
return new ErrorBox("Access Error","You do not have permission to administer the system.",null);
setMyLocation(request,"sysadmin");
return makeSystemAdminTop();
} // end doVeniceGet
} // end class SystemAdmin

View File

@@ -21,6 +21,7 @@ import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.ValidationException;
import com.silverwrist.venice.security.Role;
import com.silverwrist.venice.core.*;
@@ -326,7 +327,7 @@ public class ConferenceMembership implements JSPRender, SearchMode
out.write("<OPTION VALUE=\"" + r.getLevel() + "\"");
if (r.getLevel()==cur_level)
out.write(" SELECTED");
out.write(">" + r.getName() + "</OPTION>\n");
out.write(">" + StringUtil.encodeHTML(r.getName()) + "</OPTION>\n");
} // end while

View File

@@ -7,7 +7,7 @@
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Community System.
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are

View File

@@ -7,7 +7,7 @@
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Community System.
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are

View File

@@ -0,0 +1,333 @@
/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.servlets.format;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.ValidationException;
import com.silverwrist.venice.security.Role;
import com.silverwrist.venice.core.*;
public class SIGMembership implements JSPRender, SearchMode
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
// Attribute name for request attribute
protected static final String ATTR_NAME = "com.silverwrist.venice.content.ConferenceMembership";
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private VeniceEngine engine; // reference to the engine
private SIGContext sig; // the SIG we're in
private List display_list = null; // list of members to display
private boolean sig_members = false; // is this a list of SIG members?
private int field = -1; // search field
private int mode = -1; // search mode
private String term = null; // search term
private int offset = 0; // search result offset
private int find_count = -1; // search results count
private List role_choices; // the list of security roles
private Role role_sig_host; // the "SIG Host" security role
/*--------------------------------------------------------------------------------
* Constructors
*--------------------------------------------------------------------------------
*/
public SIGMembership(VeniceEngine engine, SIGContext sig)
{
this.engine = engine;
this.sig = sig;
this.role_choices = Role.getSIGMemberLevelChoices();
this.role_sig_host = Role.getSIGHostRole();
} // end constructor
/*--------------------------------------------------------------------------------
* Internal functions
*--------------------------------------------------------------------------------
*/
private static int getParamInt(ServletRequest request, String name, int default_val)
{
String str = request.getParameter(name);
if (str==null)
return -1;
try
{ // parse the integer value
return Integer.parseInt(str);
} // end try
catch (NumberFormatException nfe)
{ // in case of conversion error, return default
return default_val;
} // end catch
} // end getParamInt
private static boolean isImageButtonClicked(ServletRequest request, String name)
{
String val = request.getParameter(name + ".x");
return (val!=null);
} // end isImageButtonClicked
/*--------------------------------------------------------------------------------
* External static functions
*--------------------------------------------------------------------------------
*/
public static SIGMembership retrieve(ServletRequest request)
{
return (SIGMembership)(request.getAttribute(ATTR_NAME));
} // end retrieve
/*--------------------------------------------------------------------------------
* Implementations from interface VeniceContent
*--------------------------------------------------------------------------------
*/
public String getPageTitle(RenderData rdat)
{
return "Membership in SIG " + sig.getName();
} // end getPageTitle
/*--------------------------------------------------------------------------------
* Implementations from interface JSPRender
*--------------------------------------------------------------------------------
*/
public void store(ServletRequest request)
{
request.setAttribute(ATTR_NAME,this);
} // end store
public String getTargetJSPName()
{
return "sig_member.jsp";
} // end getTargetJSPName
/*--------------------------------------------------------------------------------
* External operations
*--------------------------------------------------------------------------------
*/
public void doSIGMemberList() throws DataException
{
this.display_list = sig.getMemberList();
this.sig_members = true;
this.term = "";
} // end doSIGMemberList
public void doSearch(ServletRequest request) throws ValidationException, DataException, AccessError
{
// Validate the search field parameter.
field = getParamInt(request,"field",FIELD_USER_NAME);
if ( (field!=FIELD_USER_NAME) && (field!=FIELD_USER_DESCRIPTION) && (field!=FIELD_USER_GIVEN_NAME)
&& (field!=FIELD_USER_FAMILY_NAME))
throw new ValidationException("The field search parameter is not valid.");
// Validate the search mode parameter.
mode = getParamInt(request,"mode",SEARCH_PREFIX);
if ((mode!=SEARCH_PREFIX) && (mode!=SEARCH_SUBSTRING) && (mode!=SEARCH_REGEXP))
throw new ValidationException("The search mode parameter is not valid.");
// Retrieve the search term parameter.
term = request.getParameter("term");
if (term==null)
term = "";
// Retrieve the offset and find count parameters.
offset = getParamInt(request,"ofs",0);
find_count = getParamInt(request,"fcount",-1);
// Adjust the search return offset based on the command button click.
int count = getNumResultsDisplayed();
if (isImageButtonClicked(request,"search"))
offset = 0;
else if (isImageButtonClicked(request,"previous"))
{ // adjust the offset in the reverse direction
offset -= count;
if (offset<0)
offset = 0;
} // end else if
else if (isImageButtonClicked(request,"next"))
offset += count; // go forwards instead
else
throw new ValidationException("Unable to determine what action triggered the form.");
// Perform the search!
List intermediate = engine.searchForUsers(field,mode,term,offset,count);
if (find_count<0)
find_count = engine.getSearchUserCount(field,mode,term);
// Create the real display list by getting the SIG security levels.
Iterator it = intermediate.iterator();
Vector rc = new Vector(count+1);
while (it.hasNext())
{ // loop around and find the member level of every one
UserFound uf = (UserFound)(it.next());
int new_level = sig.getMemberLevel(uf.getUID());
if (new_level==-1)
new_level = 0;
rc.add(uf.createNewLevel(new_level));
} // end while
display_list = rc; // save display list for display
} // end doSearch
public int getSIGID()
{
return sig.getSIGID();
} // end getSIGID
public String getSIGName()
{
return sig.getName();
} // end getSIGName
public String getLocator()
{
return "sig=" + sig.getSIGID();
} // end getLocator
public boolean displayList()
{
if ((display_list==null) || (display_list.size()==0))
return false;
if (sig_members && (display_list.size()>engine.getMaxNumSIGMembersDisplay()))
return false;
return true;
} // end displayList
public boolean isSIGMemberList()
{
return sig_members;
} // end isSIGMemberList
public int getSearchField()
{
return field;
} // end getSearchField
public int getSearchMode()
{
return mode;
} // end getSearchMode
public boolean searchFieldIs(int value)
{
return (field==value);
} // end searchFieldIs
public boolean searchModeIs(int value)
{
return (mode==value);
} // end searchModeIs
public String getSearchTerm()
{
return term;
} // end getSearchTerm
public int getFindCount()
{
return find_count;
} // end getFindCount
public int getOffset()
{
return offset;
} // end getOffset
public int getSize()
{
return display_list.size();
} // end getSize
public int getNumResultsDisplayed()
{
return engine.getStdNumSearchResults();
} // end getNumResultsDisplayed
public UserFound getItem(int ndx)
{
return (UserFound)(display_list.get(ndx));
} // end getItem
public void outputDropDown(Writer out, int uid, int cur_level) throws IOException
{
out.write("<INPUT TYPE=HIDDEN NAME=\"zxcur_" + uid + "\" VALUE=\"" + cur_level + "\">\n");
out.write("<SELECT NAME=\"zxnew_" + uid + "\" SIZE=1>\n");
if (cur_level==role_sig_host.getLevel()) // cheat and put in just the host level
out.write("<OPTION VALUE=\"" + role_sig_host.getLevel() + "\" SELECTED>"
+ StringUtil.encodeHTML(role_sig_host.getName()) + "</OPTION>\n");
else
{ // display all the level choices properly
Iterator it = role_choices.iterator();
while (it.hasNext())
{ // output the <OPTION> lines for the dropdown
Role r = (Role)(it.next());
out.write("<OPTION VALUE=\"" + r.getLevel() + "\"");
if (r.getLevel()==cur_level)
out.write(" SELECTED");
out.write(">" + StringUtil.encodeHTML(r.getName()) + "</OPTION>\n");
} // end while
} // end else
out.write("</SELECT>\n");
} // end outputDropDown
} // end class SIGMembership

View File

@@ -0,0 +1,57 @@
/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.servlets.format;
import java.util.*;
import java.io.Writer;
import java.io.IOException;
public class SystemAdminTop extends ContentMenuPanel
{
/*--------------------------------------------------------------------------------
* Constructors
*--------------------------------------------------------------------------------
*/
public SystemAdminTop()
{
super("System Administration",null);
addChoice("Set Global Parameters","TODO");
addChoice("View/Edit Banned Users","TODO");
addChoice("User Account Management","TODO");
} // end constructor
protected SystemAdminTop(SystemAdminTop other)
{
super(other);
} // end constructor
/*--------------------------------------------------------------------------------
* External operations
*--------------------------------------------------------------------------------
*/
public Object clone()
{
return new SystemAdminTop(this);
} // end clone
} // end class SystemAdminTop