head     1.1;
branch   1.1.1;
access   ;
symbols  NEWHELM:1.1.1.1 TIGRIS_NOV_12_2000:1.1.1;
locks    ; strict;
comment  @# @;


1.1
date     2000.11.12.21.16.12;  author dlr;  state Exp;
branches 1.1.1.1;
next     ;

1.1.1.1
date     2000.11.12.21.16.12;  author dlr;  state Exp;
branches ;
next     ;


desc
@@



1.1
log
@Initial revision
@
text
@/* ================================================================
 * Copyright (c) 2000 CollabNet.  All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * 
 * 3. The end-user documentation included with the redistribution, if
 * any, must include the following acknowlegement: "This product includes
 * software developed by CollabNet (http://www.Collab.Net/)."
 * Alternately, this acknowlegement may appear in the software itself, if
 * and wherever such third-party acknowlegements normally appear.
 * 
 * 4. The hosted project names must not be used to endorse or promote
 * products derived from this software without prior written
 * permission. For written permission, please contact info@@collab.net.
 * 
 * 5. Products derived from this software may not use the "Tigris" name
 * nor may "Tigris" appear in their names without prior written
 * permission of CollabNet.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * ====================================================================
 * 
 * This software consists of voluntary contributions made by many
 * individuals on behalf of CollabNet.
 */

package org.tigris.helm.project;

import org.webmacro.servlet.*;
import org.webmacro.util.*;

//import java.util.*;

import com.workingdogs.village.*;

import java.util.Enumeration;
import java.util.Vector;
import java.util.StringTokenizer;
import java.sql.*;
import javax.servlet.http.*;

import org.tigris.helm.security.HelmServlet;
import org.tigris.helm.security.AccessControlList;

import org.tigris.helm.domain.User;
import org.tigris.helm.domain.User;
import org.tigris.helm.database.UserRoleProjectManager;

import org.joist.database.RoleManager;
import org.joist.database.DataManager;
import org.joist.database.UserManager;
import org.tigris.helm.database.ProjectManager;

import org.joist.security.RedirectException;
import org.joist.mail.Emailer;

/**
 * Display a summary of users who belong to this project.
 */

public class ProjectMembers extends org.tigris.helm.security.HelmServlet
{
  static private Log log = new Log ("prjMbs", "ProjectMembers");
  static private boolean debug = true;

  protected String processRequest (Connection connection, WebContext context)
    throws HandlerException, RedirectException
  {
    String templateName = super.processRequest (connection, context);
    Project project = (Project) context.get ("currentProject");
    HttpServletRequest request = context.getRequest ();
    Enumeration paramNames = request.getParameterNames ();
    String paramName;
    Vector newSet = new Vector (50);

    UserRoleProjectManager urpMgr = (UserRoleProjectManager)
      dMgr.getManager ("org.tigris.helm.database.UserRoleProjectManager");
    ProjectManager pMgr = (ProjectManager)
      dMgr.getManager ("org.tigris.helm.database.ProjectManager");
    UserManager uMgr = (UserManager)
      dMgr.getManager ("org.joist.database.UserManager");
    RoleManager rMgr = (RoleManager)
      dMgr.getManager ("org.joist.database.RoleManager");

    String action = (String) context.get ("action");

      try
    {

      String loginUserID = super.getLoginUser (context).getUserID ();
      if (debug)
	  log.debug ("loginID=" + loginUserID);

      if (action.equals ("Revoke Checked Roles"))
      {
	while (paramNames.hasMoreElements ())
	{
	  paramName = (String) paramNames.nextElement ();
	  if (paramName.startsWith ("Revoke"))
	    newSet.addElement (paramName);
	}
	if (debug)
	    log.debug ("checked: " + newSet.toString ());

	for (int i = 0; i < newSet.size (); i++)
	{
	  String element = (String) newSet.elementAt (i);
	  StringTokenizer tok = new StringTokenizer (element);
	    tok.nextToken ();
	  String user = tok.nextToken ();
	  String role = tok.nextToken ();
	    urpMgr.revoke (connection, user, role, project.getID ());
	}

      }
      else if (action.equals ("Perform Actions"))
      {

	Vector values = new Vector ();

	while (paramNames.hasMoreElements ())
	{
	  paramName = (String) paramNames.nextElement ();
	  if (paramName.startsWith ("Pending"))
	  {
	    newSet.addElement (paramName);
	    values.addElement (context.getForm (paramName));
	  }
	}
	if (debug)
	  log.debug ("checked: " + newSet.toString ());

	Emailer emailer = new Emailer ();

	for (int i = 0; i < newSet.size (); i++)
	{
	  String element = (String) newSet.elementAt (i);
	  StringTokenizer tok = new StringTokenizer (element);
	  tok.nextToken ();
	  String user = tok.nextToken ();
	  String role = tok.nextToken ();
	  String value = (String) values.elementAt (i);
	  String email = uMgr.getUserEmail (connection, user);
	  String roleName = rMgr.getRoleName (connection, role);
	  String projectName =
	    pMgr.getProjectName (connection, project.getID ());
	  StringBuffer messageBuf =
	    new StringBuffer ("You requested the role of ");
	  messageBuf.append (roleName).append (" on project '").
	    append (projectName).append ("'. ");
	  String subject;
	  String message;

	  if (debug)
	    log.debug (value + " role " + role + " for  user " + user);

	  if (value.equals ("Approve"))
	  {
	    urpMgr.updateField (connection, project.getID (),
				user, role, "approved_by", loginUserID);
	    subject = "Requested role on sourceCast has been granted";
	    messageBuf.append ("Congratulations! The role has been granted.");
	    message = messageBuf.toString ();
	    //emailer.sendEmail(email, subject, message);
	  }
	  else if (value.equals ("Disapprove"))
	  {
	    urpMgr.revoke (connection, user, role, project.getID ());
	    subject = "Requested role on sourceCast has not been granted";
	    messageBuf.
	      append
	      ("We regret to inform you that the role has not been granted.");
	    message = messageBuf.toString ();
	    //emailer.sendEmail(email, subject, message);
	  }
	}
      }
    }
    catch (Exception e)
    {
      log.exception (e);
      String message = "ProjectMembers: " + e.getMessage ();
      if (debug)
	log.debug (message);
      context.put ("message", message);
    }

    return templateName;
  }

}				/* end class ProjectMembers */
@


1.1.1.1
log
@Merging newhelm tree into helm, as per IZ issue #557.  Previous major version of helm is tagged TIGRIS_NOV_11_2000.
@
text
@@
