Changeset 4314


Ignore:
Timestamp:
May 26, 2008, 1:01:24 PM (14 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #967: Assign the parent directory permissions to new files/directories

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/src/docbook/userdoc/file_system.xml

    r3719 r4314  
    816816              <varlistentry>
    817817                <term>
     818                  <guilabel>Share new files and subdirectories automatically</guilabel>
     819                </term>
     820                <listitem>
     821                  <para>
     822                    Enable this option to let BASE automatically share
     823                    new files and directories with the same permissions
     824                    as have been specified on this directory. This
     825                    option is useful when you have assigned a specific
     826                    directory as a common area for a group of users and
     827                    you want to make sure that all users has access to
     828                    all files. Some restrictions apply:
     829                  </para>
     830                  <itemizedlist>
     831                  <listitem>
     832                    <para>
     833                    Permissions for the <emphasis>Everyone</emphasis>
     834                    group are not inherited if the logged in user doesn't
     835                    have the <emphasis>SHARE_TO_EVERYONE</emphasis> permission.
     836                    </para>
     837                  </listitem>
     838                  <listitem>
     839                    <para>
     840                    If a project is active the new file/directory will be shared
     841                    to the active project as well.
     842                    </para>
     843                  </listitem>
     844                  </itemizedlist>
     845                 
     846                </listitem>
     847              </varlistentry>
     848              <varlistentry>
     849                <term>
    818850                  <guilabel>Description</guilabel>
    819851                </term>
  • trunk/src/core/common-queries.xml

    r4311 r4314  
    31913191  </query>
    31923192
     3193  <query id="SET_AUTOSHARE_ON_DIRECTORIES" type="HQL">
     3194    <sql>
     3195      UPDATE DirectoryData dir
     3196      SET dir.autoShare = :autoShare
     3197      WHERE dir.autoShare IS NULL
     3198    </sql>
     3199    <description>
     3200      A HQL query that set the autoShare property on all
     3201      directories witha  null value.
     3202    </description>
     3203  </query>
     3204
     3205
    31933206</predefined-queries>
  • trunk/src/core/net/sf/basedb/core/Directory.java

    r3719 r4314  
    100100    d.setParent(parent);
    101101    d.setAutoCompress(parent.getAutoCompress());
     102    if (parent.getAutoShare())
     103    {
     104      ShareableUtil.copyPermissions(dc, parent, d);
     105      d.setAutoShare(true);
     106    }
    102107    return d;
    103108  }
     
    651656  }
    652657 
     658  /**
     659    If new files and subdirectories that are created in this
     660    directory automatically should be shared wtih the same
     661    permissions as this directory. This setting only affects
     662    new files/directories.
     663
     664    @return TRUE to automatically share new files and subdreictories
     665    @since 2.8
     666  */
     667  public boolean getAutoShare()
     668  {
     669    return getData().getAutoShare();
     670  }
     671 
     672  /**
     673    Set if new files and subdirectories of should automatically
     674    be shared with the same permissions as this directory. If a
     675    project is active and this directory isn't already shared
     676    to the project, the permissions will be extended to also
     677    share the new item to the project.
     678   
     679    @param autoShare TRUE to enable auto-sharing
     680    @throws PermissionDeniedException If the logged in user doesn't have
     681      write permission
     682    @since 2.8
     683  */
     684  public void setAutoShare(boolean autoShare)
     685    throws PermissionDeniedException
     686  {
     687    checkPermission(Permission.WRITE);
     688    getData().setAutoShare(autoShare);
     689  }
    653690 
    654691  /**
  • trunk/src/core/net/sf/basedb/core/File.java

    r4017 r4314  
    100100    file.setName("New file");
    101101    file.uploadCompressed = directory.getAutoCompress();
     102    if (directory.getAutoShare())
     103    {
     104      ShareableUtil.copyPermissions(dc, directory, file);
     105    }
    102106    return file;
    103107  }
  • trunk/src/core/net/sf/basedb/core/Install.java

    r4311 r4314  
    107107    method.
    108108  */
    109   public static final int NEW_SCHEMA_VERSION = Integer.valueOf(57).intValue();
     109  public static final int NEW_SCHEMA_VERSION = Integer.valueOf(58).intValue();
    110110 
    111111  public static synchronized void createTables(boolean update, final ProgressReporter progress)
  • trunk/src/core/net/sf/basedb/core/ShareableUtil.java

    r4312 r4314  
    3030import net.sf.basedb.core.data.GroupData;
    3131import net.sf.basedb.core.data.ItemKeyData;
     32import net.sf.basedb.core.data.ProjectData;
    3233import net.sf.basedb.core.data.ProjectKeyData;
    3334import net.sf.basedb.core.data.ShareableData;
     
    157158    return numItems;
    158159  }
     160 
     161  /**
     162    Copy permissions from one item to another. If the 'from' item
     163    is shared to the 'EVERYONE' group, but the logged in user lacks
     164    the {@link Permission#SHARE_TO_EVERYONE} permission, the share to
     165    everyone is removed. If the 'to' item is a new item, a project
     166    is active and the 'from' item isn't already shared to the project,
     167    the 'to' item will be shared to the project.
     168
     169    @param from The item to copy permissions from
     170    @param to The item to copy permissions to
     171    @since 2.8
     172  */
     173  public static void copyPermissions(DbControl dc, Shareable from, Shareable to)
     174  {
     175    SessionControl sc = dc.getSessionControl();
     176    ItemKey itemKey = from.getItemKey();
     177    ProjectKey projectKey = from.getProjectKey();
     178   
     179    // Check if we need to remove permissions for the EVERYONE group
     180    if (itemKey != null && !sc.hasSystemPermission(Permission.SHARE_TO_EVERYONE))
     181    {
     182      GroupData everyone = HibernateUtil.loadData(dc.getHibernateSession(), GroupData.class,
     183        SystemItems.getId(Group.EVERYONE));
     184
     185      if (itemKey.getData().getGroups().containsKey(everyone))
     186      {
     187        // Remove the EVERYONE grup
     188        GroupPermissions gp = new GroupPermissions(itemKey);
     189        gp.getGroupPermissions().remove(everyone);
     190       
     191        UserPermissions up = new UserPermissions(itemKey);
     192        if (up.size() == 0 && gp.size() == 0)
     193        {
     194          itemKey = null;
     195        }
     196        else
     197        {
     198          itemKey = ItemKey.getNewOrExisting(dc, up, gp);
     199        }
     200      }
     201    }
     202
     203    // Check if we need to add permissions for the current project
     204    if (projectKey != null && sc.getProjectKeyId() != 0 && to.getId() == 0)
     205    {
     206      ProjectData project = HibernateUtil.loadData(dc.getHibernateSession(),
     207          ProjectData.class, sc.getActiveProjectId());
     208     
     209      if (!projectKey.getData().getProjects().containsKey(project))
     210      {
     211        // Add the current project
     212        ProjectKey activeKey = ProjectKey.getById(dc, sc.getProjectKeyId());
     213        ProjectPermissions pp = new ProjectPermissions(projectKey);
     214        pp.getProjectPermissions().put(project, activeKey.getData().getProjects().get(project));
     215        projectKey = ProjectKey.getNewOrExisting(dc, pp);
     216      }
     217    }
     218   
     219    if (itemKey != null) to.setItemKey(itemKey);
     220    if (projectKey != null) to.setProjectKey(projectKey);
     221  }
     222 
    159223}
  • trunk/src/core/net/sf/basedb/core/Update.java

    r4311 r4314  
    657657    </td>
    658658  </tr>
     659  <tr>
     660    <td>58</td>
     661    <td>
     662      <ul>
     663      <li>Added {@link net.sf.basedb.core.data.DirectoryData#getAutoShare()}.
     664      </ul>
     665      The update sets the value to false for all directories.
     666    </td>
     667  </tr>
     668 
    659669  </table>
    660670
     
    925935        if (progress != null) progress.display((int)(56*progress_factor), "--Updating schema version: " + schemaVersion + " -> 57...");
    926936        schemaVersion = updateToSchemaVersion57(session);
     937      }
     938     
     939      if (schemaVersion < 58)
     940      {
     941        if (progress != null) progress.display((int)(57*progress_factor), "--Updating schema version: " + schemaVersion + " -> 58...");
     942        schemaVersion = setSchemaVersionInTransaction(session, 58);
    927943      }
    928944     
     
    27322748        }
    27332749       
     2750        if (schemaVersion < 58)
     2751        {
     2752          // Set autoShare = false on all directories
     2753          org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session,
     2754            "SET_AUTOSHARE_ON_DIRECTORIES");
     2755          /*
     2756            UPDATE DirectoryData dir
     2757            SET dir.autoShare = :autoShare
     2758            WHERE dir.autoShare IS NULL
     2759          */
     2760          query.setBoolean("autoShare", false);
     2761          HibernateUtil.executeUpdate(query);
     2762        }
     2763       
    27342764        //  Commit the changes
    27352765        HibernateUtil.commit(tx);
  • trunk/src/core/net/sf/basedb/core/data/DirectoryData.java

    r3948 r4314  
    103103  }
    104104 
     105  private boolean autoShare;
     106  /**
     107    If new files and subdirectories should inherit the share permission
     108    on this directory or not.
     109    @since 2.8
     110    @hibernate.property column="`auto_share`" type="boolean" not-null="true"
     111  */
     112  public boolean getAutoShare()
     113  {
     114    return autoShare;
     115  }
     116  public void setAutoShare(boolean autoShare)
     117  {
     118    this.autoShare = autoShare;
     119  }
     120 
    105121  private Set<FileData> files;
    106122  /**
  • trunk/www/filemanager/directories/edit_directory.jsp

    r3719 r4314  
    6161  Directory parent = null;
    6262  boolean autoCompress = false;
     63  boolean autoShare = false;
    6364
    6465  if (itemId == 0)
     
    6970    );
    7071    autoCompress = parent.getAutoCompress();
     72    autoShare = parent.getAutoShare();
    7173    cc.removeObject("item");
    7274  }
     
    7678    parent = directory.getParent();
    7779    autoCompress = directory.getAutoCompress();
     80    autoShare = directory.getAutoShare();
    7881    cc.setObject("item", directory);
    7982    title = "Edit directory -- " + HTML.encodeTags(directory.getName());
     
    135138
    136139    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
    137     <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*180)+"px;"%>"
     140    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*240)+"px;"%>"
    138141      position="bottom" remember="<%=directory != null%>">
    139142    <t:tab id="info" title="Directory" validate="validateDirectory()" helpid="directory.edit">
     
    154157          <input type="radio" name="autoCompress" value="0" <%=!autoCompress ? "checked" : ""%>>no
    155158          <input type="radio" name="autoCompress" value="1" <%=autoCompress ? "checked" : ""%>>yes
     159        </td>
     160      </tr>
     161      <tr>
     162        <td class="prompt">
     163          Share new files and sub-<br>
     164          directories automatically
     165        </td>
     166        <td>
     167          <input type="radio" name="autoShare" value="0" <%=!autoShare ? "checked" : ""%>>no
     168          <input type="radio" name="autoShare" value="1" <%=autoShare ? "checked" : ""%>>yes
    156169        </td>
    157170      </tr>
  • trunk/www/filemanager/directories/index.jsp

    r3719 r4314  
    145145    directory.setName(Values.getStringOrNull(request.getParameter("name")));
    146146    directory.setAutoCompress(Values.getBoolean(request.getParameter("autoCompress")));
     147    directory.setAutoShare(Values.getBoolean(request.getParameter("autoShare")));
    147148    directory.setDescription(Values.getStringOrNull(request.getParameter("description")));
    148149    dc.commit();
  • trunk/www/include/scripts/main.js

    r4311 r4314  
    418418    this.controllers['PROJECT'] = { url:'my_base/projects/index.jsp', width:600, height:460 };
    419419    this.controllers['FILE'] = { url:'filemanager/index.jsp', width:500, height:360 };
    420     this.controllers['DIRECTORY'] = { url:'filemanager/directories/index.jsp', width:500, height:360, xpopup:true };
     420    this.controllers['DIRECTORY'] = { url:'filemanager/directories/index.jsp', width:600, height:400, xpopup:true };
    421421    this.controllers['ARRAYBATCH'] = { url:'lims/arraybatches/index.jsp', width:800, height:500 };
    422422    this.controllers['ARRAYDESIGN'] = { url:'lims/arraydesigns/index.jsp', width:800, height:500 };
Note: See TracChangeset for help on using the changeset viewer.