head	1.18;
access;
symbols
	TIGRIS_1_1_0RC2:1.10.6.3
	TIGRIS_1_1_0RC1:1.10.6.3
	TIGRIS_1_1:1.10.6.3.0.2
	TIGRIS_1_0_8:1.10.6.3
	TIGRIS_1_0_8RC3:1.10.6.3
	TIGRIS_1_0_8RC2:1.10.6.3
	TIGRIS_1_0_8RC1:1.10.6.3
	TIGRIS_1_0_7:1.10.6.3
	TIGRIS_1_0_7RC3:1.10.6.3
	TIGRIS_1_0_7RC2:1.10.6.3
	TIGRIS_1_0_7RC1:1.10.6.3
	TIGRIS_1_0_6:1.10.6.3
	TIGRIS_1_0_6RC5:1.10.6.3
	TIGRIS_1_0_6RC4:1.10.6.3
	TIGRIS_1_0_6RC3:1.10.6.3
	TIGRIS_1_0_6RC2:1.10.6.3
	TIGRIS_1_0_6RC1:1.10.6.3
	TIGRIS_1_0_5:1.10.6.2
	TIGRIS_1_0_5RC6:1.10.6.2
	TIGRIS_1_0_5RC5:1.10.6.2
	TIGRIS_1_0_5RC4:1.10.6.2
	TIGRIS_1_0_5RC3:1.10.6.2
	TIGRIS_1_0_5RC2:1.10.6.2
	TIGRIS_1_0_5RC1:1.10
	TIGRIS_1_0_4:1.10
	TIGRIS_1_0_3:1.10
	TIGRIS_1_0_2:1.10
	TIGRIS_1_0_1:1.10
	TIGRIS_1_0:1.10.0.6
	TIGRIS_1_0_0:1.10
	TIGRIS_1_0_0_RC1:1.10.0.2
	dlr:1.1.1
	HELM_PEER_PORT_BRANCH:1.1.1.1;
locks; strict;
comment	@# @;


1.18
date	2001.08.11.09.08.04;	author dlr;	state Exp;
branches;
next	1.17;

1.17
date	2001.07.30.19.29.57;	author leonardr;	state Exp;
branches;
next	1.16;

1.16
date	2001.07.25.19.39.26;	author leonardr;	state Exp;
branches;
next	1.15;

1.15
date	2001.06.18.22.12.20;	author leonardr;	state Exp;
branches;
next	1.14;

1.14
date	2001.06.13.17.30.16;	author leonardr;	state Exp;
branches;
next	1.13;

1.13
date	2001.05.17.14.51.17;	author leonardr;	state Exp;
branches;
next	1.12;

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

1.11
date	2001.05.02.08.11.04;	author dlr;	state Exp;
branches;
next	1.10;

1.10
date	2001.03.20.17.57.09;	author leonardr;	state Exp;
branches
	1.10.6.1;
next	1.9;

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

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

1.7
date	2001.03.07.01.53.22;	author lucas;	state Exp;
branches;
next	1.6;

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

1.5
date	2001.02.26.22.03.25;	author leonardr;	state Exp;
branches;
next	1.4;

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

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

1.2
date	2001.02.21.03.02.22;	author edk;	state Exp;
branches;
next	1.1;

1.1
date	2001.01.30.23.57.51;	author leonardr;	state dead;
branches
	1.1.1.1
	1.1.2.1;
next	;

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

1.1.2.1
date	2001.01.30.23.57.51;	author leonardr;	state Exp;
branches;
next	1.1.2.2;

1.1.2.2
date	2001.01.31.01.00.54;	author dlr;	state Exp;
branches;
next	1.1.2.3;

1.1.2.3
date	2001.02.05.17.04.46;	author leonardr;	state Exp;
branches;
next	1.1.2.4;

1.1.2.4
date	2001.02.06.18.54.00;	author leonardr;	state Exp;
branches;
next	1.1.2.5;

1.1.2.5
date	2001.02.12.15.09.40;	author leonardr;	state Exp;
branches;
next	1.1.2.6;

1.1.2.6
date	2001.02.12.16.24.32;	author leonardr;	state Exp;
branches;
next	1.1.2.7;

1.1.2.7
date	2001.02.12.16.32.38;	author leonardr;	state Exp;
branches;
next	1.1.2.8;

1.1.2.8
date	2001.02.12.16.39.12;	author leonardr;	state Exp;
branches;
next	1.1.2.9;

1.1.2.9
date	2001.02.12.17.14.23;	author leonardr;	state Exp;
branches;
next	1.1.2.10;

1.1.2.10
date	2001.02.12.17.18.41;	author leonardr;	state Exp;
branches;
next	1.1.2.11;

1.1.2.11
date	2001.02.13.03.12.17;	author dlr;	state Exp;
branches;
next	1.1.2.12;

1.1.2.12
date	2001.02.13.03.39.46;	author leonardr;	state Exp;
branches;
next	1.1.2.13;

1.1.2.13
date	2001.02.13.21.27.47;	author leonardr;	state Exp;
branches;
next	1.1.2.14;

1.1.2.14
date	2001.02.14.23.20.29;	author leonardr;	state Exp;
branches;
next	1.1.2.15;

1.1.2.15
date	2001.02.15.20.09.32;	author leonardr;	state Exp;
branches;
next	1.1.2.16;

1.1.2.16
date	2001.02.15.20.50.38;	author leonardr;	state Exp;
branches;
next	1.1.2.17;

1.1.2.17
date	2001.02.16.02.42.41;	author leonardr;	state Exp;
branches;
next	1.1.2.18;

1.1.2.18
date	2001.02.16.03.01.27;	author dlr;	state Exp;
branches;
next	1.1.2.19;

1.1.2.19
date	2001.02.16.16.09.07;	author leonardr;	state Exp;
branches;
next	1.1.2.20;

1.1.2.20
date	2001.02.16.16.26.36;	author leonardr;	state Exp;
branches;
next	;

1.10.6.1
date	2001.05.15.23.49.52;	author edk;	state Exp;
branches;
next	1.10.6.2;

1.10.6.2
date	2001.05.16.00.29.29;	author leonardr;	state Exp;
branches;
next	1.10.6.3;

1.10.6.3
date	2001.05.24.23.31.09;	author leonardr;	state Exp;
branches;
next	;


desc
@@


1.18
log
@Upgrading to Turbine 3.0-dev, Fulcrum 1.0, and Torque 1.0.
@
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.om;

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

//import org.apache.commons.util.*;
import org.apache.commons.util.exception.NestableException;
import org.apache.torque.util.Criteria;

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

import org.tigris.helm.AlreadyExists;
import org.tigris.helm.om.profile.*;
import org.tigris.helm.om.*;
import org.tigris.helm.tool.audit.AuditLog;
import org.tigris.helm.tool.paginate.PeerBackedList;

public class UserGroup extends User
{
    /**
     * Description of the audit log entry created when a user of this
     * type is added.  
     */
    private static final String AUDIT_LOG_ON_ADD = "User group added: ";

    /**
     * Description of the audit log entry created when a user of this
     * type is deleted.
     */
    private static final String AUDIT_LOG_ON_DELETE = "User group deleted: ";

    /**
     * Description of the audit log entry created when a user of this
     * type is edited.
     */
    private static final String AUDIT_LOG_ON_EDIT = "User group edited: ";

    /**
     * Description of the audit log entry created when a user of this
     * type is granted a role.
     */
    private static final String AUDIT_LOG_ON_ROLE_GRANT = 
        "Role granted to user group: ";

    /**
     * Description of the audit log entry created when a role is
     * revoked from a user of this type.  
     */
    private static final String AUDIT_LOG_ON_ROLE_REVOKE = 
        "Role revoked from user group: ";

    /**
     * Description of the audit log entry created when a user is added
     * to this group.
     */
    private static final String AUDIT_LOG_ON_USER_ADD = "User added to user group: ";

    /**
     * Description of the audit log entry created when a user is removed
     * from this group.
     */
    private static final String AUDIT_LOG_ON_USER_REMOVE = 
        "User removed from user group: ";

    //
    // Accessor methods
    //
   
    /**
     * Returns a paginatable list of users in this group.
     */
    public PeerBackedList getUsers(Integer itemsPerPage, Criteria filter)
        throws Exception
    {
        List users = new ArrayList();

        //Get the users who are elements of this user group.
        Criteria base = new Criteria()
            .addJoin(UserPeer.USER_ID, UserUsergroupPeer.USER_ID)
            .add(UserUsergroupPeer.USER_GROUP_ID, getID());
        return new PeerBackedList(UserPeer.class, 
                                  itemsPerPage, base, filter);
    }

    /**
     * Returns all the users in this group.
     */
    public List getUsers()
        throws Exception
    {
        return getUsers(new Integer(0), HelmPeer.NO_CRITERIA);
    }

    /**
     * Returns the number of users in this group.
     */
    public int getNumberOfUsers()
        throws Exception
    {
        return getUsers().size();
    }

    /**
     * Overrides the base User expand(). Returns all the users equivalent
     * to this user.
     */
    public List expand()
        throws Exception
    {
        return getUsers();
    }

    /**
     * Returns true iff this group contains the given user.
     */
    public boolean containsUser(User u)
        throws Exception
    {
        Criteria c = new Criteria()
            .add(UserUsergroupPeer.USER_ID, u.getID())
            .add(UserUsergroupPeer.USER_GROUP_ID, getID());
        return !UserUsergroupPeer.doSelect(c).isEmpty();
    }

    /**
     * Returns the name of the user group.
     */
    public String getName() 
    {
        return getLoginName();
    }

    /**
     * Returns the description of the user group.
     */
    public String getDescription() 
    {
        return super.getRealName();
    }

    //
    // Mutator methods.
    //

    public UserGroup()
    {
        setType(UserPeer.CLASSKEY_GROUP);
    }

    public static UserGroup add(AccessControlList acl, Domain domain,
                                String name)
        throws AlreadyExists, Exception
    {
        return add(acl, domain, name, "", new ArrayList());
    }

    public static UserGroup add(AccessControlList acl, Domain domain, 
                                String name, String description, List elements)
        throws AlreadyExists, Exception
    {        
        User.assertNonexistance(domain, name);
        UserGroup g = new UserGroup();
        g.setDomainId(domain.getID());
        g.setLoginName(name);
        g.setRealName(description);   
        g.assertAddPermission(acl, false);    
        g.save();

        //Add the user to the appropriate user group.
        g.addToDomainGroup();

        //Add the initial elements to the group.
        if (elements != null)
        {
            for (Iterator i = elements.iterator(); i.hasNext();)
            {
                User u = (User)i.next();
                g.addUser(acl, u);
            }        
        }
        return g;
    }
        
    /**
     * Add a user to this user group. Does nothing if the user is
     * already in the group.  Performs <code>save()</code> internally.
     */
    public void addUser(AccessControlList acl, User user)
        throws ACLException, Exception
    {
        user.assertNondeletion();

        if (!containsUser(user))
        {
            acl.assertPermission
                ("UserGroup Element - Add", getDomain());
            if (!user.isBase() && !(isHost() || isDomain()))
            {
                throw new NestableException
                    ("User-created user groups cannot themselves contain user groups.");
            }
            UserUsergroup mapping = new UserUsergroup();
            mapping.setUserId(user.getUserId());
            mapping.setUserGroupId(getUserId());
            mapping.save();

            AccessControlList.rebuildACL(user);

            AuditLog.logEvent
                (acl.getUser(), getDomain(), 
                 this.AUDIT_LOG_ON_USER_ADD + getName() 
                 + " <- " + user.getLoginName());
        }
    }

    /**
     * Remove a user from this user group. Does nothing if the user is
     * not already in the group.  
     */
    public void removeUser(AccessControlList acl, User user)
        throws ACLException, Exception
    {
        user.assertNondeletion();
        if (containsUser(user))
        {
            acl.assertPermission
                ("UserGroup Element - Delete", getDomain());
            
            Criteria c = new Criteria()
                .add(UserUsergroupPeer.USER_ID, user.getUserId())
                .add(UserUsergroupPeer.USER_GROUP_ID, getUserId());
            UserUsergroupPeer.doDelete(c);
                        
            //Invalidate the removed user's ACL.
            AccessControlList.rebuildACL(user);

            AuditLog.logEvent
                (acl.getUser(), getDomain(), this.AUDIT_LOG_ON_USER_REMOVE 
                 + getName() + " -> " + user.getLoginName());
        }
    }            

    /**
     * Changes the information (just description for now) of a usergroup.
     */
    public void updateInfo(AccessControlList acl, String description)
        throws ACLException, Exception
    {
        assertEditPermission(acl);
        setRealName(description);
        save();
    }

    /**
     * Totally deletes a user group.
     */
    public void delete(AccessControlList acl)
        throws ACLException, Exception
    {
        assertDeletePermission(acl);

        //Remove all users from this group.
        for (Iterator i = getUsers().iterator(); i.hasNext();)
        {
            removeUser(acl, (User)i.next());
        }

        //Remove the group proper.
        super.delete(acl);
    }
    
}



@


1.17
log
@Stop coddling IZ in terms of user accounts; assume that IZ can get its permissions from Helm through the XML-RPC interface.
@
text
@d52 3
a54 2
import org.apache.turbine.util.db.Criteria;
import org.apache.turbine.util.*;
a66 1

d246 1
a246 1
                throw new TurbineException
@


1.16
log
@User deletes are now soft deletes which change the user type to 'deleted' (a minimal type of user which has user information but is not allowed associations with roles or user groups). Includes some other miscellaneous bug fixes.
@
text
@a255 7
            List projects = getAllProjectsWithApprovedRole();
            for (Iterator i = projects.iterator(); i.hasNext();)
            {
                Project p = (Project)i.next();
                p.rebuildIssueTracking();
            }

d281 1
a281 1
            //Invalidate the removed user's ACL, and run scripts.
a282 6
            List projects = getAllProjectsWithApprovedRole();
            for (Iterator i = projects.iterator(); i.hasNext();)
            {
                Project p = (Project)i.next();
                p.rebuildIssueTracking();
            }
@


1.15
log
@Huge patch of the day: Got rid of redundant HELM_DOMAIN table. The project representation of the domain and the host is now the canonical one. Host and Domain now subclass ProjectGroup. The canonical representation of a project's membership in a domain group is now the corresponding mapping in HELM_PROJECT_PROJECTGROUP. Schema changes: No more HELM_DOMAIN table (obviously); no more DOMAIN_ID in HELM_PROJECT; HELM_USER and HELM_VC_VIEW now have foreign keys in HELM_PROJECT instead of HELM_DOMAIN.
@
text
@d238 2
d277 1
@


1.14
log
@Added more places where unapproved roles are filtered out.
@
text
@d210 1
a210 1
        g.setDomainId(domain.getDomainId());
@


1.13
log
@Refactored a lot of code to get rid of the good-looking but very slow IssueTrackingAccount{Descriptor,Map} classes. Also cleaned up the script-running interface quite a bit.
@
text
@d254 1
a254 1
            List projects = getAllProjectsWithRole();
d287 1
a287 1
            List projects = getAllProjectsWithRole();
@


1.12
log
@remove setDistinct from a call where it appears to be unnecessary
(it appears this can cause problems)
@
text
@a61 1
import org.tigris.helm.tool.task.IssueTrackingAccountDescriptor;
a172 16
     * Returns an IssueTrackingAccountDescriptor describing the
     * current state of the given user as regards the projects in
     * which this user group has a role.
     */
    public IssueTrackingAccountDescriptor getDescriptorForUser(User baseUser)
        throws Exception
    {
        //All projects in which this usergroup has a role are affected
        Criteria c = new Criteria()
            .addJoin(ProjectPeer.PROJECT_ID, UserRoleProjectPeer.PROJECT_ID)
            .add(UserRoleProjectPeer.USER_ID, getUserId());
        List projects = ProjectPeer.doSelect(c);
        return new IssueTrackingAccountDescriptor(projects, baseUser);
    }

    /**
a246 1
            IssueTrackingAccountDescriptor before = getDescriptorForUser(user);
d251 1
a251 2
            
            //UserGroupPeer.buildUserGroups();
d253 8
a260 2
            IssueTrackingAccountDescriptor after = getDescriptorForUser(user);
            before.syncTo(after, acl.getUser());
a278 1
            IssueTrackingAccountDescriptor before = getDescriptorForUser(user);
d284 1
a284 3
            
            //UserGroupPeer.buildUserGroups(conn, dMgr);        
            
d287 7
a293 2
            IssueTrackingAccountDescriptor after = getDescriptorForUser(user);
            before.syncTo(after, acl.getUser());
@


1.11
log
@Corrected getAttributes() call in Role and made use of HelmPeer's new NO_CRITERIA constant.
@
text
@a128 1
        base.setDistinct();
@


1.10
log
@Updated method call.
@
text
@d140 1
a140 1
        return getUsers(new Integer(0), new Criteria(0));
@


1.10.6.1
log
@remove setDistinct from a call where it appears to be unnecessary
(it appears this can cause problems).  ported from the HEAD.
@
text
@d129 1
@


1.10.6.2
log
@Use Project.rebuildIssueTracking rather than using an IssueTrackingAccountdescriptor.
@
text
@d62 1
d174 16
d264 1
d270 1
d272 2
a273 8

            List projects = getAllProjectsWithRole();
            for (Iterator i = projects.iterator(); i.hasNext();)
            {
                Project p = (Project)i.next();
                p.rebuildIssueTracking(acl);
            }

d292 1
d303 2
a304 8

            List projects = getAllProjectsWithRole();
            for (Iterator i = projects.iterator(); i.hasNext();)
            {
                Project p = (Project)i.next();
                p.rebuildIssueTracking(acl);
            }

@


1.10.6.3
log
@Ported task running system in from HEAD.
@
text
@d258 1
a258 1
                p.rebuildIssueTracking();
d294 1
a294 1
                p.rebuildIssueTracking();
@


1.9
log
@User-created groups cannot themselves contain groups.
@
text
@d231 1
a231 1
        g.assertAddPermission(acl);    
@


1.8
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.apache.turbine.util.Log;
d260 5
@


1.7
log
@Corrected regex madness for Torque upgrade.  -dlr
@
text
@d125 1
a125 1
        //Get the users with membership in this user group.
d223 1
a223 1
                                String name, String description, List members)
a226 1
        Log.debug("OK To go ahead.");
d237 2
a238 2
        //Add the initial members to the group.
        if (members != null)
d240 1
a240 1
            for (Iterator i = members.iterator(); i.hasNext();)
d259 1
a259 1
                ("UserGroup Member - Add", getDomain());
d287 1
a287 1
                ("UserGroup Member - Delete", getDomain());
@


1.6
log
@Noted an oddity.
@
text
@d60 1
a60 2
import org.tigris.helm.om.peer.*;
import org.tigris.helm.om.base.*;
@


1.5
log
@Almost got rid of dependance on hacky one-argument IssueTrackingAccountDescriptor.syncto().
@
text
@d253 1
a253 1
     * already in the group.  
@


1.4
log
@How about actually removing them from the group.
@
text
@d271 1
a271 1
            before.syncTo(after);
@


1.3
log
@Minor cleanup.
@
text
@d292 5
@


1.2
log
@adding files from the branch to the head
@
text
@d126 1
a126 1
        //Get the mappings of users to this user group.
d130 1
d264 2
a265 2
            mapping.setUserId(user.getPrimaryKeyAsInt());
            mapping.setUserGroupId(getPrimaryKeyAsInt());
@


1.1
log
@file UserGroup.java was initially added on branch HELM_PEER_PORT_BRANCH.
@
text
@d1 335
@


1.1.1.1
log
@Replacing the HEAD with the HELM_PEER_PORT_BRANCH.
@
text
@a0 335
/* ================================================================
 * 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.om;

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

import org.apache.turbine.util.db.Criteria;
import org.apache.turbine.util.Log;

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

import org.tigris.helm.AlreadyExists;
import org.tigris.helm.om.profile.*;
import org.tigris.helm.om.peer.*;
import org.tigris.helm.om.base.*;
import org.tigris.helm.tool.audit.AuditLog;
import org.tigris.helm.tool.task.IssueTrackingAccountDescriptor;
import org.tigris.helm.tool.paginate.PeerBackedList;

public class UserGroup extends User
{

    /**
     * Description of the audit log entry created when a user of this
     * type is added.  
     */
    private static final String AUDIT_LOG_ON_ADD = "User group added: ";

    /**
     * Description of the audit log entry created when a user of this
     * type is deleted.
     */
    private static final String AUDIT_LOG_ON_DELETE = "User group deleted: ";

    /**
     * Description of the audit log entry created when a user of this
     * type is edited.
     */
    private static final String AUDIT_LOG_ON_EDIT = "User group edited: ";

    /**
     * Description of the audit log entry created when a user of this
     * type is granted a role.
     */
    private static final String AUDIT_LOG_ON_ROLE_GRANT = 
        "Role granted to user group: ";

    /**
     * Description of the audit log entry created when a role is
     * revoked from a user of this type.  
     */
    private static final String AUDIT_LOG_ON_ROLE_REVOKE = 
        "Role revoked from user group: ";

    /**
     * Description of the audit log entry created when a user is added
     * to this group.
     */
    private static final String AUDIT_LOG_ON_USER_ADD = "User added to user group: ";

    /**
     * Description of the audit log entry created when a user is removed
     * from this group.
     */
    private static final String AUDIT_LOG_ON_USER_REMOVE = 
        "User removed from user group: ";

    //
    // Accessor methods
    //
   
    /**
     * Returns a paginatable list of users in this group.
     */
    public PeerBackedList getUsers(Integer itemsPerPage, Criteria filter)
        throws Exception
    {
        List users = new ArrayList();

        //Get the mappings of users to this user group.
        Criteria base = new Criteria()
            .addJoin(UserPeer.USER_ID, UserUsergroupPeer.USER_ID)
            .add(UserUsergroupPeer.USER_GROUP_ID, getID());
        return new PeerBackedList(UserPeer.class, 
                                  itemsPerPage, base, filter);
    }

    /**
     * Returns all the users in this group.
     */
    public List getUsers()
        throws Exception
    {
        return getUsers(new Integer(0), new Criteria(0));
    }

    /**
     * Returns the number of users in this group.
     */
    public int getNumberOfUsers()
        throws Exception
    {
        return getUsers().size();
    }

    /**
     * Overrides the base User expand(). Returns all the users equivalent
     * to this user.
     */
    public List expand()
        throws Exception
    {
        return getUsers();
    }

    /**
     * Returns true iff this group contains the given user.
     */
    public boolean containsUser(User u)
        throws Exception
    {
        Criteria c = new Criteria()
            .add(UserUsergroupPeer.USER_ID, u.getID())
            .add(UserUsergroupPeer.USER_GROUP_ID, getID());
        return !UserUsergroupPeer.doSelect(c).isEmpty();
    }

    /**
     * Returns an IssueTrackingAccountDescriptor describing the
     * current state of the given user as regards the projects in
     * which this user group has a role.
     */
    public IssueTrackingAccountDescriptor getDescriptorForUser(User baseUser)
        throws Exception
    {
        //All projects in which this usergroup has a role are affected
        Criteria c = new Criteria()
            .addJoin(ProjectPeer.PROJECT_ID, UserRoleProjectPeer.PROJECT_ID)
            .add(UserRoleProjectPeer.USER_ID, getUserId());
        List projects = ProjectPeer.doSelect(c);
        return new IssueTrackingAccountDescriptor(projects, baseUser);
    }

    /**
     * Returns the name of the user group.
     */
    public String getName() 
    {
        return getLoginName();
    }

    /**
     * Returns the description of the user group.
     */
    public String getDescription() 
    {
        return super.getRealName();
    }

    //
    // Mutator methods.
    //

    public UserGroup()
    {
        setType(UserPeer.CLASSKEY_GROUP);
    }

    public static UserGroup add(AccessControlList acl, Domain domain,
                                String name)
        throws AlreadyExists, Exception
    {
        return add(acl, domain, name, "", new ArrayList());
    }

    public static UserGroup add(AccessControlList acl, Domain domain, 
                                String name, String description, List members)
        throws AlreadyExists, Exception
    {        
        User.assertNonexistance(domain, name);
        Log.debug("OK To go ahead.");
        UserGroup g = new UserGroup();
        g.setDomainId(domain.getDomainId());
        g.setLoginName(name);
        g.setRealName(description);   
        g.assertAddPermission(acl);    
        g.save();

        //Add the user to the appropriate user group.
        g.addToDomainGroup();

        //Add the initial members to the group.
        if (members != null)
        {
            for (Iterator i = members.iterator(); i.hasNext();)
            {
                User u = (User)i.next();
                g.addUser(acl, u);
            }        
        }
        return g;
    }
        
    /**
     * Add a user to this user group. Does nothing if the user is
     * already in the group.  
     */
    public void addUser(AccessControlList acl, User user)
        throws ACLException, Exception
    {
        if (!containsUser(user))
        {
            acl.assertPermission
                ("UserGroup Member - Add", getDomain());
            IssueTrackingAccountDescriptor before = getDescriptorForUser(user);
            UserUsergroup mapping = new UserUsergroup();
            mapping.setUserId(user.getPrimaryKeyAsInt());
            mapping.setUserGroupId(getPrimaryKeyAsInt());
            mapping.save();
            
            //UserGroupPeer.buildUserGroups();
            AccessControlList.rebuildACL(user);
            IssueTrackingAccountDescriptor after = getDescriptorForUser(user);
            before.syncTo(after);
            AuditLog.logEvent
                (acl.getUser(), getDomain(), 
                 this.AUDIT_LOG_ON_USER_ADD + getName() 
                 + " <- " + user.getLoginName());
        }
    }

    /**
     * Remove a user from this user group. Does nothing if the user is
     * not already in the group.  
     */
    public void removeUser(AccessControlList acl, User user)
        throws ACLException, Exception
    {
        if (containsUser(user))
        {
            acl.assertPermission
                ("UserGroup Member - Delete", getDomain());
            IssueTrackingAccountDescriptor before = getDescriptorForUser(user);
            
            //UserGroupPeer.buildUserGroups(conn, dMgr);        
            
            //Invalidate the removed user's ACL, and run scripts.
            AccessControlList.rebuildACL(user);
            IssueTrackingAccountDescriptor after = getDescriptorForUser(user);
            before.syncTo(after, acl.getUser());
            AuditLog.logEvent
                (acl.getUser(), getDomain(), this.AUDIT_LOG_ON_USER_REMOVE 
                 + getName() + " -> " + user.getLoginName());
        }
    }            

    /**
     * Changes the information (just description for now) of a usergroup.
     */
    public void updateInfo(AccessControlList acl, String description)
        throws ACLException, Exception
    {
        assertEditPermission(acl);
        setRealName(description);
        save();
    }

    /**
     * Totally deletes a user group.
     */
    public void delete(AccessControlList acl)
        throws ACLException, Exception
    {
        assertDeletePermission(acl);

        //Remove all users from this group.
        for (Iterator i = getUsers().iterator(); i.hasNext();)
        {
            removeUser(acl, (User)i.next());
        }

        //Remove the group proper.
        super.delete(acl);
    }
    
}



@


1.1.2.1
log
@Port of UserGroup.
@
text
@a0 237
/* ================================================================
 * Copyright (c) 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.om;

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

import org.webmacro.util.*;

import org.apache.turbine.util.db.Criteria;

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

import org.tigris.helm.AlreadyExists;
import org.tigris.helm.om.profile.*;
import org.tigris.helm.om.peer.UserUsergroupPeer;
import org.tigris.helm.om.peer.UserPeer;

public class UserGroup extends User
{
    private static Log log = new Log("userGrp", "UserGroup");

    ////////////////////////////////////////////////////////////////////
    // Constructors.
    ////////////////////////////////////////////////////////////////////

    public static UserGroup add(AccessControlList acl, Domain domain,
                                String name)
        throws AlreadyExists, Exception
    {
        return add(acl, domain, name, "", new ArrayList());
    }

    public static UserGroup add(AccessControlList acl, Domain domain, 
                                String name, String description, List members)
        throws AlreadyExists, Exception
    {
        UserGroup g = User.add(acl, domain, description, name, User.GROUP_TYPE).asGroup();

        //Add the initial members to the group.
        if (members != null)
        {
            for (Iterator i = members.iterator(); i.hasNext();)
            {
                User u = (User)i.next();
                g.addUser(acl, u);
            }        
        }
        return g;
    }
    
    ////////////////////////////////////////////////////////////////////
    // Read-write methods.
    ////////////////////////////////////////////////////////////////////
    
    public void addUser(AccessControlList acl, User user)
        throws ACLException, Exception
    {
        //IssueTrackingAccountDescriptor before = getDescriptorForUser(user);
        acl.assertPermissionForDomain
            ("UserGroup Member - Add", getDomain());

        UserUsergroup mapping = new UserUsergroup();
        mapping.setUserId(user.getPrimaryKeyAsInt());
        mapping.setUserGroupId(getPrimaryKeyAsInt());
        mapping.save();

        //UserGroupPeer.buildUserGroups();
        AccessControlList.rebuildACL(user);
        //IssueTrackingAccountDescriptor after = getDescriptorForUser(user);
        //before.syncTo(conn, dMgr, after);
    }

    public void removeUser(AccessControlList acl, User user)
        throws ACLException, Exception
    {
        acl.assertPermissionForDomain
            ("UserGroup Member - Delete", getDomain());
        //IssueTrackingAccountDescriptor before = getDescriptorForUser(user);

        //UserGroupPeer.buildUserGroups(conn, dMgr);        

        //Invalidate the removed user's ACL, and run scripts.
        AccessControlList.rebuildACL(user);
        //IssueTrackingAccountDescriptor after = getDescriptorForUser(user);
        //before.syncTo(conn, dMgr, after, acl.getUser());
    }            
    /*
    public void updateInfo(AccessControlList acl, String description, 
                           WebContext context)
        throws ACLException, DataSetException, SQLException,
               JoistDatabaseException
    {
        acl.assertPermissionForDomain("UserGroup - Edit", getDomainID());
        uMgr.updateUser(conn, context, getID(), getLoginID(), getEmail(),
                        description, null);
        try 
        {
            setRecord(uMgr.getUser(conn, getID()));
        } catch (DoesNotExist ignore) {} //Can't happen--we just used it.    
    }
*/
    /**
     * Totally deletes a user group.
     */
//     public void delete(AccessControlList acl)
//         throws DataSetException, SQLException, JoistDatabaseException, 
//                ACLException, DoesNotExist
//     {
//         acl.assertPermissionForDomain("UserGroup - Delete", getDomain());

//         //Remove all users from this group.
//         for (Iterator i = getUsers().iterator(); i.hasNext();)
//         {
//             removeUser(acl, (User)i.next());
//         }

//         //Remove the group proper.
//         super.delete(acl);
//     }

//     /**
//      * Returns an IssueTrackingAccountDescriptor describing the
//      * current state of the given user as regards the projects in
//      * which this user group has a role.
//      */
//     public IssueTrackingAccountDescriptor getDescriptorForUser(User baseUser)
//         throws SQLException, DataSetException, JoistDatabaseException,
//                DoesNotExist
//     {
//         /*        List projectList = new ArrayList();
//         //All projects this usergroup has a role in are affected
//         DataSet projects = urpMgr.getProjectsForUser(conn, getID());
//         for (int i = 0; i < projects.size(); i++)
//         {
//             Project project = new Project(conn, dMgr, projects.getRecord(i));
//             projectList.add(project);
//         }

//         return new IssueTrackingAccountDescriptor(projectList, baseUser);
//         */
//     }

    ////////////////////////////////////////////////////////////////////
    // Read-only methods.
    ////////////////////////////////////////////////////////////////////
    
    public List getUsers()
        throws Exception
    {
        List users = new ArrayList();

        //Get the mappings of users to this user group.
        Criteria c = new Criteria()
            .add(UserUsergroupPeer.USER_GROUP_ID, getID());
        List mappings = UserUsergroupPeer.doSelect(c);
        for (Iterator i = mappings.iterator(); i.hasNext();)
        {
            UserUsergroup m = (UserUsergroup)i.next();
            users.add(UserPeer.retrieveByPK(m.getUserId()));
        }

        Collections.sort(users);
        return users;
    }
    
    public List expand()
        throws Exception
    {
	return getUsers();
    }

    public int getNumberOfUsers(AccessControlList acl)
        throws Exception
    {
        return getUsers().size();
    }

    public String getName() 
    {
        return getLoginName();
    }

    public String getDescription() 
    {
        return super.getRealName();
    }
    
}



@


1.1.2.2
log
@Removed crappy WebMacro logging in favor of the new Turbine logging system.  You can now say Log.debug("my msg") to use the Turbine system.
@
text
@d52 2
d66 2
@


1.1.2.3
log
@Put back usage of IssueTrackingAccountDescriptor in methods that should use it.
@
text
@d59 2
a60 2
import org.tigris.helm.om.peer.*;
import org.tigris.helm.tool.task.IssueTrackingAccountDescriptor;
d100 1
a100 1
        IssueTrackingAccountDescriptor before = getDescriptorForUser(user);
d111 2
a112 2
        IssueTrackingAccountDescriptor after = getDescriptorForUser(user);
        before.syncTo(after);
d120 1
a120 1
        IssueTrackingAccountDescriptor before = getDescriptorForUser(user);
d126 2
a127 2
        IssueTrackingAccountDescriptor after = getDescriptorForUser(user);
        before.syncTo(after, acl.getUser());
d163 17
a179 12
    /**
     * Returns an IssueTrackingAccountDescriptor describing the
     * current state of the given user as regards the projects in
     * which this user group has a role.
     */
    public IssueTrackingAccountDescriptor getDescriptorForUser(User baseUser)
        throws Exception
    {
        //All projects this usergroup has a role in are affected
        Criteria c = new Criteria().add
            (UserRoleProjectPeer.USER_ID, getUserId());
        List mappings = UserRoleProjectPeer.doSelect(c);
d181 3
a183 10
        List projectList = new ArrayList(mappings.size());   
        for (Iterator i = mappings.iterator(); i.hasNext();)
        {
            UserRoleProject mapping = (UserRoleProject)i.next();
            Project project = ProjectPeer.getInstance(String.valueOf(mapping.getProjectId()));
            projectList.add(project);
        }

        return new IssueTrackingAccountDescriptor(projectList, baseUser);
    }
@


1.1.2.4
log
@Added log import
@
text
@a52 1
import org.apache.turbine.util.Log;
d103 1
d183 1
@


1.1.2.5
log
@Hacky support for user group listing.
@
text
@d215 1
a215 1
    public int getNumberOfUsers()
@


1.1.2.6
log
@Changed code to no longer use deprecated methods.
@
text
@d102 1
a102 1
        acl.assertPermission
d118 1
a118 1
        acl.assertPermission
d135 1
a135 1
        acl.assertPermission("UserGroup - Edit", getDomainID());
d151 1
a151 1
//         acl.assertPermission("UserGroup - Delete", getDomain());
@


1.1.2.7
log
@Ported updateInfo method.
@
text
@d129 5
a133 6

    /**
     * Changes a user group's information. Right now only changes description.
     */
    public void updateInfo(AccessControlList acl, String description)
        throws ACLException, Exception
d135 7
a141 2
        acl.assertPermission("UserGroup - Edit", getDomain());
        setRealName(description);
d143 1
a143 1

@


1.1.2.8
log
@Ported delete method.
@
text
@d143 5
a147 4
    public void delete(AccessControlList acl)
        throws ACLException, Exception
    {
        acl.assertPermission("UserGroup - Delete", getDomain());
d149 5
a153 5
        //Remove all users from this group.
        for (Iterator i = getUsers().iterator(); i.hasNext();)
        {
            removeUser(acl, (User)i.next());
        }
d155 3
a157 3
        //Remove the group proper.
        super.delete(acl);
    }
@


1.1.2.9
log
@Added Javadoc.
@
text
@d97 1
a97 4

    /**
     * Add a user to a user group.
     */    
a114 3
    /**
     * Remove a user from a user group.
     */
d122 1
a122 4
        Criteria c = new Criteria()
            .add(UserUsergroupPeer.USER_ID, user.getUserId())
            .add(UserUsergroupPeer.USER_GROUP_ID, getUserId());
        UserUsergroupPeer.doDelete(c);
@


1.1.2.10
log
@Added more JavaDoc and the ever-important call to save().
@
text
@a68 3
    /**
     * Adds a new user group.
     */
a75 3
    /**
     * Adds a new user group and some initial members..
     */
a146 1
        save();
@


1.1.2.11
log
@Reverting ProjectGroup and UserGroup, accidently overwritten on last commit of Torque-generated files.
@
text
@d69 3
d79 3
d103 4
a106 1
    
d124 3
d134 4
a137 1
        //UserGroupPeer.buildUserGroups(conn, dMgr);        
d144 10
a153 13
    /*
    public void updateInfo(AccessControlList acl, String description, 
                           WebContext context)
        throws ACLException, DataSetException, SQLException,
               JoistDatabaseException
    {
        acl.assertPermission("UserGroup - Edit", getDomainID());
        uMgr.updateUser(conn, context, getID(), getLoginID(), getEmail(),
                        description, null);
        try 
        {
            setRecord(uMgr.getUser(conn, getID()));
        } catch (DoesNotExist ignore) {} //Can't happen--we just used it.    
d155 1
a155 1
*/
d159 14
a172 15
//     public void delete(AccessControlList acl)
//         throws DataSetException, SQLException, JoistDatabaseException, 
//                ACLException, DoesNotExist
//     {
//         acl.assertPermission("UserGroup - Delete", getDomain());

//         //Remove all users from this group.
//         for (Iterator i = getUsers().iterator(); i.hasNext();)
//         {
//             removeUser(acl, (User)i.next());
//         }

//         //Remove the group proper.
//         super.delete(acl);
//     }
@


1.1.2.12
log
@Ported UserGroup methods *again*
@
text
@d129 5
a133 6

    /**
     * Changes the information (just description for now) of a usergroup.
     */
    public void updateInfo(AccessControlList acl, String description)
        throws ACLException, Exception
d135 7
a141 3
        assertEditPermission(acl);
        setRealName(description);
        save();
d143 1
a143 1

d147 5
a151 4
    public void delete(AccessControlList acl)
        throws ACLException, Exception
    {
        assertDeletePermission(acl);
d153 5
a157 5
        //Remove all users from this group.
        for (Iterator i = getUsers().iterator(); i.hasNext();)
        {
            removeUser(acl, (User)i.next());
        }
d159 3
a161 3
        //Remove the group proper.
        super.delete(acl);
    }
@


1.1.2.13
log
@Patches to get user groups to play nice with the new generated peers.
@
text
@a68 5
    public UserGroup()
    {
        setType(UserPeer.CLASSKEY_GROUP);
    }

d79 2
a80 12
    {        
        User.assertNonexistance(domain, name);
        Log.debug("OK To go ahead.");
        UserGroup g = new UserGroup();
        g.setDomainId(domain.getDomainId());
        g.setLoginName(name);
        g.setRealName(description);   
        g.assertAddPermission(acl);    
        g.save();

        //Add the user to the appropriate user group.
        g.addToDomainGroup();
a90 1
        Log.debug("Returning.");
@


1.1.2.14
log
@Big wide-ranging patch being committed all at once due to network downness. Features of this patch include: lots of added and updated JavaDoc, conversion of emails to use TemplateInterpolator and HelmEmailer, rearrangement of methods, changing code that gets mappings and loops over them to code that just gets the appropriate objects from the peer using AddJoin.
@
text
@a61 1
import org.tigris.helm.tool.paginate.PeerBackedList;
d65 3
a67 84

    //
    // Accessor methods
    //
   
    /**
     * Returns a paginatable list of users in this group.
     */
    public PeerBackedList getUsers(Integer itemsPerPage, Criteria filter)
        throws Exception
    {
        List users = new ArrayList();

        //Get the mappings of users to this user group.
        Criteria base = new Criteria()
            .addJoin(UserPeer.USER_ID, UserUsergroupPeer.USER_ID)
            .add(UserUsergroupPeer.USER_GROUP_ID, getID());
        return new PeerBackedList(UserPeer.class, 
                                  itemsPerPage, base, filter);
    }

    /**
     * Returns all the users in this group.
     */
    public List getUsers()
        throws Exception
    {
        return getUsers(new Integer(0), new Criteria(0));
    }

    /**
     * Returns the number of users in this group.
     */
    public int getNumberOfUsers()
        throws Exception
    {
        return getUsers().size();
    }

    /**
     * Overrides the base User expand(). Returns all the users equivalent
     * to this user.
     */
    public List expand()
        throws Exception
    {
	return getUsers();
    }

    /**
     * Returns an IssueTrackingAccountDescriptor describing the
     * current state of the given user as regards the projects in
     * which this user group has a role.
     */
    public IssueTrackingAccountDescriptor getDescriptorForUser(User baseUser)
        throws Exception
    {
        //All projects in which this usergroup has a role are affected
        Criteria c = new Criteria()
            .addJoin(ProjectPeer.PROJECT_ID, UserRoleProjectPeer.PROJECT_ID)
            .add(UserRoleProjectPeer.USER_ID, getUserId());
        List projects = UserRoleProjectPeer.doSelect(c);
        return new IssueTrackingAccountDescriptor(projects, baseUser);
    }

    /**
     * Returns the name of the user group.
     */
    public String getName() 
    {
        return getLoginName();
    }

    /**
     * Returns the description of the user group.
     */
    public String getDescription() 
    {
        return super.getRealName();
    }

    //
    // Mutator methods.
    //
d106 1
d109 5
a113 1
        
d173 68
@


1.1.2.15
log
@What's sauce for ProjectGroup.java is sauce for UserGroup.java.
@
text
@a115 12
     * Returns true iff this group contains the given user.
     */
    public boolean containsUser(User u)
        throws Exception
    {
        Criteria c = new Criteria()
            .add(UserUsergroupPeer.USER_ID, u.getID())
            .add(UserUsergroupPeer.USER_GROUP_ID, getID());
        return !UserUsergroupPeer.doSelect(c).isEmpty();
    }

    /**
a190 4
    /**
     * Add a user to this user group. Does nothing if the user is
     * already in the group.  
     */
d194 12
a205 15
        if (!containsUser(user))
        {
            acl.assertPermission
                ("UserGroup Member - Add", getDomain());
            IssueTrackingAccountDescriptor before = getDescriptorForUser(user);
            UserUsergroup mapping = new UserUsergroup();
            mapping.setUserId(user.getPrimaryKeyAsInt());
            mapping.setUserGroupId(getPrimaryKeyAsInt());
            mapping.save();
            
            //UserGroupPeer.buildUserGroups();
            AccessControlList.rebuildACL(user);
            IssueTrackingAccountDescriptor after = getDescriptorForUser(user);
            before.syncTo(after);
        }
@


1.1.2.16
log
@Normalized copyright dates.
@
text
@d2 1
a2 1
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
@


1.1.2.17
log
@Do select from correct peer.
@
text
@d139 1
a139 1
        List projects = ProjectPeer.doSelect(c);
@


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


1.1.2.19
log
@Added audit logging in a bunch of places.
@
text
@a67 45
    /**
     * Description of the audit log entry created when a user of this
     * type is added.  
     */
    private static final AUDIT_LOG_ON_ADD = "User group added: ";

    /**
     * Description of the audit log entry created when a user of this
     * type is deleted.
     */
    private static final AUDIT_LOG_ON_DELETE = "User group deleted: ";

    /**
     * Description of the audit log entry created when a user of this
     * type is edited.
     */
    private static final AUDIT_LOG_ON_EDIT = "User group edited: ";

    /**
     * Description of the audit log entry created when a user of this
     * type is granted a role.
     */
    private static final AUDIT_LOG_ON_ROLE_GRANT = 
        "Role granted to user group: ";

    /**
     * Description of the audit log entry created when a role is
     * revoked from a user of this type.  
     */
    private static final AUDIT_LOG_ON_ROLE_REVOKE = 
        "Role revoked from user group: ";

    /**
     * Description of the audit log entry created when a user is added
     * to this group.
     */
    private static final AUDIT_LOG_ON_USER_ADD = "User added to user group: ";

    /**
     * Description of the audit log entry created when a user is removed
     * from this group.
     */
    private static final AUDIT_LOG_ON_USER_REMOVE = 
        "User removed from user group: ";

d113 1
a113 1
        return getUsers();
a224 4
            AuditLog.logEvent
                (acl.getUser(), getDomain(), 
                 this.AUDIT_LOG_ON_USER_ADD + getName() 
                 + " <- " + user.getLoginName());
a227 4
    /**
     * Remove a user from this user group. Does nothing if the user is
     * not already in the group.  
     */
d231 10
a240 16
        if (containsUser(user))
        {
            acl.assertPermission
                ("UserGroup Member - Delete", getDomain());
            IssueTrackingAccountDescriptor before = getDescriptorForUser(user);
            
            //UserGroupPeer.buildUserGroups(conn, dMgr);        
            
            //Invalidate the removed user's ACL, and run scripts.
            AccessControlList.rebuildACL(user);
            IssueTrackingAccountDescriptor after = getDescriptorForUser(user);
            before.syncTo(after, acl.getUser());
            AuditLog.logEvent
                (acl.getUser(), getDomain(), this.AUDIT_LOG_ON_USER_REMOVE 
                 + getName() + " -> " + user.getLoginName());
        }
@


1.1.2.20
log
@Fixed compile errors introduced in audit logging patch.
@
text
@a61 1
import org.tigris.helm.tool.audit.AuditLog;
d72 1
a72 1
    private static final String AUDIT_LOG_ON_ADD = "User group added: ";
d78 1
a78 1
    private static final String AUDIT_LOG_ON_DELETE = "User group deleted: ";
d84 1
a84 1
    private static final String AUDIT_LOG_ON_EDIT = "User group edited: ";
d90 1
a90 1
    private static final String AUDIT_LOG_ON_ROLE_GRANT = 
d97 1
a97 1
    private static final String AUDIT_LOG_ON_ROLE_REVOKE = 
d104 1
a104 1
    private static final String AUDIT_LOG_ON_USER_ADD = "User added to user group: ";
d110 1
a110 1
    private static final String AUDIT_LOG_ON_USER_REMOVE = 
@


