head	1.7;
access;
symbols
	TIGRIS_1_1_0RC2:1.1
	TIGRIS_1_1_0RC1:1.1
	TIGRIS_1_1:1.1.0.4
	TIGRIS_1_0_8:1.1
	TIGRIS_1_0_8RC3:1.1
	TIGRIS_1_0_8RC2:1.1
	TIGRIS_1_0_8RC1:1.1
	TIGRIS_1_0_7:1.1
	TIGRIS_1_0_7RC3:1.1
	TIGRIS_1_0_7RC2:1.1
	TIGRIS_1_0_7RC1:1.1
	TIGRIS_1_0_6:1.1
	TIGRIS_1_0_6RC5:1.1
	TIGRIS_1_0_6RC4:1.1
	TIGRIS_1_0_6RC3:1.1
	TIGRIS_1_0_6RC2:1.1
	TIGRIS_1_0_6RC1:1.1
	TIGRIS_1_0_5:1.1
	TIGRIS_1_0_5RC6:1.1
	TIGRIS_1_0_5RC5:1.1
	TIGRIS_1_0_5RC4:1.1
	TIGRIS_1_0_5RC3:1.1
	TIGRIS_1_0_5RC2:1.1
	TIGRIS_1_0_5RC1:1.1
	TIGRIS_1_0_4:1.1
	TIGRIS_1_0_3:1.1
	TIGRIS_1_0_2:1.1
	TIGRIS_1_0_1:1.1
	TIGRIS_1_0:1.1.0.6
	TIGRIS_1_0_0:1.1
	TIGRIS_1_0_0_RC1:1.1.0.2;
locks; strict;
comment	@# @;


1.7
date	2001.08.28.00.56.12;	author leonardr;	state Exp;
branches;
next	1.6;

1.6
date	2001.08.11.09.08.01;	author dlr;	state Exp;
branches;
next	1.5;

1.5
date	2001.07.18.10.05.12;	author dlr;	state Exp;
branches;
next	1.4;

1.4
date	2001.07.17.17.55.45;	author leonardr;	state Exp;
branches;
next	1.3;

1.3
date	2001.06.04.19.16.06;	author leonardr;	state Exp;
branches;
next	1.2;

1.2
date	2001.05.23.01.50.10;	author dlr;	state Exp;
branches;
next	1.1;

1.1
date	2001.03.08.19.05.37;	author leonardr;	state Exp;
branches;
next	;


desc
@@


1.7
log
@Moved code out of BaseHelmServlet and into other classes which suit it better.
@
text
@/* ================================================================
 * Copyright (c) 2000-2001 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 COLLABNET 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.domain;

import java.sql.*;
import java.util.*;

import org.apache.velocity.context.Context;

import org.apache.turbine.util.Log;
import org.apache.commons.util.exception.NestableException;

import org.tigris.helm.security.RedirectException;

import org.tigris.helm.DoesNotExist;
import org.tigris.helm.security.*;
import org.tigris.helm.om.*;
import org.tigris.helm.tool.ContextAPI;

/**
 * Add users to a user group.
 *
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 * @@version $Id: UserGroupElementAdd.java,v 1.6 2001/08/11 09:08:01 dlr Exp $
 */
public class UserGroupElementAdd extends org.tigris.helm.security.HelmServlet {
    public static final  String versionID = "$Id: UserGroupElementAdd.java,v 1.6 2001/08/11 09:08:01 dlr Exp $";
    
    private static boolean DEBUG = true;

    private static String ADD_ELEMENTS_ACTION="Add to Group";
    private static String ADD_ELEMENT_FIELD_PREFIX="Add ";

    private static String MASS_ADD_ELEMENTS_ACTION="Perform Mass Add";
    private static String GROUP_ELEMENTS_FIELD="elements";
    
    /**
     * Add some users to the group.
     */
    protected String processRequest(Context context)
	throws NestableException, RedirectException
    {
	String templateName = super.processRequest(context);
        try 
        {
            String action = getAction(context);
            
            // Gather any user input, adding it to the context as well.

            Domain domain = getCurrentDomain(context);
            UserGroup group = getCurrentUserGroup(context);

            List toAdd = null;
            if (ADD_ELEMENTS_ACTION.equals(action))
            {
                toAdd = UserPeer.getInstances
                    (ContextAPI.searchParamsForPrefix
                     (context, ADD_ELEMENT_FIELD_PREFIX));
            }

            if (MASS_ADD_ELEMENTS_ACTION.equals(action))
            {
                String elements = ContextAPI.processField
                    (context, GROUP_ELEMENTS_FIELD);
                toAdd = UserPeer.parseDesignantList
                    (elements, domain, 
                     ContextAPI.getValidationErrors(context));
            }
            
            //If there are users to add, add them.
            if (toAdd != null && ContextAPI.isValidUserInput(context))
            {
                AccessControlList acl = getLoginUser(context).getACL();
                for (Iterator i = toAdd.iterator(); i.hasNext();)
                {
                    User u = (User)i.next();
                    group.addUser(acl, u);
                }
                
                String url = domain.getDomainHomeServletURL
                    ("UserGroupEdit?userGroupID="+group.getID());
                redirectToURL(context, url);
            }            
        }
        catch (RedirectException e) 
        {
            throw e;
        }
        catch (Exception e) 
        {
            String msg = "Unable to add element(s) to user group: " +
                e.getMessage();
            Log.error(msg, e);
            throw new NestableException(e);
        }

        return templateName;  
    }
}
@


1.6
log
@Upgrading to Turbine 3.0-dev, Fulcrum 1.0, and Torque 1.0.
@
text
@d69 1
a69 1
 * @@version $Id: UserGroupElementAdd.java,v 1.5 2001/07/18 10:05:12 dlr Exp $
d72 1
a72 1
    public static final  String versionID = "$Id: UserGroupElementAdd.java,v 1.5 2001/07/18 10:05:12 dlr Exp $";
d102 2
a103 1
                    (searchParamsForPrefix(context, ADD_ELEMENT_FIELD_PREFIX));
@


1.5
log
@Ported Joist Redirect*Exception to Helm.
@
text
@d56 1
a56 1
import org.apache.turbine.util.TurbineException;
d69 1
a69 1
 * @@version $Id: UserGroupElementAdd.java,v 1.4 2001/07/17 17:55:45 leonardr Exp $
d72 1
a72 1
    public static final  String versionID = "$Id: UserGroupElementAdd.java,v 1.4 2001/07/17 17:55:45 leonardr Exp $";
d86 1
a86 1
	throws TurbineException, RedirectException
d138 1
a138 1
            throw new TurbineException(e);
@


1.4
log
@Porting of domain package to new error handling API.
@
text
@d58 1
a58 1
import org.joist.security.RedirectException;
d69 1
a69 1
 * @@version $Id: UserGroupElementAdd.java,v 1.3 2001/06/04 19:16:06 leonardr Exp $
d72 1
a72 1
    public static final  String versionID = "$Id: UserGroupElementAdd.java,v 1.3 2001/06/04 19:16:06 leonardr Exp $";
@


1.3
log
@Use convenience method.
@
text
@a56 1
import org.apache.turbine.util.TurbineException;
d63 2
a64 1
import org.tigris.helm.om.*;
d69 1
a69 1
 * @@version $Id: UserGroupElementAdd.java,v 1.2 2001/05/23 01:50:10 dlr Exp $
d72 1
a72 1
    public static final  String versionID = "$Id: UserGroupElementAdd.java,v 1.2 2001/05/23 01:50:10 dlr Exp $";
a97 3
            List missingFields = new ArrayList();
            List validationErrors = new ArrayList();

d107 5
a111 3
                String elements = processField(context, GROUP_ELEMENTS_FIELD);
                toAdd = UserPeer.parseDesignantList(elements, domain, 
                                                    validationErrors);
d115 1
a115 1
            if (toAdd != null && validationErrors.isEmpty())
a127 6

            if (!validationErrors.isEmpty())
            {
                reportInvalidUserInput(context, missingFields, 
                                       validationErrors);
            }
@


1.2
log
@Ported Helm from WebMacro to Velocity.
@
text
@d69 1
a69 1
 * @@version $Id: UserGroupElementAdd.java,v 1.1 2001/03/08 19:05:37 leonardr Exp $
d72 1
a72 1
    public static final  String versionID = "$Id: UserGroupElementAdd.java,v 1.1 2001/03/08 19:05:37 leonardr Exp $";
d78 3
d92 2
d95 1
a95 1
            // Gather any user input, adding it to the context as well.
a96 2
            AccessControlList acl = getLoginUser(context).getACL();
            Domain currentDomain = getCurrentDomain(context);
d101 16
a116 1
            if (action != null && action.equals(ADD_ELEMENTS_ACTION))
d118 2
a119 3
                Enumeration paramNames =
                    getRequest(context).getParameterNames();
                while (paramNames.hasMoreElements ())
d121 13
a133 13
                    String paramName = (String) paramNames.nextElement ();
                    
                    if (paramName.startsWith(ADD_ELEMENT_FIELD_PREFIX))
                    {
                        StringTokenizer tok = new StringTokenizer (paramName);
                        tok.nextToken ();
                        User user = UserPeer.getInstance(tok.nextToken());
                        group.addUser(acl, user);
                    }
                }    
                redirectToURL
                    (context, currentDomain.getDomainHomeServletURL
                     ("UserGroupEdit?userGroupID="+group.getID()));       
d136 2
a137 1
        catch (ACLException e) {
d140 3
a142 5
        catch (RedirectException e) {
            throw e;
        }
        catch (Exception e) {
            String msg = "Unable to add element to user group: " +
@


1.1
log
@Political correctness strikes Tigris.org! The components of project and user groups no longer wish to be called "members", as that causes them to be confused with users who have roles in projects. The new, approved term is "elements".
@
text
@d53 1
a53 1
import org.webmacro.servlet.*;
d56 2
d69 1
a69 1
 * @@version $Id: UserGroupElementAdd.java,v 1.7 2001/03/07 01:53:20 lucas Exp $
d72 1
a72 1
    public static final  String versionID = "$Id: UserGroupElementAdd.java,v 1.7 2001/03/07 01:53:20 lucas Exp $";
d82 2
a83 2
    protected String processRequest (Connection connection, WebContext context)
	throws HandlerException, RedirectException
d85 1
a85 1
	String templateName = super.processRequest(connection, context);
d101 1
a101 1
                    context.getRequest().getParameterNames();
d129 1
a129 1
            throw new HandlerException(msg);
@

