head	1.41;
access;
symbols
	TIGRIS_1_1_0RC2:1.31.2.1
	TIGRIS_1_1_0RC1:1.31.2.1
	TIGRIS_1_1:1.31.2.1.0.2
	TIGRIS_1_0_8:1.31.2.1
	TIGRIS_1_0_8RC3:1.31.2.1
	TIGRIS_1_0_8RC2:1.31.2.1
	TIGRIS_1_0_8RC1:1.31.2.1
	TIGRIS_1_0_7:1.31.2.1
	TIGRIS_1_0_7RC3:1.31.2.1
	TIGRIS_1_0_7RC2:1.31.2.1
	TIGRIS_1_0_7RC1:1.31.2.1
	TIGRIS_1_0_6:1.31.2.1
	TIGRIS_1_0_6RC5:1.31.2.1
	TIGRIS_1_0_6RC4:1.31.2.1
	TIGRIS_1_0_6RC3:1.31.2.1
	TIGRIS_1_0_6RC2:1.31.2.1
	TIGRIS_1_0_6RC1:1.31.2.1
	TIGRIS_1_0_5:1.31.2.1
	TIGRIS_1_0_5RC6:1.31.2.1
	TIGRIS_1_0_5RC5:1.31.2.1
	TIGRIS_1_0_5RC4:1.31.2.1
	TIGRIS_1_0_5RC3:1.31.2.1
	TIGRIS_1_0_5RC2:1.31.2.1
	TIGRIS_1_0_5RC1:1.31.2.1
	TIGRIS_1_0_4:1.31.2.1
	TIGRIS_1_0_3:1.31.2.1
	TIGRIS_1_0_2:1.31.2.1
	TIGRIS_1_0_1:1.31.2.1
	TIGRIS_1_0:1.31.2.1.0.4
	TIGRIS_1_0_0:1.31.2.1
	TIGRIS_1_0_0_RC1:1.31.0.2
	dlr:1.1.1
	TIGRIS_0_9_2_4:1.18
	TIGRIS_0_9_2_3:1.18
	HELM_PEER_PORT_BRANCH:1.1.1.2
	TURBINE_PEER:1.20
	TIGRIS_0_9_2_1:1.20
	TIGRIS_0_9_2:1.18.0.4
	TIGRIS_0_9_0:1.18.0.2
	TIGRIS_0_8_4:1.16.0.2
	NEWHELM:1.1.1.1
	TIGRIS_NOV_12_2000:1.1.1;
locks; strict;
comment	@# @;


1.41
date	2001.08.15.18.51.59;	author leonardr;	state Exp;
branches;
next	1.40;

1.40
date	2001.08.11.09.08.07;	author dlr;	state Exp;
branches;
next	1.39;

1.39
date	2001.07.30.18.40.42;	author leonardr;	state Exp;
branches;
next	1.38;

1.38
date	2001.07.24.00.02.28;	author leonardr;	state Exp;
branches;
next	1.37;

1.37
date	2001.07.18.10.05.14;	author dlr;	state Exp;
branches;
next	1.36;

1.36
date	2001.07.17.20.54.06;	author leonardr;	state Exp;
branches;
next	1.35;

1.35
date	2001.07.17.20.10.49;	author leonardr;	state Exp;
branches;
next	1.34;

1.34
date	2001.05.23.01.50.15;	author dlr;	state Exp;
branches;
next	1.33;

1.33
date	2001.03.30.00.25.57;	author leonardr;	state Exp;
branches;
next	1.32;

1.32
date	2001.03.28.23.08.01;	author leonardr;	state Exp;
branches;
next	1.31;

1.31
date	2001.03.23.19.36.36;	author leonardr;	state Exp;
branches
	1.31.2.1;
next	1.30;

1.30
date	2001.03.23.19.30.57;	author leonardr;	state Exp;
branches;
next	1.29;

1.29
date	2001.03.23.18.52.47;	author leonardr;	state Exp;
branches;
next	1.28;

1.28
date	2001.03.23.04.09.06;	author dlr;	state Exp;
branches;
next	1.27;

1.27
date	2001.03.23.02.47.16;	author dlr;	state Exp;
branches;
next	1.26;

1.26
date	2001.03.14.22.50.48;	author dlr;	state Exp;
branches;
next	1.25;

1.25
date	2001.03.14.20.04.20;	author dlr;	state Exp;
branches;
next	1.24;

1.24
date	2001.03.08.03.19.26;	author dlr;	state Exp;
branches;
next	1.23;

1.23
date	2001.03.08.03.12.23;	author dlr;	state Exp;
branches;
next	1.22;

1.22
date	2001.03.07.01.53.25;	author lucas;	state Exp;
branches;
next	1.21;

1.21
date	2001.02.21.01.08.23;	author dlr;	state Exp;
branches;
next	1.20;

1.20
date	2001.01.26.18.29.05;	author edk;	state Exp;
branches
	1.20.2.1;
next	1.19;

1.19
date	2001.01.26.05.24.06;	author edk;	state dead;
branches;
next	1.18;

1.18
date	2000.12.14.03.09.59;	author leonardr;	state Exp;
branches;
next	1.17;

1.17
date	2000.12.14.03.04.17;	author edk;	state Exp;
branches;
next	1.16;

1.16
date	2000.12.01.22.34.29;	author edk;	state Exp;
branches;
next	1.15;

1.15
date	2000.11.23.09.20.04;	author dlr;	state Exp;
branches;
next	1.14;

1.14
date	2000.11.23.09.19.38;	author dlr;	state Exp;
branches;
next	1.13;

1.13
date	2000.11.22.06.09.20;	author edk;	state Exp;
branches;
next	1.12;

1.12
date	2000.11.22.02.18.55;	author edk;	state Exp;
branches;
next	1.11;

1.11
date	2000.11.22.01.51.09;	author edk;	state Exp;
branches;
next	1.10;

1.10
date	2000.11.17.22.21.12;	author edk;	state Exp;
branches;
next	1.9;

1.9
date	2000.11.17.21.49.38;	author leonardr;	state Exp;
branches;
next	1.8;

1.8
date	2000.11.15.23.49.43;	author leonardr;	state Exp;
branches;
next	1.7;

1.7
date	2000.11.15.23.05.27;	author elicia;	state Exp;
branches;
next	1.6;

1.6
date	2000.11.15.22.48.40;	author leonardr;	state Exp;
branches;
next	1.5;

1.5
date	2000.11.15.21.09.41;	author elicia;	state Exp;
branches;
next	1.4;

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

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

1.2
date	2000.11.13.19.18.49;	author leonardr;	state Exp;
branches;
next	1.1;

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

1.1.1.1
date	2000.11.12.21.16.13;	author dlr;	state Exp;
branches;
next	1.1.1.2;

1.1.1.2
date	2001.02.21.00.35.01;	author dlr;	state Exp;
branches;
next	;

1.20.2.1
date	2001.01.28.01.02.18;	author dlr;	state dead;
branches;
next	1.20.2.2;

1.20.2.2
date	2001.02.16.02.02.17;	author leonardr;	state Exp;
branches;
next	1.20.2.3;

1.20.2.3
date	2001.02.16.03.01.34;	author dlr;	state Exp;
branches;
next	;

1.31.2.1
date	2001.03.28.19.22.27;	author leonardr;	state Exp;
branches;
next	;


desc
@@


1.41
log
@Use the database to check whether a user has a role in a project, not their ACL. The ACL counts roles you have via a user group as roles you have personally, and you should be able to request roles in a project even if you already have them via a user group.
@
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 Collab.Net.
 * 
 * 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.project;

import java.sql.Connection;
import java.util.*;
import javax.servlet.http.HttpSession;

import org.apache.velocity.context.Context;

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

import org.tigris.helm.security.RedirectException;

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

public class ProjectMembershipRequest extends HelmServlet 
{
    /**
     * Field indicating the requested role.
     */
    public final static String REQUESTED_ROLE_FIELD = "role";

    /**
     * Whether in debug state.
     */    
    private static final boolean DEBUG = true;
            
    /**
     * Key to pull the invitation/ticket w/ getForm()
     */
    private static final String TICKET_KEY = "ticket";

    /**
     * Property file field name for success page
     */
    private static final String SUCCESS_PAGE = "successPage";
        
    /**
     * Action for role requesting.
     */
    private static final String SUBMIT_REQUEST_ACTION = "Submit Request";

    /**
     * Error to display if someone requests a role they already hold
     * (not a likely occurance since such roles are not shown.)
     */    	
    private static final String ROLE_ALREADY_REQUESTED_ERROR =
        "You have already requested this role in this project. You will receive email once your request has been processed.";

    /**
     * Error to display if someone requests a role they already hold
     * (not a likely occurance since such roles are not shown.)
     */    	
    private static final String ROLE_ALREADY_GRANTED_ERROR =
        "You already have this role in this project.";

    /**
     * The membership request action.
     */
    private final String REQUEST_ACTION = "Role - Request";

    /**
     * Display and process the Project Membership Request screen
     */
    protected String processRequest(Context context)
        throws NestableException, RedirectException
    {
        String templateName = super.processRequest(context);

        try 
        {
            Project currentProject = getCurrentProject(context);
            User loginUser = getLoginUser(context);
            AccessControlList acl = loginUser.getACL();
            Invitation invitation = null;

            /**
             * If they have a ticket, store it in the context; if the
             * ACLException fails, we'll set the detour to come back
             * here in the event that they get some permissions (by logging
             * in or signing up for the site)
             */
            String ticket = ContextAPI.processField(context, TICKET_KEY);
            if (DEBUG) Log.debug("ProjectMembershipRequest ticket: " + ticket);

            if (haveValue(ticket))
            {
                invitation = InvitationPeer.getInstance(ticket);
                if (invitation == null)
                {
                    context.put(TICKET_KEY, null);
                    redirectToError(context, Invitation.BAD_TICKET_MESSAGE);
                }
                else
                {
                    if (invitation.isMatch(currentProject))
                    {
                        // We'll want to check and possibly delete this
                        // ticket later.
                        context.put(TICKET_KEY, ticket);
                    } 
                    else
                    {
                        context.put(TICKET_KEY, null);
                        //TODO: Change to ContextAPI.addFatalError
                        redirectToError
                            (context, 
                             Invitation.WRONG_PROJECT_FOR_TICKET_MESSAGE);
                    }
                }
            }

            try
            {
                acl.assertPermission(REQUEST_ACTION, currentProject);
                doAction(context, currentProject, loginUser);
            }
            catch (ACLException e)
            {
                ticket = (String)context.get(TICKET_KEY);
                if (!loginUser.isAnonymous() && ticket != null)
                {
                    doAction(context, currentProject, loginUser);
                }
                else
                {
                    if (ticket != null && !"".equals(ticket))
                    {
                        ContextAPI.addMessage(context, "You need to log in before you can use your ticket. If you do not yet have an account, you need to <a href=\"/servlets/Join\">register</a> with the site.");
                    }

                    setAsDetour(context);
                    throw e;
                }
            }
        }
        catch (RedirectException e)
        {
            throw e;
        }
        catch (Exception e)
        {
            Log.error("Error servicing project membership request", e);
            throw new NestableException(e);
        }

        return templateName;
    }

    /**
     * Decides which action to take to handle this request.
     */
    private void doAction(Context context, Project currentProject,
                          User loginUser)
        throws RedirectException, Exception
    {
        String action = getAction(context);
        if (action != null)
        {
            if (action.equals(SUBMIT_REQUEST_ACTION))
            {
                // Check for missing fields or validation errors.  If
                // we have any, go around again on this same form --
                // displaying the problem w/ current form submission
                // in the 'Message' field in the head of the form.
                //

                // We have all fields.  Request the role for the
                // user.
                String roleRequested = ContextAPI.processRequiredField
                    (context, REQUESTED_ROLE_FIELD, "Role");

                if (ContextAPI.isValidUserInput(context))
                {
                    Role role = (Role)RolePeer.getInstance(roleRequested);
                    boolean request = false;

                    //If they've already requested or already have this
                    //role, it's an error.
                    if (loginUser.hasApprovedRoleInProject
                        (role, currentProject))
                    {
                        ContextAPI.addError(context, 
                                            ROLE_ALREADY_GRANTED_ERROR);
                    }
                    else if (loginUser.hasRequestedRoleInProject
                             (role, currentProject))
                    {
                        ContextAPI.addError(context, 
                                            ROLE_ALREADY_REQUESTED_ERROR);
                    }
                    else
                    {
                        String ticket = ContextAPI.processField
                            (context, TICKET_KEY);

                        if (ticket == "")
                        {
                            //They want to request the role without a ticket.
                            //Let their ACL decide whether or not they
                            //can do it.
                            loginUser.requestRole(role, currentProject);
                        }
                        else
                        {
                            //They're requesting a role using a ticket.
                            loginUser.requestRole(ticket, role, currentProject);                                                        
                        } 

                        //Remove any ticket from the context
                        context.put(TICKET_KEY, null);

                        String redirectTo = getCurrentDomain(context)
                            .getDomainHomeServletURL("StartPage");
                        if (currentProject.isViewableBy(loginUser.getACL()))
                        {
                            redirectTo = currentProject.getProjectHome();
                        }
                        redirectToURL(context, redirectTo);   
                    }
                }
            }
        }
    }
}
@


1.40
log
@Upgrading to Turbine 3.0-dev, Fulcrum 1.0, and Torque 1.0.
@
text
@d230 2
a231 1
                    if (loginUser.getACL().hasRole(role, currentProject))
@


1.39
log
@Action cleanup. Some role actions, and Audit Log - View, had three actions apiece when one would do. We're now down to 76 actions.
@
text
@d56 2
a57 2
import org.apache.turbine.util.TurbineException;
import org.apache.turbine.util.TurbineException;
d116 1
a116 1
        throws TurbineException, RedirectException
d194 1
a194 1
            throw new TurbineException(e);
@


1.38
log
@The final pieces of the error handling revolution.
@
text
@d108 1
a108 1
     * The membership request role.
d110 1
a110 1
    private final String REQUEST_ROLE = "Project Role - Request";
d165 1
a165 1
                acl.assertPermission(REQUEST_ROLE, currentProject);
@


1.37
log
@Ported Joist Redirect*Exception to Helm.
@
text
@d194 1
a194 1
            appendToError(context, e.getMessage());            
@


1.36
log
@Cleanup for port to new error handling system.
@
text
@d59 1
a59 1
import org.joist.security.RedirectException;
@


1.35
log
@Ported servlets to new error-handling mechanism.
@
text
@d243 2
a244 1
                        String ticket = processField(context, TICKET_KEY);
@


1.34
log
@Ported Helm from WebMacro to Velocity.
@
text
@d64 1
d133 1
a133 1
            String ticket = processField(context, TICKET_KEY);
d155 1
d179 1
a179 1
                        appendToMessage(context, "You need to log in before you can use your ticket. If you do not yet have an account, you need to <a href=\"/servlets/Join\">register</a> with the site.");
a206 1
        List missingFields = new ArrayList();
a211 2
                List validationErrors = new ArrayList();
                
d217 7
a223 1
                if (isValidUserInput(missingFields, validationErrors))
a224 4
                    // We have all fields.  Request the role for the
                    // user.
                    String roleRequested = processField
                        (context, REQUESTED_ROLE_FIELD, "Role", missingFields);
d232 2
a233 2
                        appendToError(context, 
                                      ROLE_ALREADY_GRANTED_ERROR);
d238 2
a239 2
                        appendToError(context, 
                                      ROLE_ALREADY_REQUESTED_ERROR);
@


1.33
log
@Factored out messages into constants, and used message in another place.
@
text
@d53 1
a53 1
import org.webmacro.servlet.*;
d56 2
d114 2
a115 2
    protected String processRequest (Connection conn, WebContext context)
        throws HandlerException, RedirectException
d117 1
a117 1
        String templateName = super.processRequest(conn, context);
d201 1
a201 1
    private void doAction(WebContext context, Project currentProject,
@


1.32
log
@Frontported change to RC1 branch.
@
text
@d139 1
a139 1
                    redirectToError(context, "Your ticket is no longer valid.");
d152 3
a154 1
                        redirectToError(context, "Your ticket is not valid for this project.");
@


1.31
log
@Don't take them to the project home if that'll just cause a permission violation (as it would if someone was using a ticket to request a role in a private or unapproved project).
@
text
@a237 6
                        //They want to request the role.
                        //TODO: Pass in ACL, or not, depending on whether
                        //or not they have a ticket.
                        loginUser.requestRole(role, currentProject);
                        
                        //Remove any ticket from the context and/or database.
d239 9
a247 2
                        context.put(TICKET_KEY, null);
                        try 
d249 2
a250 3
                            Invitation invitation =
                                InvitationPeer.getInstance(ticket);
                            invitation.delete();
d252 4
a255 4
                        catch (DoesNotExist ignore)
                        {
                            Log.debug("No such invitation for ticket " + ticket);
                        }
@


1.31.2.1
log
@Role requests using tickets were doing an ACL check instead of using the tickets. This is fixed now.
@
text
@d238 6
d245 2
a246 2

                        if (ticket == "")
d248 5
a252 6
                            //They want to request the role without a ticket.
                            //Let their ACL decide whether or not they
                            //can do it.
                            loginUser.requestRole(role, currentProject);
                        }
                        else
d254 1
a254 2
                            //They're requesting a role using a ticket.
                            loginUser.requestRole(ticket, role, currentProject);
a255 4

                        //Remove any ticket from the context
                        context.put(TICKET_KEY, null);
                        
@


1.30
log
@Errors prevent the page from being shown.
@
text
@d258 4
a261 1
                        redirectTo = currentProject.getProjectHome();
@


1.29
log
@Some fixes for the whole ProjectMembershipRequest/Join/Login/Invitation Rube Goldberg.
@
text
@d139 1
a139 1
                    appendToError(context, "Your ticket is no longer valid.");
d152 1
a152 1
                        appendToError(context, "Your ticket is not valid for this project.");
@


1.28
log
@* Both the inter- and intra-servlet flow were fundamentally flawed.
Moving towards a useable flow.

* Added cleanup code.
@
text
@d61 2
a62 1
import org.tigris.helm.om.*;
d124 7
a130 2
            HttpSession session = context.getRequest().getSession(true);
            String ticket = processField(context, TICKET_KEY, session);
d136 1
a136 1
                if (invitation.isMatch(currentProject))
d138 16
a153 2
                    // We'll want to delet this ticket later.
                    session.putValue(TICKET_KEY, ticket);
d164 2
a165 1
                if (!loginUser.isAnonymous() && haveValue(ticket))
d171 6
d242 11
a252 8

                        // Clean up the session and database.
                        HttpSession session =
                            context.getRequest().getSession(true);
                        String ticket = (String) session.getValue(TICKET_KEY);
                        Invitation invitation =
                            InvitationPeer.getInstance(ticket);
                        if (invitation != null)
d254 1
a254 6
                            if (DEBUG)
                            {
                                Log.debug("Deleting project memebership " +
                                          "invitation " + invitation.getID());
                            }
                            invitation.delete(loginUser.getACL());
a255 1
                        session.removeValue(TICKET_KEY);
@


1.27
log
@* Moved public var up in file.

* Made DEBUG const.
@
text
@d51 1
d115 1
a115 2
        String action = getAction(context);
        
d117 1
a117 1
        {                                                                     
d123 2
a124 1
            String ticket = processField(context, TICKET_KEY);
d127 10
d140 1
d144 1
a144 3
                // If a valid ticket & invitation are presented, ignore the
                // access violation.
                if (haveValue(ticket))
d146 1
a146 8
                    invitation = InvitationPeer.getInstance(ticket);

                    if (!invitation.isMatch(currentProject))
                    {
                        Log.debug("User has neither membership ticket nor " +
                                  REQUEST_ROLE + " role");
                        throw e;
                    }
d153 10
d164 2
a165 3
            List missingFields = new ArrayList();
            String roleRequested = processField
                (context, REQUESTED_ROLE_FIELD, "Role", missingFields);
d167 12
a178 1
            if (action != null)
d180 8
a187 1
                if (action.equals(SUBMIT_REQUEST_ACTION))
d189 21
a209 8
                    List validationErrors = new ArrayList();
                
                    // Check for missing fields or validation errors.  If
                    // we have any, go around again on this same form --
                    // displaying the problem w/ current form submission
                    // in the 'Message' field in the head of the form.
                    //
                    if (isValidUserInput(missingFields, validationErrors))
d211 12
a222 19
                        // We have all fields.  Request the role for the
                        // user.
                        Role role = (Role)RolePeer.getInstance(roleRequested);
                        boolean request = false;

                        //If they've already requested or already have this
                        //role, it's an error.
                        if (loginUser.getACL().hasRole(role, currentProject))
                        {
                            appendToError(context, 
                                          ROLE_ALREADY_GRANTED_ERROR);
                        }
                        else if (loginUser.hasRequestedRoleInProject
                                 (role, currentProject))
                        {
                            appendToError(context, 
                                          ROLE_ALREADY_REQUESTED_ERROR);
                        }
                        else
d224 1
a224 7
                            //They want to request the role.
                            //TODO: Pass in ACL, or not, depending on whether
                            //or not they have a ticket.
                            loginUser.requestRole(role, currentProject);
                            
                            /* TODO: Add Invitation.delete().
                            if (invitation != null)
d226 2
a227 6
                                if (DEBUG)
                                {
                                    Log.debug("Deleting project memebership " +
                                              "invitation");
                                }
                                invitation.delete();
d229 1
a229 5
                            */
                            String redirectTo = getCurrentDomain(context)
                                .getDomainHomeServletURL("StartPage");
                            redirectTo = currentProject.getProjectHome();
                            redirectToURL(context, redirectTo);   
d231 5
d238 1
a238 10
            } 
        }
        catch (RedirectException e)
        {
            throw e;
        }
        catch (Exception e)
        {
            Log.error("Error servicing project membership request", e);
            appendToError(context, e.getMessage());            
a239 2

        return templateName;
@


1.26
log
@Misc. minor cleanup.
@
text
@a63 5
     *Is in debug state.
     */    
    private static boolean DEBUG = true;
            
    /**
d69 5
d86 1
a86 1
    private static final String SUBMIT_REQUEST_ACTION="Submit Request";
@


1.25
log
@Formatting change.
@
text
@a154 3
            //
            // Switch on the action
            //
d179 4
a182 2
                        }  else if (loginUser.hasRequestedRoleInProject
                                    (role, currentProject)) {
d193 11
a203 5
                            // for now, we're not deleting invitations
                            //if (invitation != null) {
                            //    if (DEBUG) Log.info("going to delete invitation");
                            //    invitation.delete();
                            //}
d219 1
a219 1
            Log.error("Exception thrown in ProjectMembershipRequest", e);
@


1.24
log
@Corrected comment plurality.
@
text
@a62 1
    
a77 1
    
d207 3
a209 1
        } catch (RedirectException e) {
d211 3
a213 1
        } catch (Exception e) {
d220 1
a220 2
  
} /* end class ProjectMembershipRequest */
@


1.23
log
@* Added constant for the "Project Role - Request" action.
* Cleaned up initialization of the ticket, taking advantage of the
  more "modern" framework features.
* Cleaned up section that allows the anonymous user to proceed with a
  add, even though they may lack the requisite permission.
@
text
@d134 1
a134 1
                // If a valid ticket & invitation is presented, ignore the
@


1.22
log
@Corrected regex madness for Torque upgrade.  -dlr
@
text
@d105 5
d124 1
d126 1
d128 5
a132 6
            if (ticket != null && !ticket.equals(""))
                context.put("ticket", ticket);
            if (DEBUG) Log.debug("ProjectMembershipRequest: got ticket: " 
                                 + ticket);

            try 
d134 3
a136 4
                acl.assertPermission("Project Role - Request", currentProject);
            } catch (ACLException e) {
                // see if they have a valid ticket / invitation
                if (DEBUG)
d138 8
a145 2
                    Log.debug
                    ("User is missing request role; checking for ticket.");
d147 1
a147 8
                if (ticket == null || ticket.equals(""))
                {
                    throw e;
                }

                invitation = InvitationPeer.getInstance(ticket);
                
                if (!invitation.isMatch(currentProject))
a148 1
                    Log.debug("User has no ticket.");
d155 1
a155 1
            (context, REQUESTED_ROLE_FIELD, "Role", missingFields);
d160 1
a160 1
            if(action != null)
@


1.21
log
@This is the highest revision from the HELM_PEER_PORT_BRANCH.  The previous import caused too many conflicts to resolve manually
@
text
@d60 1
a60 3
import org.tigris.helm.om.peer.*;
import org.tigris.helm.om.base.*;

@


1.20
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d2 1
a2 1
 * Copyright (c) 2000 CollabNet.  All rights reserved.
d49 2
a50 5
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.List;
import java.util.ArrayList;
a51 1
import org.webmacro.util.*;
d54 1
a54 1
import com.workingdogs.village.*;
d56 1
a56 5
import org.joist.*;
import org.joist.util.*;
import org.joist.session.*;
import org.joist.security.*;
import org.joist.database.*;
a57 2
import org.tigris.helm.DoesNotExist;
import org.tigris.helm.database.*;
d59 5
a63 63
import org.tigris.helm.domain.*;
import org.tigris.helm.tool.*;
import org.tigris.helm.tool.paginate.*;
import org.tigris.helm.project.Project;

/** 
* Handle the Project Membership Request form.
* <p>
* Issues:
* <ol>
*    <li>We drop the membershipReason field.  We don't have anywhere to insert 
*       it yet.  
*     Need to modify the grant method in UserRoleProjectManager
*   </li>
*    <li>The javadoc adds a 'Serialized Form' on the end of this comment block.  
*       Don't know why
*     </li>
* </ol>
* </p>
* <p>
* Test Cases:
* <ol>
* <li>What happens when form is empty and it's submitted?
*     <ol>
*         <li>Missing Fields message shows up ('Missing Fields: Reason' as 
*           'Reason' is the only field w/o a value).  
*            When the popup menu had mocki-ah project names that didn't fit 
*           the isValidProject RE, Validation Error messages were showing.</li>
*     </ol>
* </li>
* <li>What happens when form is partially completed?  Does the missing fields messages display?
*     <ol>
*        <li>Yes.  See above.
*        </li>
*     </ol>
* </li>
* <li>On successful submission, does the content show up in the database?  
*         <ol>
*            <li>Yes.  Has NULL in the approved by column.</li>
*            <li>ISSUE: If you submit same request twice, nothing add to database.  No warning.</li>
*        </ol>
* </li>
* <li>On successful submission, are we taken to the next page, the project home page?
*     <ol>
*        <li>Yes -- ProjectHome.  I've put successPage into properties file.</li>
*    </ol>
* </li>
* <li>Check the javadoc.  How does it come out?
*         <ol>
*            <li>Looks good.  I built the javadoc using: 
*                 <pre>/home/stack/software/jdk1.3/bin/javadoc -d javadoc -classpath /home/stack/cvsroot/sandbox/site/lib/joist.jar:${CLASSPATH}  -sourcepath . org.tigris.helm.project.ProjectMembershipRequest org.tigris.helm.domain.ProjectAddStep1
*                </pre>
*            </li>
*        </ol>
* </li>
* </ol>
*
* @@version $Id: ProjectMembershipRequest.java,v 1.18 2000/12/14 03:09:59 leonardr Exp $
* @@see org.tigris.helm.domain.ProjectAddStep1 This servlet is modeled on
* org.tigris.helm.domain.ProjectAddStep1
*/
public class ProjectMembershipRequest
    extends org.tigris.helm.security.HelmServlet 
a64 9
    /**
     * Version string.
     */
    public static final  String versionID = "$Id: ProjectMembershipRequest.java,v 1.18 2000/12/14 03:09:59 leonardr Exp $";
    
    /**
     *Instance of logging class.
     */
    private static Log log = new Log("projMbrReq", "ProjectMembershipRequest");
d69 2
a70 2
    private static boolean debug = true;
    
d72 1
a72 4
     * List of projects context key.
     *
     * Use this to get the list of projects out of context.
     * E.g., context.get(PROJECTS_CONTEXT_KEY)
d74 2
a75 3
    public final static String PROJECTS_CONTEXT_KEY = "projects";
    
    
d77 1
a77 4
     *List of roles context key.
     * 
     * Use this string to get the list of roles from context.
     * E.g., context.get(ROLES_CONTEXT_KEY)
d79 1
a79 1
    public final static String ROLES_CONTEXT_KEY = "role";
d86 1
a86 2
    
    
d88 1
a88 1
     * Key to pull 'action' from context w/ getForm()
d90 8
a97 1
    private static final String ACTION_KEY = "action";
d100 6
a105 5
     * Key to pull the invitation/ticket w/ getForm()
     */
    private static final String TICKET_KEY = "ticket";
    
	
d109 2
a110 2
    protected String processRequest (Connection connection, WebContext context)
        throws HandlerException, RedirectException, ACLException
d112 2
a113 2
        String templateName = super.processRequest(connection, context);
        String action = (String)context.get(ACTION_KEY); 
d119 1
a119 2
            readDomainIntoContext(connection, context);
            AccessControlList acl = getACL(context, connection);
a122 5
            // provide some extra info on the page if the project isn't
            // approved yet
            if (!currentProject.isApproved())
                context.put("projectApprovalPending", new Boolean(true));

d125 2
a126 1
            if (debug) log.info("got ticket: " + ticket);
d128 3
a130 14
            String projectID = null;
            try {
                projectID = currentProject.getID();
            } catch (DataSetException e) {
                log.exception(e);
                if (debug) log.info("unable to get currentProjectID: "+
                        e.getMessage());
            }
            log.info("got projectID : " + projectID);

            try {
                acl.assertPermissionForProject("Project Role - Request",
                        projectID);
                log.info("have required role");
d133 5
a137 1
                log.info("missing required role");
d139 1
d141 1
d143 6
a148 8
                DataManager dMgr = getDataManager(context);
                try {
                    invitation = new Invitation(connection, 
                            dMgr, ticket);
                } catch (DoesNotExist ignored) {
                    throw new ACLException(acl, "Project Role - Request", 
                            "Invitations can only be used once for private " +
                            "projects", null);
a149 3
                if (projectID == null || 
                        !invitation.isValidForProject(currentProject.getID()))
                    throw e;
d153 4
a156 4
            String roleRequested = processField(context, 
                                                ROLES_CONTEXT_KEY,
                                                "Role",
                                                missingFields);
d159 1
a159 1
            if(action != null && action.equals("Submit Request"))
d161 3
a163 1
                List validationErrors = new ArrayList();
d165 6
a170 36
                // Check for missing fields or validation errors.  If
                // we have any, go around again on this same form --
                // displaying the problem w/ current form submission
                // in the 'Message' field in the head of the form.
                //
                if(!missingFields.isEmpty())
                {
                    appendToMessage(context, "Missing Fields", missingFields);
                    if(debug)
                        log.info("Missing Fields: " 
                                 + missingFields.toString());
                } else if(!validationErrors.isEmpty()) {
                    appendToMessage(context, "Validation Errors", 
                                    validationErrors);
                    if(debug)
                        log.info("Validation Errors: " 
                                 + validationErrors.toString());
                }
                else
                {
                    // We have all fields.  Request the role for the
                    // user.
                    Role role = new Role(connection, dMgr, roleRequested);
                    boolean request = false;
                    if (invitation == null) {
                        if(debug) log.info("Requesting role " + role.getName());
                        request = loginUser.requestRole(acl, role,
                                currentProject);
                    } else {
                        if (debug) log.info("Requesting role through " +
                                "invitation: " + role.getName());
                        request = loginUser.requestRoleWithoutApproval(role,
                                currentProject);
                    }

                    if (request)
d172 17
a188 9
                        // for now, we're not deleting invitations
                        //if (invitation != null) {
                        //    if (debug) log.info("going to delete invitation");
                        //    invitation.delete();
                        //}
                        String redirectTo = getCurrentDomain(context)
                            .getDomainHomeServletURL( "StartPage" );
                        if (acl.hasPermissionForProject
                            ("Project Page - View", currentProject.getID()))
d190 12
d203 1
a204 7
                        redirectToURL(context, redirectTo);   
                    } else {
                        appendToMessage(context, 
                                        "You have already requested this role "
                                        + "in this project. You will receive "
                                        + "email once your request has been "
                                        + "processed.");
d207 6
a212 26
            } // End of if 'Submit Request' is true
        } catch (SQLException e) {
            log.exception(e);
            String message = "" + e.getMessage();
            if(debug) log.info(message);
            appendToMessage(context, message);
        } catch (JoistException e) {
            log.exception(e);
            String message = "" + e.getMessage();
            if(debug) log.info(message);
            appendToMessage(context, message);
        } catch (DataSetException e) {
            log.exception(e);
            String message = "" + e.getMessage();
            if(debug) log.info(message);
            appendToMessage(context, message);
        } catch (JoistDatabaseException e) {
            log.exception(e);
            String message = "" + e.getMessage();
            if(debug) log.info(message);
            appendToMessage(context, message);            
        } catch (DoesNotExist e) {
            log.exception(e);
            String message = "" + e.getMessage();
            if(debug) log.info(message);
            appendToMessage(context, message);            
a213 1
        if(debug) log.info("done");
a215 35
    }
    
    /** Read domain contents -- roles and projects -- and put them into the
     * context.
     * 
     * Get domain object.  From this object, pull the list of projects and
     * roles.  Push them into context for the webmacro template to populate
     * the form with.
     * <p>
     * Talking to davidp, there should be a list of projects in the context.
     * We shouldn't be asking domain object for the project list in the webmacro
     * page directly in case of db exception; These are hard to handle
     * in a webmacro page. 
     *
     * @@param connection Database connection to use.
     * @@param context    Current request context.
     *
     * @@exception Exception
     */
    private void readDomainIntoContext(Connection connection, 
                                       WebContext context)
        throws SQLException, DataSetException, JoistDatabaseException,
               DoesNotExist
    {
        List roles = getCurrentDomain(context).getRoles();
        if(roles != null)
        {
            context.put(ROLES_CONTEXT_KEY, roles);
            if(debug)
                log.info("Put " + ROLES_CONTEXT_KEY + " = " + roles.toString());
        }
        else
        {
            if(debug) log.info(ROLES_CONTEXT_KEY + " is null");
        }
@


1.20.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@d126 1
a126 1
* @@version $Id: ProjectMembershipRequest.java,v 1.20 2001/01/26 18:29:05 edk Exp $
d136 1
a136 1
    public static final  String versionID = "$Id: ProjectMembershipRequest.java,v 1.20 2001/01/26 18:29:05 edk Exp $";
@


1.20.2.2
log
@Ported ProjectMembershipRequest servlet.
@
text
@d2 1
a2 1
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
d49 5
a53 2
import java.sql.Connection;
import java.util.*;
d55 1
d58 1
a58 1
import org.apache.turbine.util.Log;
d60 5
a64 1
import org.joist.security.RedirectException;
d66 2
d69 63
a131 4
import org.tigris.helm.om.*;
import org.tigris.helm.om.peer.*;

public class ProjectMembershipRequest extends HelmServlet 
d133 9
d146 2
a147 2
    private static boolean DEBUG = true;
            
d149 4
a152 1
     * Field indicating the requested role.
d154 3
a156 2
    public final static String REQUESTED_ROLE_FIELD = "role";

d158 4
a161 1
     * Key to pull the invitation/ticket w/ getForm()
d163 1
a163 1
    private static final String TICKET_KEY = "ticket";
d170 2
a171 1
        
d173 1
a173 1
     * Action for role requesting.
d175 1
a175 1
    private static final String SUBMIT_REQUEST_ACTION="Submit Request";
d178 5
a182 13
     * Error to display if someone requests a role they already hold
     * (not a likely occurance since such roles are not shown.)
     */    	
    private static final String ROLE_ALREADY_REQUESTED_ERROR =
        "You have already requested this role in this project. You will receive email once your request has been processed.";

    /**
     * Error to display if someone requests a role they already hold
     * (not a likely occurance since such roles are not shown.)
     */    	
    private static final String ROLE_ALREADY_GRANTED_ERROR =
        "You already have this role in this project.";

d186 2
a187 2
    protected String processRequest (Connection conn, WebContext context)
        throws HandlerException, RedirectException
d189 2
a190 2
        String templateName = super.processRequest(conn, context);
        String action = getAction(context);
d196 2
a197 1
            AccessControlList acl = loginUser.getACL();
d201 5
d208 11
a218 2
            if (DEBUG) Log.debug("ProjectMembershipRequest: got ticket: " 
                                 + ticket);
d220 4
a223 3
            try 
            {
                acl.assertPermission("Project Role - Request", currentProject);
d226 1
a226 5
                if (DEBUG)
                {
                    Log.debug
                    ("User is missing request role; checking for ticket.");
                }
a227 1
                {
d229 9
d239 2
a240 6

                invitation = InvitationPeer.getInstance(ticket);
                
                if (!invitation.isMatch(currentProject))
                {
                    Log.debug("User has no ticket.");
a241 1
                }
d245 4
a248 4
            String roleRequested = processField
            (context, REQUESTED_ROLE_FIELD, "Role", missingFields);

            //
d251 1
a251 1
            if(action != null)
d253 8
a260 1
                if (action.equals(SUBMIT_REQUEST_ACTION))
d262 29
a290 8
                    List validationErrors = new ArrayList();
                
                    // Check for missing fields or validation errors.  If
                    // we have any, go around again on this same form --
                    // displaying the problem w/ current form submission
                    // in the 'Message' field in the head of the form.
                    //
                    if (isValidUserInput(missingFields, validationErrors))
d292 9
a300 17
                        // We have all fields.  Request the role for the
                        // user.
                        Role role = (Role)RolePeer.getInstance(roleRequested);
                        boolean request = false;

                        //If they've already requested or already have this
                        //role, it's an error.
                        if (loginUser.getACL().hasRole(role, currentProject))
                        {
                            appendToError(context, 
                                          ROLE_ALREADY_GRANTED_ERROR);
                        }  else if (loginUser.hasRequestedRoleInProject
                                    (role, currentProject)) {
                            appendToError(context, 
                                          ROLE_ALREADY_REQUESTED_ERROR);
                        }
                        else
a301 12
                            //They want to request the role.
                            //TODO: Pass in ACL, or not, depending on whether
                            //or not they have a ticket.
                            loginUser.requestRole(role, currentProject);
                            
                            // for now, we're not deleting invitations
                            //if (invitation != null) {
                            //    if (DEBUG) Log.info("going to delete invitation");
                            //    invitation.delete();
                            //}
                            String redirectTo = getCurrentDomain(context)
                                .getDomainHomeServletURL("StartPage");
a302 1
                            redirectToURL(context, redirectTo);   
d304 7
d313 26
a338 6
            } 
        } catch (RedirectException e) {
            throw e;
        } catch (Exception e) {
            Log.error("Exception thrown in ProjectMembershipRequest", e);
            appendToError(context, e.getMessage());            
d340 1
d343 35
@


1.20.2.3
log
@Added new imports necessitated by Torque.
@
text
@a60 1
import org.tigris.helm.om.base.*;
@


1.19
log
@revert this stuff to its state as of 2001/01/24 12:42:00 GMT -- with
the following exceptions, which have some different modifications so
they'll work with changes which have happened in joist:

ProjectNewsEdit.java
SkinManager.java
SkinStyleElementValueManager.java
StyleElementManager.java
StyleManager.java

it compiles.  i dunno if it works, though.
@
text
@@


1.18
log
@Moved paginator stuff to its own directory.
@
text
@d126 1
a126 1
* @@version $Id: ProjectMembershipRequest.java,v 1.17 2000/12/14 03:04:17 edk Exp $
d136 1
a136 1
    public static final  String versionID = "$Id: ProjectMembershipRequest.java,v 1.17 2000/12/14 03:04:17 edk Exp $";
@


1.17
log
@* adjust for corrections to Role constructor
* correct another Role constructor which listed the DataManager before
  the Connection
@
text
@d71 1
d126 1
a126 1
* @@version $Id: ProjectMembershipRequest.java,v 1.16 2000/12/01 22:34:29 edk Exp $
d136 1
a136 1
    public static final  String versionID = "$Id: ProjectMembershipRequest.java,v 1.16 2000/12/01 22:34:29 edk Exp $";
@


1.16
log
@send people to the start page instead of the domain hope page
@
text
@d125 1
a125 1
* @@version $Id: ProjectMembershipRequest.java,v 1.15 2000/11/23 09:20:04 dlr Exp $
d135 1
a135 1
    public static final  String versionID = "$Id: ProjectMembershipRequest.java,v 1.15 2000/11/23 09:20:04 dlr Exp $";
d276 1
a276 1
                    Role role = new Role(dMgr, connection, roleRequested);
@


1.15
log
@Renamed other occurance of class.
@
text
@d125 1
a125 1
* @@version $Id: ProjectMembershipRequest.java,v 1.14 2000/11/23 09:19:38 dlr Exp $
d135 1
a135 1
    public static final  String versionID = "$Id: ProjectMembershipRequest.java,v 1.14 2000/11/23 09:19:38 dlr Exp $";
d297 1
a297 1
                            .getDomainHome();
@


1.14
log
@Renamed class.
@
text
@d125 3
a127 3
* @@version $Id: ProjectMembershipRequest.java,v 1.13 2000/11/22 06:09:20 edk Exp $
* @@see org.tigris.helm.domain.ProjectAdd This servlet is modeled on
* org.tigris.helm.domain.ProjectAdd
d135 1
a135 1
    public static final  String versionID = "$Id: ProjectMembershipRequest.java,v 1.13 2000/11/22 06:09:20 edk Exp $";
@


1.13
log
@provide better use guidance wrt new / unapproved projects: suggest
mailing the project owner (by replying) and provide a way for the
template to determine if the project is approved yet.
@
text
@d118 1
a118 1
*                 <pre>/home/stack/software/jdk1.3/bin/javadoc -d javadoc -classpath /home/stack/cvsroot/sandbox/site/lib/joist.jar:${CLASSPATH}  -sourcepath . org.tigris.helm.project.ProjectMembershipRequest org.tigris.helm.domain.SelfServeProjectAdd
d125 1
a125 1
* @@version $Id: ProjectMembershipRequest.java,v 1.12 2000/11/22 02:18:55 edk Exp $
d135 1
a135 1
    public static final  String versionID = "$Id: ProjectMembershipRequest.java,v 1.12 2000/11/22 02:18:55 edk Exp $";
@


1.12
log
@don't remove invitations after they're used.
@
text
@d125 1
a125 1
* @@version $Id: ProjectMembershipRequest.java,v 1.11 2000/11/22 01:51:09 edk Exp $
d135 1
a135 1
    public static final  String versionID = "$Id: ProjectMembershipRequest.java,v 1.11 2000/11/22 01:51:09 edk Exp $";
d199 6
d207 1
a207 1
            log.info("got ticket: " + ticket);
@


1.11
log
@new invitations stuff : if you have a valid ticket, you can request
roles, even if the project is private and you have none so far.
@
text
@d125 1
a125 1
* @@version $Id: ProjectMembershipRequest.java,v 1.10 2000/11/17 22:21:12 edk Exp $
d135 1
a135 1
    public static final  String versionID = "$Id: ProjectMembershipRequest.java,v 1.10 2000/11/17 22:21:12 edk Exp $";
d285 5
a289 4
                        if (invitation != null) {
                            if (debug) log.info("going to delete invitation");
                            invitation.delete();
                        }
@


1.10
log
@minor changes (mostly reformatting, one update) to javadocs
@
text
@d125 1
a125 1
* @@version $Id: ProjectMembershipRequest.java,v 1.9 2000/11/17 21:49:38 leonardr Exp $
d135 1
a135 1
    public static final  String versionID = "$Id: ProjectMembershipRequest.java,v 1.9 2000/11/17 21:49:38 leonardr Exp $";
d175 5
a181 5
    /** Key to pull projectID from query string
	*/
    private static final String PROJECTID_KEY = "projectID";
    
    
d197 39
a237 7
            
            /* 
               String projectID_Select = processField(context, 
               "projectSelect",
               "Project",
               missingFields);
            */
d271 11
a281 3
                    if(debug) log.info("Requesting role " + role.getName());
                    boolean request = loginUser.requestRole(acl, role, 
                                                            currentProject);
d285 4
@


1.9
log
@Implemented requestable roles and requesting roles in proprietary projects.
@
text
@d125 3
a127 2
* @@version $Id: ProjectMembershipRequest.java,v 1.8 2000/11/15 23:49:43 leonardr Exp $
* @@see org.tigris.helm.domain.SelfServeProjectAdd This servlet is modeled on org.tigris.helm.domain.SelfServeAddProject
d129 2
a130 1
public class ProjectMembershipRequest extends org.tigris.helm.security.HelmServlet 
d135 1
a135 1
    public static final  String versionID = "$Id: ProjectMembershipRequest.java,v 1.8 2000/11/15 23:49:43 leonardr Exp $";
d171 3
a173 2
    /** Key to pull 'action' from context w/ getForm()
	*/
d293 17
a309 16
    /** Read domain contents -- roles and projects -- and put them into the context.
    * 
    * Get domain object.  From this object, pull the list of projects and
    * roles.  Push them into context for the webmacro template to populate
    * the form with.
    * <p>
    * Talking to davidp, there should be a list of projects in the context.
    * We shouldn't be asking domain object for the project list in the webmacro
    * page directly in case of db exception; These are hard to handle
    * in a webmacro page. 
    *
    * @@param connection Database connection to use.
    * @@param context    Current request context.
    *
    * @@exception Exception
    */
@


1.8
log
@UpdateExceptions begone\!
@
text
@d125 1
a125 1
* @@version $Id: ProjectMembershipRequest.java,v 1.7 2000/11/15 23:05:27 elicia Exp $
d133 1
a133 1
    public static final  String versionID = "$Id: ProjectMembershipRequest.java,v 1.7 2000/11/15 23:05:27 elicia Exp $";
d242 8
a249 2
                        String projectHome = currentProject.getProjectHome();
                        redirectToURL(context, projectHome);   
@


1.7
log
@added UpdateException
@
text
@d17 1
a17 1
 * software developed by Collab.Net (http://www.Collab.Net/)."
d32 1
a32 1
 * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d125 1
a125 1
* @@version $Id: ProjectMembershipRequest.java,v 1.6 2000/11/15 22:48:40 leonardr Exp $
d133 1
a133 1
    public static final  String versionID = "$Id: ProjectMembershipRequest.java,v 1.6 2000/11/15 22:48:40 leonardr Exp $";
a273 5
            log.exception(e);
            String message = "" + e.getMessage();
            if(debug) log.info(message);
            appendToMessage(context, message);            
        } catch (UpdateException e) {
@


1.6
log
@Got rid of more superfluous UpdateException throwage.
@
text
@d70 1
d125 1
a125 1
* @@version $Id: ProjectMembershipRequest.java,v 1.5 2000/11/15 21:09:41 elicia Exp $
d133 1
a133 1
    public static final  String versionID = "$Id: ProjectMembershipRequest.java,v 1.5 2000/11/15 21:09:41 elicia Exp $";
d274 5
@


1.5
log
@added JoistException
@
text
@a70 1
import org.tigris.helm.tool.UpdateException;
d124 1
a124 1
* @@version $Id: ProjectMembershipRequest.java,v 1.4 2000/11/15 01:28:48 leonardr Exp $
d132 1
a132 1
    public static final  String versionID = "$Id: ProjectMembershipRequest.java,v 1.4 2000/11/15 01:28:48 leonardr Exp $";
a276 5
        } catch (UpdateException e) {
            log.exception(e);
            String message = "" + e.getMessage();
            if(debug) log.info(message);
            appendToMessage(context, message);            
d278 1
a278 3
    
        if(debug)
            log.info("done");
@


1.4
log
@Catch the newly thrown exception.
@
text
@d125 1
a125 1
* @@version $Id: ProjectMembershipRequest.java,v 1.3 2000/11/15 01:19:08 leonardr Exp $
d133 1
a133 1
    public static final  String versionID = "$Id: ProjectMembershipRequest.java,v 1.3 2000/11/15 01:19:08 leonardr Exp $";
d256 1
a256 2
            if(debug) 
                log.info(message);
d258 1
a258 1
        } catch (DataSetException e) {
d263 1
a263 1
        } catch (JoistDatabaseException e) {
d267 2
a268 2
            appendToMessage(context, message);            
        } catch (JoistException e) {
@


1.3
log
@Send mail to project owners when someone requests a role in a project.
@
text
@d125 1
a125 1
* @@version $Id: ProjectMembershipRequest.java,v 1.2 2000/11/13 19:18:49 leonardr Exp $
d133 1
a133 1
    public static final  String versionID = "$Id: ProjectMembershipRequest.java,v 1.2 2000/11/13 19:18:49 leonardr Exp $";
d265 5
@


1.2
log
@Fixed project deletion and ProjectMembershipRequest
@
text
@d125 1
a125 1
* @@version $Id: ProjectMembershipRequest.java,v 1.1.1.1 2000/11/12 21:16:13 dlr Exp $
d133 1
a133 1
    public static final  String versionID = "$Id: ProjectMembershipRequest.java,v 1.1.1.1 2000/11/12 21:16:13 dlr Exp $";
a242 2
                        if(debug)
                            log.info("Done. Redirecting: " + projectHome);
@


1.1
log
@Initial revision
@
text
@d63 2
a64 2
import org.joist.security.RedirectException;
import org.joist.database.DataManager;
d66 4
a69 8
import org.tigris.helm.database.DomainManager;
import org.tigris.helm.database.ProjectManager;
import org.tigris.helm.database.UserRoleProjectManager;
import org.tigris.helm.security.AccessControlList;
import org.tigris.helm.security.HelmServlet;
import org.tigris.helm.domain.Domain;
import org.tigris.helm.domain.Role;
import org.tigris.helm.domain.User;
d71 1
d125 1
a125 1
* @@version $Id: ProjectMembershipRequest.java,v 1.33 2000/11/11 03:46:37 edk Exp $
d133 1
a133 1
    public static final  String versionID = "$Id: ProjectMembershipRequest.java,v 1.33 2000/11/11 03:46:37 edk Exp $";
d183 1
a183 1
        throws HandlerException, RedirectException
a184 3
        if (debug) 
            log.info("started!");

a185 1

d187 1
a187 5
        String projectID = (String)context.getForm(PROJECTID_KEY); 

        if (debug) 
            log.info("action=" + action);
            
d190 5
d196 1
a196 1

d204 3
a206 11
                                             ROLES_CONTEXT_KEY,
                                             "Role",
                                             missingFields);
                                            
            SessionManager sMgr = getSessionManager(context);
            String userID = sMgr.getUserID();
            if(debug) 
                log.info("userID=" + userID);
                
            readDomainIntoContext(connection, context);
            
d212 5
a216 5

                // Check for missing fields or validation errors.  If we
                // have any, go around again on this same form -- displaying
                // the problem w/ current form submission in the 'Message' field
                // in the head of the form.
d224 1
a224 3
                }
                else if(!validationErrors.isEmpty())
                {
a234 1
                    User user = getLoginUser(context);
a235 1
                    Project project = getCurrentProject(context);
d237 3
a239 3
                    AccessControlList acl = getACL(context, connection);
                    boolean request = user.requestRole(acl, role, project);
                    
d242 1
a242 1
                        String projectHome = project.getProjectHome();
d246 1
a246 3
                    }
                    else
                    {
d255 1
a255 4
        }
    
        catch (Exception e) 
        {
d261 21
a281 1
        }    
d305 4
a308 2
    private void readDomainIntoContext(Connection connection, WebContext context)
        throws Exception
d310 1
a310 2

        List roles = super.getCurrentDomain(context).getRoles();
@


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
@@


1.1.1.2
log
@Replacing the HEAD with the HELM_PEER_PORT_BRANCH.
@
text
@d2 1
a2 1
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
d17 1
a17 1
 * software developed by CollabNet (http://www.collab.net/)."
d32 1
a32 1
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d49 5
a53 2
import java.sql.Connection;
import java.util.*;
d55 1
d58 1
a58 1
import org.apache.turbine.util.Log;
d60 3
d64 1
d66 66
a131 6
import org.tigris.helm.security.*;
import org.tigris.helm.om.*;
import org.tigris.helm.om.peer.*;
import org.tigris.helm.om.base.*;

public class ProjectMembershipRequest extends HelmServlet 
d133 9
d146 2
a147 2
    private static boolean DEBUG = true;
            
d149 4
a152 1
     * Field indicating the requested role.
d154 3
a156 2
    public final static String REQUESTED_ROLE_FIELD = "role";

d158 4
a161 1
     * Key to pull the invitation/ticket w/ getForm()
d163 1
a163 1
    private static final String TICKET_KEY = "ticket";
d170 12
a181 1
        
d183 1
a183 1
     * Action for role requesting.
d185 5
a189 1
    private static final String SUBMIT_REQUEST_ACTION="Submit Request";
d191 1
a191 6
    /**
     * Error to display if someone requests a role they already hold
     * (not a likely occurance since such roles are not shown.)
     */    	
    private static final String ROLE_ALREADY_REQUESTED_ERROR =
        "You have already requested this role in this project. You will receive email once your request has been processed.";
d193 2
a194 6
    /**
     * Error to display if someone requests a role they already hold
     * (not a likely occurance since such roles are not shown.)
     */    	
    private static final String ROLE_ALREADY_GRANTED_ERROR =
        "You already have this role in this project.";
d196 3
a198 9
    /**
     * Display and process the Project Membership Request screen
     */
    protected String processRequest (Connection conn, WebContext context)
        throws HandlerException, RedirectException
    {
        String templateName = super.processRequest(conn, context);
        String action = getAction(context);
        
d201 1
a201 10
            Project currentProject = getCurrentProject(context);
            User loginUser = getLoginUser(context);
            AccessControlList acl = loginUser.getACL();
            Invitation invitation = null;
            String ticket = processField(context, TICKET_KEY);

            if (ticket != null && !ticket.equals(""))
                context.put("ticket", ticket);
            if (DEBUG) Log.debug("ProjectMembershipRequest: got ticket: " 
                                 + ticket);
d203 21
a223 1
            try 
d225 8
a232 4
                acl.assertPermission("Project Role - Request", currentProject);
            } catch (ACLException e) {
                // see if they have a valid ticket / invitation
                if (DEBUG)
d234 4
a237 2
                    Log.debug
                    ("User is missing request role; checking for ticket.");
d239 1
a239 1
                if (ticket == null || ticket.equals(""))
d241 5
a245 1
                    throw e;
d247 1
a247 4

                invitation = InvitationPeer.getInstance(ticket);
                
                if (!invitation.isMatch(currentProject))
d249 17
a265 24
                    Log.debug("User has no ticket.");
                    throw e;
                }
            }

            List missingFields = new ArrayList();
            String roleRequested = processField
            (context, REQUESTED_ROLE_FIELD, "Role", missingFields);

            //
            // Switch on the action
            //
            if(action != null)
            {
                if (action.equals(SUBMIT_REQUEST_ACTION))
                {
                    List validationErrors = new ArrayList();
                
                    // Check for missing fields or validation errors.  If
                    // we have any, go around again on this same form --
                    // displaying the problem w/ current form submission
                    // in the 'Message' field in the head of the form.
                    //
                    if (isValidUserInput(missingFields, validationErrors))
d267 5
a271 33
                        // We have all fields.  Request the role for the
                        // user.
                        Role role = (Role)RolePeer.getInstance(roleRequested);
                        boolean request = false;

                        //If they've already requested or already have this
                        //role, it's an error.
                        if (loginUser.getACL().hasRole(role, currentProject))
                        {
                            appendToError(context, 
                                          ROLE_ALREADY_GRANTED_ERROR);
                        }  else if (loginUser.hasRequestedRoleInProject
                                    (role, currentProject)) {
                            appendToError(context, 
                                          ROLE_ALREADY_REQUESTED_ERROR);
                        }
                        else
                        {
                            //They want to request the role.
                            //TODO: Pass in ACL, or not, depending on whether
                            //or not they have a ticket.
                            loginUser.requestRole(role, currentProject);
                            
                            // for now, we're not deleting invitations
                            //if (invitation != null) {
                            //    if (DEBUG) Log.info("going to delete invitation");
                            //    invitation.delete();
                            //}
                            String redirectTo = getCurrentDomain(context)
                                .getDomainHomeServletURL("StartPage");
                            redirectTo = currentProject.getProjectHome();
                            redirectToURL(context, redirectTo);   
                        }
d274 1
a274 6
            } 
        } catch (RedirectException e) {
            throw e;
        } catch (Exception e) {
            Log.error("Exception thrown in ProjectMembershipRequest", e);
            appendToError(context, e.getMessage());            
d276 12
d290 33
@

