Changeset 3150


Ignore:
Timestamp:
Feb 26, 2007, 11:44:59 AM (16 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #501: Make members of a project readable by all other members

Location:
branches/2.2.2/src/core
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.2/src/core/common-queries.xml

    r3136 r3150  
    202202    <description>
    203203      Load the ID of all users which has a quota group from one of the given groups.
     204    </description>
     205  </query>
     206
     207  <query id="GET_USER_IDS_FOR_PROJECT" type="HQL">
     208    <sql>
     209      SELECT up.userId
     210      FROM UserProjects up
     211      WHERE up.projectId = :projectId
     212    </sql>
     213    <description>
     214      Load the ID of all users which are direct member of the given project
     215    </description>
     216  </query>
     217
     218  <query id="GET_GROUP_IDS_FOR_PROJECT" type="HQL">
     219    <sql>
     220      SELECT gp.groupId
     221      FROM GroupProjects gp
     222      WHERE gp.projectId = :projectId
     223    </sql>
     224    <description>
     225      Load the ID of all groups which are direct member of the given project
    204226    </description>
    205227  </query>
  • branches/2.2.2/src/core/net/sf/basedb/core/Group.java

    r2898 r3150  
    2929import net.sf.basedb.core.query.Hql;
    3030
     31import java.util.Collection;
    3132import java.util.HashSet;
    3233import java.util.Set;
     
    124125  public static Set<Integer> getGroupsRecursive(DbControl dc, Set<Integer> groups)
    125126  {
     127    return getGroupsRecursive(dc.getHibernateSession(), groups);
     128  }
     129
     130  static Set<Integer> getGroupsRecursive(org.hibernate.Session session, Collection<Integer> groups)
     131  {
    126132    Set<Integer> allGroups = new HashSet<Integer>(groups);
    127133    if (allGroups.size() > 0)
    128134    {
    129135     
    130       org.hibernate.Query query = HibernateUtil.getPredefinedQuery(dc.getHibernateSession(),
     136      org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session,
    131137        "GET_CHILDGROUPS_IDS_FOR_GROUPS");
    132138      /*
     
    143149    return allGroups;
    144150  }
     151
    145152 
    146153  /**
  • branches/2.2.2/src/core/net/sf/basedb/core/Keyring.java

    r2981 r3150  
    450450    Load all users which are member of at least one group where the
    451451    logged in user is also a member and put that information
    452     in the {@link #users} variable.
     452    in the {@link #users} variable. If a project is active, also load the members
     453    and owner of that project.
    453454  */
    454455  private void loadUsers(org.hibernate.Session session)
    455456    throws BaseException
    456457  {
    457     Set<Integer> temp;
     458    Set<Integer> temp = new HashSet<Integer>();
    458459    try
    459460    {
     
    468469        */
    469470        query.setParameterList("groups", groups, org.hibernate.Hibernate.INTEGER);
    470         temp = new HashSet<Integer>(HibernateUtil.loadList(Integer.class, query));
     471        temp.addAll(HibernateUtil.loadList(Integer.class, query));
    471472       
    472473        // Get the users that have a quota group among the same groups
     
    479480        query.setParameterList("groups", groups, org.hibernate.Hibernate.INTEGER);
    480481        temp.addAll(HibernateUtil.loadList(Integer.class, query));
     482      }
     483     
     484      if (projectId != 0)
     485      {
     486        // Get the owner of the active project
     487        ProjectData pd = HibernateUtil.loadData(session, ProjectData.class, projectId);
     488        temp.add(pd.getOwner().getId());
    481489       
    482         users = Collections.unmodifiableSet(temp);
    483       }
     490        // Get direct members of the active project
     491        org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session, "GET_USER_IDS_FOR_PROJECT");
     492        /*
     493          SELECT up.userId
     494          FROM UserProjects up
     495          WHERE up.projectId = :projectId
     496        */
     497        query.setInteger("projectId", projectId);
     498        temp.addAll(HibernateUtil.loadList(Integer.class, query));
     499       
     500        // Get groups that are direct members of the active project
     501        query = HibernateUtil.getPredefinedQuery(session, "GET_GROUP_IDS_FOR_PROJECT");
     502        /*
     503          SELECT gp.groupId
     504          FROM GroupProjects gp
     505          WHERE gp.projectId = :projectId
     506        */
     507        query.setInteger("projectId", projectId);
     508        // Load the direct groups and subgroups
     509        Set<Integer> projectGroups = Group.getGroupsRecursive(session, HibernateUtil.loadList(Integer.class, query));
     510
     511        // Load users that are members of the project groups
     512        temp.addAll(User.getAllMembers(session, projectGroups));
     513       
     514      }
     515      users = Collections.unmodifiableSet(temp);
    484516    }
    485517    catch (HibernateException ex)
     
    717749  {
    718750    if (getReload() && !reload()) projectData = null;
     751    int oldProjectId = projectId;
    719752    if (projectData == null)
    720753    {
     
    725758    {
    726759      projectId = projectData.getId();
    727       org.hibernate.Session session = null;
    728       org.hibernate.Transaction tx = null;
    729       try
    730       {
    731         session = HibernateUtil.newSession();
    732         tx = HibernateUtil.newTransaction(session);
    733         loadMaxProjectPermission(session, projectData);
    734         loadProjectKeys(session);
    735       }
    736       catch (BaseException ex)
    737       {
    738         projectId = 0;
    739         maxProjectPermission = 0;
    740         throw ex;
    741       }
    742       finally
    743       {
    744         if (tx != null) HibernateUtil.commit(tx);
    745         if (session != null) HibernateUtil.close(session);
    746       }
    747     }
     760    }
     761    reload = projectId != oldProjectId;
    748762  }
    749763 
  • branches/2.2.2/src/core/net/sf/basedb/core/User.java

    r2902 r3150  
    3636
    3737import java.util.ArrayList;
     38import java.util.Collection;
    3839import java.util.Date;
    3940import java.util.HashSet;
     
    124125  public static Set<Integer> getAllMembers(DbControl dc, Set<Integer> groupIds)
    125126  {
     127    return getAllMembers(dc.getHibernateSession(), groupIds);
     128  }
     129 
     130  static Set<Integer> getAllMembers(org.hibernate.Session session, Collection<Integer> groupIds)
     131  {
    126132    Set<Integer> userIds = new HashSet<Integer>();
    127133    if (groupIds != null && groupIds.size() > 0)
    128134    {
    129       org.hibernate.Session session = dc.getHibernateSession();
    130135      // Get the users which are members of the same groups
    131136      org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session, "GET_USER_IDS_FOR_GROUPS");
     
    149154    }
    150155    return userIds;
    151    
    152   }
     156  }
     157
    153158 
    154159  /**
Note: See TracChangeset for help on using the changeset viewer.