[DS-92] Bitstream access rights inheritenc, editing in_archive items - ID: 1993036

git-svn-id: http://scm.dspace.org/svn/repo/branches/dspace-1_5_x@3659 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Andrea Bollini
2009-03-31 07:30:14 +00:00
parent d0c8954136
commit e9c0e8a761
5 changed files with 82 additions and 15 deletions

View File

@@ -50,6 +50,7 @@ import java.util.ListIterator;
import org.apache.log4j.Logger;
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.authorize.ResourcePolicy;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.core.LogManager;
@@ -594,4 +595,67 @@ public class Bundle extends DSpaceObject
{
return Constants.BUNDLE;
}
/**
* remove all policies on the bundle and its contents, and replace them with
* the DEFAULT_BITSTREAM_READ policies belonging to the collection.
*
* @param c
* Collection
* @throws java.sql.SQLException
* if an SQL error or if no default policies found. It's a bit
* draconian, but default policies must be enforced.
* @throws AuthorizeException
*/
public void inheritCollectionDefaultPolicies(Collection c)
throws java.sql.SQLException, AuthorizeException
{
List<ResourcePolicy> policies = AuthorizeManager.getPoliciesActionFilter(ourContext, c,
Constants.DEFAULT_BITSTREAM_READ);
// change the action to just READ
// just don't call update on the resourcepolicies!!!
Iterator<ResourcePolicy> i = policies.iterator();
if (!i.hasNext())
{
throw new java.sql.SQLException("Collection " + c.getID()
+ " has no default bitstream READ policies");
}
while (i.hasNext())
{
ResourcePolicy rp = (ResourcePolicy) i.next();
rp.setAction(Constants.READ);
}
replaceAllBitstreamPolicies(policies);
}
/**
* remove all of the policies for the bundle and bitstream contents and replace
* them with a new list of policies
*
* @param newpolicies -
* this will be all of the new policies for the bundle and
* bitstream contents
* @throws SQLException
* @throws AuthorizeException
*/
public void replaceAllBitstreamPolicies(List<ResourcePolicy> newpolicies)
throws SQLException, AuthorizeException
{
if (bitstreams != null && bitstreams.size() > 0)
{
for (Bitstream bs : bitstreams)
{
// change bitstream policies
AuthorizeManager.removeAllPolicies(ourContext, bs);
AuthorizeManager.addPolicies(ourContext, newpolicies, bs);
}
}
// change bundle policies
AuthorizeManager.removeAllPolicies(ourContext, this);
AuthorizeManager.addPolicies(ourContext, newpolicies, this);
}
}

View File

@@ -2018,21 +2018,7 @@ public class Item extends DSpaceObject
for (int i = 0; i < bunds.length; i++)
{
Bundle mybundle = bunds[i];
Bitstream[] bs = mybundle.getBitstreams();
for (int j = 0; j < bs.length; j++)
{
Bitstream mybitstream = bs[j];
// change bitstream policies
AuthorizeManager.removeAllPolicies(ourContext, bs[j]);
AuthorizeManager.addPolicies(ourContext, newpolicies, bs[j]);
}
// change bundle policies
AuthorizeManager.removeAllPolicies(ourContext, mybundle);
AuthorizeManager.addPolicies(ourContext, newpolicies, mybundle);
mybundle.replaceAllBitstreamPolicies(newpolicies);
}
}

View File

@@ -684,6 +684,14 @@ public class EditItemServlet extends DSpaceServlet
{
// set bundle's name to ORIGINAL
b = item.createSingleBitstream(is, "ORIGINAL");
// set the permission as defined in the owning collection
Collection owningCollection = item.getOwningCollection();
if (owningCollection != null)
{
Bundle bnd = b.getBundles()[0];
bnd.inheritCollectionDefaultPolicies(owningCollection);
}
}
else
{

View File

@@ -391,6 +391,14 @@ public class FlowItemUtils
{
// set bundle's name to ORIGINAL
bitstream = item.createSingleBitstream(is, bundleName);
// set the permission as defined in the owning collection
Collection owningCollection = item.getOwningCollection();
if (owningCollection != null)
{
Bundle bnd = bitstream.getBundles()[0];
bnd.inheritCollectionDefaultPolicies(owningCollection);
}
}
else
{

View File

@@ -121,6 +121,7 @@
- [DS-115] metadata not showed in verify step
- [DS-122] Problems with repeatable metadata
- [DS-116] File description not correct
- [DS-92] Bitstream access rights inheritenc, editing in_archive items - ID: 1993036
(Paulo Jobim)
- SF Patch [2655052] Authors re-ordered when item edited (xmlui)