Changeset 5077


Ignore:
Timestamp:
Aug 26, 2009, 2:03:37 PM (13 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1182: Groups with hidden members

Location:
trunk
Files:
12 edited

Legend:

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

    r5063 r5077  
    36093609    </description>
    36103610  </query>
     3611  <query id="SET_HIDDENMEMBERS_ON_GROUPS" type="HQL">
     3612    <sql>
     3613      UPDATE GroupData grp
     3614      SET grp.hiddenMembers = :hiddenMembers
     3615      WHERE grp.hiddenMembers IS NULL
     3616    </sql>
     3617    <description>
     3618      An HQL query that sets the hiddenMembers flag on all
     3619      groups with a null value.
     3620    </description>
     3621  </query>
     3622  <query id="GET_GROUPS_WITH_NONHIDDENMEMBERS" type="HQL">
     3623    <sql>
     3624      SELECT grp.id
     3625      FROM GroupData grp
     3626      WHERE grp.hiddenMembers = false
     3627      AND grp.id IN (:groups)
     3628    </sql>
     3629    <description>
     3630      A HQL query that selects the ID of the groups among a given set of
     3631      groups that has 'hiddenMembers=false'
     3632    </description>
     3633  </query>
    36113634
    36123635</predefined-queries>
  • trunk/src/core/net/sf/basedb/core/Group.java

    r4889 r5077  
    396396    }
    397397    getData().setDefault(isDefault);
     398  }
     399 
     400  /**
     401    Does this group have hidden members? In a group with hidden members
     402    one user doesn't get read permission to other members of the same
     403    group.
     404    @return TRUE if the members are hidden
     405    @since 2.13
     406  */
     407  public boolean hasHiddenMembers()
     408  {
     409    return getData().getHiddenMembers();
     410  }
     411 
     412  /**
     413    Set the hidden members flag for this group.
     414    @throws PermissionDeniedException If the logged in user doesn't
     415      have {@link Permission#WRITE} permission for the group, or if
     416      this group is the {@link #EVERYONE} group
     417    @since 2.13
     418  */
     419  public void setHiddenMembers(boolean hiddenMembers)
     420  {
     421    checkPermission(Permission.WRITE);
     422    if (getId() == SystemItems.getId(EVERYONE))
     423    {
     424      throw new PermissionDeniedException("Not allowed to add members to the EVERYONE group.");
     425    }
     426    getData().setHiddenMembers(hiddenMembers);
    398427  }
    399428 
  • trunk/src/core/net/sf/basedb/core/Install.java

    r5056 r5077  
    114114    method.
    115115  */
    116   public static final int NEW_SCHEMA_VERSION = Integer.valueOf(74).intValue();
     116  public static final int NEW_SCHEMA_VERSION = Integer.valueOf(75).intValue();
    117117 
    118118  public static synchronized void createTables(boolean update, final ProgressReporter progress)
     
    229229 
    230230      if (progress != null) progress.display((int)(5*progress_factor), "--Creating groups...");
    231       GroupData groupEveryone = createGroup(Group.EVERYONE, "Everyone", false, "Everyone are members of this group.");
     231      GroupData groupEveryone = createGroup(Group.EVERYONE, "Everyone", false, true, "Everyone are members of this group.");
    232232 
    233233      if (progress != null) progress.display((int)(6*progress_factor), "--Creating keys...");
     
    11891189    Create a {@link Group}.
    11901190  */
    1191   private static GroupData createGroup(String systemId, String name, boolean isDefault, String description)
     1191  private static GroupData createGroup(String systemId, String name, boolean isDefault,
     1192    boolean hiddenMembers, String description)
    11921193    throws BaseException
    11931194  {
     
    12151216          // Set default property if upgrading
    12161217          group.setDefault(isDefault);
     1218        }
     1219        if (schemaVersion.getSchemaVersion() < 75)
     1220        {
     1221          // Set default property if upgrading
     1222          group.setHiddenMembers(hiddenMembers);
    12171223        }
    12181224        log.info("createGroup: EXISTS [SYSTEM ID="+systemId+"; name="+name+"]");
     
    12271233        group.setDescription(description);
    12281234        group.setDefault(isDefault);
     1235        group.setHiddenMembers(hiddenMembers);
    12291236        HibernateUtil.saveData(session, group);
    12301237        HibernateUtil.commit(tx);
  • trunk/src/core/net/sf/basedb/core/Keyring.java

    r4889 r5077  
    114114  */
    115115  private Set<Integer> groups;
     116 
     117  /**
     118    A subset of the 'groups' set that holds the id of the groups
     119    that has hiddenMembers = false
     120  */
     121  private Set<Integer> groupsWithNonHiddenMembers;
    116122
    117123  /**
     
    227233    this.projectPermissions = parent.projectPermissions;
    228234    this.groups = parent.groups;
     235    this.groupsWithNonHiddenMembers = parent.groupsWithNonHiddenMembers;
    229236    this.users = parent.users;
    230237    this.projects = parent.projects;
     
    332339  /**
    333340    Loads group membership for the user and put that information
    334     in the {@link #groups} variable.
     341    in the {@link #groups} and {@link #groupsWithNonHiddenMembers} variables.
    335342  */
    336343  private void loadGroups(org.hibernate.Session session)
     
    379386      temp.add(EVERYONE);
    380387      groups = Collections.unmodifiableSet(temp);
     388     
     389      // Load the subset of groups that has hiddenMembers = false
     390      query = HibernateUtil.getPredefinedQuery(session, "GET_GROUPS_WITH_NONHIDDENMEMBERS");
     391      /*
     392        SELECT grp.id
     393        FROM GroupData grp
     394        WHERE grp.hiddenMembers = false
     395        AND grp.id IN (:groups)
     396      */
     397      query.setParameterList("groups", groups, org.hibernate.Hibernate.INTEGER);
     398      temp = new HashSet<Integer>(HibernateUtil.loadList(Integer.class, query, null));
     399      groupsWithNonHiddenMembers = Collections.unmodifiableSet(temp);
    381400    }
    382401    catch (HibernateException ex)
     
    459478    try
    460479    {
    461       if (groups.size() > 0)
     480      if (groupsWithNonHiddenMembers.size() > 0)
    462481      {
    463482        // Get the users which are members of the same groups
    464         org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session, "GET_USER_IDS_FOR_GROUPS");
    465         /*
    466           SELECT ug.userId
    467           FROM UserGroups ug
    468           WHERE ug.groupId IN (:groups)
    469         */
    470         query.setParameterList("groups", groups, org.hibernate.Hibernate.INTEGER);
    471         temp.addAll(HibernateUtil.loadList(Integer.class, query, null));
    472        
    473         // Get the users that have a quota group among the same groups
    474         query = HibernateUtil.getPredefinedQuery(session, "GET_USER_IDS_FOR_QUOTAGROUPS");
    475         /*
    476           SELECT usr.id
    477           FROM UserData usr
    478           WHERE usr.quotaGroup.id IN (:groups)
    479         */
    480         query.setParameterList("groups", groups, org.hibernate.Hibernate.INTEGER);
    481         temp.addAll(HibernateUtil.loadList(Integer.class, query, null));
     483        temp.addAll(User.getAllMembers(session, groupsWithNonHiddenMembers));
    482484      }
    483485     
     
    508510        // Load the direct groups and subgroups
    509511        Set<Integer> projectGroups = Group.getGroupsRecursive(session, HibernateUtil.loadList(Integer.class, query, null));
    510 
     512       
     513        // Finally, filter away groups that has hiddenMembers=true
     514        query = HibernateUtil.getPredefinedQuery(session, "GET_GROUPS_WITH_NONHIDDENMEMBERS");
     515        /*
     516          SELECT grp.id
     517          FROM GroupData grp
     518          WHERE grp.hiddenMembers = false
     519          AND grp.id IN (:groups)
     520        */
     521        query.setParameterList("groups", projectGroups, org.hibernate.Hibernate.INTEGER);
     522        projectGroups.retainAll(HibernateUtil.loadList(Integer.class, query, null));
     523       
    511524        // Load users that are members of the project groups
    512         temp.addAll(User.getAllMembers(session, projectGroups));
    513        
     525        temp.addAll(User.getAllMembers(session, projectGroups)); 
    514526      }
    515527      users = Collections.unmodifiableSet(temp);
     
    894906  }
    895907 
    896   Set<Integer> getGroups()
     908  Set<Integer> getGroups(boolean onlyWithNonHiddenMembers)
    897909  {
    898910    if (getReload()) reload();
    899     return groups;
    900   }
    901  
     911    return onlyWithNonHiddenMembers ? groupsWithNonHiddenMembers : groups;
     912  }
     913 
     914  /**
     915    Get all users that share group membership with the logged in user.
     916    Only groups membership in groups that has hiddenMembers=false are
     917    considered.
     918  */
    902919  Set<Integer> getUsers()
    903920  {
  • trunk/src/core/net/sf/basedb/core/SessionControl.java

    r5043 r5077  
    10581058  public boolean isMemberOf(Group group)
    10591059  {
    1060     return loginInfo == null ? false : loginInfo.keyring.getGroups().contains(group.getId());
     1060    return loginInfo == null ? false : loginInfo.keyring.getGroups(false).contains(group.getId());
    10611061  }
    10621062 
     
    11131113  public Set<Integer> getGroups()
    11141114  {
    1115     return loginInfo == null ? null : loginInfo.keyring.getGroups();
     1115    return loginInfo == null ? null : loginInfo.keyring.getGroups(false);
    11161116  }
    11171117
  • trunk/src/core/net/sf/basedb/core/Update.java

    r5056 r5077  
    4343import net.sf.basedb.core.data.FileData;
    4444import net.sf.basedb.core.data.FormulaData;
     45import net.sf.basedb.core.data.GroupData;
    4546import net.sf.basedb.core.data.JobData;
    4647import net.sf.basedb.core.data.MeasuredBioMaterialData;
     
    831832    </td>
    832833  </tr>
     834  <tr>
     835    <td>75</td>
     836    <td>
     837      Added {@link GroupData#getHiddenMembers()}.
     838      The update sets the value for all existing groups to false.
     839    </td>
     840  </tr>
    833841  </table>
    834842
     
    11131121      }
    11141122     
    1115       // Schemaversion 61-74 only updates the version number
    1116       if (schemaVersion < 74)
    1117       {
    1118         if (progress != null) progress.display((int)(73*progress_factor), "--Updating schema version: " + schemaVersion + " -> 74...");
    1119         schemaVersion = setSchemaVersionInTransaction(session, 74);
     1123      // Schemaversion 61-75 only updates the version number
     1124      if (schemaVersion < 75)
     1125      {
     1126        if (progress != null) progress.display((int)(74*progress_factor), "--Updating schema version: " + schemaVersion + " -> 75...");
     1127        schemaVersion = setSchemaVersionInTransaction(session, 75);
    11201128      }
    11211129     
     
    30373045        }
    30383046       
     3047        if (schemaVersion < 75)
     3048        {
     3049          // Set hiddenMembers=false on all groups
     3050          org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session,
     3051            "SET_HIDDENMEMBERS_ON_GROUPS");
     3052          /*
     3053            UPDATE GroupData grp
     3054            SET grp.hiddenMembers = :hiddenMembers
     3055            WHERE grp.hiddenMembers IS NULL
     3056          */
     3057          query.setBoolean("hiddenMembers", false);
     3058          HibernateUtil.executeUpdate(query);
     3059        }
     3060       
    30393061        //  Commit the changes
    30403062        HibernateUtil.commit(tx);
  • trunk/src/core/net/sf/basedb/core/data/GroupData.java

    r4889 r5077  
    228228  }
    229229 
     230  private boolean hiddenMembers;
     231  /**
     232    A flag indicating if members of the group should be hidden
     233    to each other or not.
     234    @since 2.13
     235    @hibernate.property column="`hidden_members`" type="boolean" not-null="true"
     236  */
     237  public boolean getHiddenMembers()
     238  {
     239    return hiddenMembers;
     240  }
     241  public void setHiddenMembers(boolean hiddenMembers)
     242  {
     243    this.hiddenMembers = hiddenMembers;
     244  }
     245 
     246 
    230247}
  • trunk/src/test/TestGroup.java

    r4889 r5077  
    9393        g.setName("Test group");
    9494        g.setDescription("Added at "+new Date());
     95        g.setHiddenMembers(true);
    9596      }
    9697      dc.saveItem(g);
     
    193194    if (!TestUtil.getSilent())
    194195    {
    195       write("   \tID \tName      \tDescription");
    196       write("-- \t-- \t--------- \t-----------");
     196      write("   \tID \tName      \tHidden members\tDescription");
     197      write("-- \t-- \t--------- \t--------------\t-----------");
    197198    }
    198199  }
     
    200201    throws BaseException
    201202  {
    202     if (!TestUtil.getSilent()) System.out.println(i+":\t"+g.getId()+"\t"+g.getName()+"\t"+g.getDescription());
     203    if (!TestUtil.getSilent())
     204    {
     205      System.out.println(i+":\t"+g.getId()+"\t"+g.getName()+"\t" + g.hasHiddenMembers() +
     206        "\t"+g.getDescription());
     207    }
    203208  }
    204209  static void write_item(int i, User u)
  • trunk/www/admin/groups/edit_group.jsp

    r4889 r5077  
    6969  boolean isEveryone = false;
    7070  boolean isDefault = false;
     71  boolean hiddenMembers = false;
    7172  final QuotaType total = QuotaType.getById(dc, SystemItems.getId(QuotaType.TOTAL));
    7273  Quota currentQuota = null;
     
    9495    }
    9596    isDefault = Values.getBoolean(cc.getPropertyValue("default"), false);
     97    hiddenMembers = Values.getBoolean(cc.getPropertyValue("hiddenMembers"), false);
    9698  }
    9799  else
     
    102104    isEveryone = Group.EVERYONE.equals(group.getSystemId());
    103105    isDefault = group.isDefault();
     106    hiddenMembers = group.hasHiddenMembers();
    104107
    105108    try
     
    271274          <input type="radio" name="is_default" value="0" <%=!isDefault ? "checked" : ""%>>no
    272275          <input type="radio" name="is_default" value="1" <%=isDefault ? "checked" : ""%>>yes
     276        </td>
     277      </tr>
     278      <tr>
     279        <td class="prompt">Hidden members</td>
     280        <td>
     281          <input type="radio" name="hidden_members" value="0" <%=!hiddenMembers ? "checked" : ""%>>no
     282          <input type="radio" name="hidden_members" value="1" <%=hiddenMembers ? "checked" : ""%>>yes
    273283        </td>
    274284      </tr>
  • trunk/www/admin/groups/index.jsp

    r5060 r5077  
    173173    group.setDescription(Values.getStringOrNull(request.getParameter("description")));
    174174    group.setDefault(Values.getBoolean(request.getParameter("is_default"), false));
     175    group.setHiddenMembers(Values.getBoolean(request.getParameter("hidden_members"), false));
    175176    int quotaId = Values.getInt(request.getParameter("quota_id"), -1);
    176177    if (quotaId >= 0) // < 0 = denied or unchanged
  • trunk/www/admin/groups/list_groups.jsp

    r4906 r5077  
    267267        datatype="boolean"
    268268        title="Is default"
     269        sortable="true"
     270        filterable="true"
     271        exportable="true"
     272      />
     273      <tbl:columndef
     274        id="hiddenMembers"
     275        property="hiddenMembers"
     276        datatype="boolean"
     277        title="Hidden members"
    269278        sortable="true"
    270279        filterable="true"
     
    456465                  /></tbl:cell>
    457466                <tbl:cell column="isDefault"><%=item.isDefault() ? "yes" : "no" %></tbl:cell>
     467                <tbl:cell column="hiddenMembers"><%=item.hasHiddenMembers() ? "yes" : "no" %></tbl:cell>
    458468                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
    459469                <tbl:cell column="groups">
  • trunk/www/admin/groups/view_group.jsp

    r5042 r5077  
    229229        <td class="prompt">Is default</td>
    230230        <td><%=group.isDefault() ? "yes" : "no"%></td>
     231      </tr>
     232      <tr>
     233        <td class="prompt">Hidden members</td>
     234        <td><%=group.hasHiddenMembers() ? "yes" : "no"%></td>
    231235      </tr>
    232236      <tr>
Note: See TracChangeset for help on using the changeset viewer.