DS-1814: Allow submitters to create new version of their items

This commit is contained in:
Marsa Haoua
2016-04-14 10:07:52 +02:00
committed by Pascal-Nicolas Becker
parent 1e344bed0f
commit 701d4ba6b1
9 changed files with 78 additions and 14 deletions

View File

@@ -29,6 +29,7 @@ import org.dspace.harvest.HarvestedItem;
import org.dspace.harvest.service.HarvestedItemService;
import org.dspace.identifier.IdentifierException;
import org.dspace.identifier.service.IdentifierService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.versioning.service.VersioningService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -407,7 +408,7 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
public void update(Context context, Item item) throws SQLException, AuthorizeException {
// Check authorisation
// only do write authorization if user is not an editor
if (!canEdit(context, item))
if (!canEdit(context, item) && !canCreateNewVersion(context, item))
{
authorizeService.authorizeAction(context, item, Constants.WRITE);
}
@@ -589,7 +590,6 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
context.addEvent(new Event(Event.DELETE, Constants.ITEM, item.getID(),
item.getHandle(), getIdentifiers(context, item)));
log.info(LogManager.getHeader(context, "delete_item", "item_id="
+ item.getID()));
@@ -885,13 +885,23 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
return collectionService.canEditBoolean(context, item.getOwningCollection(), false);
}
/*
With every finished submission a bunch of resource policy entries with have null value for the dspace_object column are generated in the database.
prevent the generation of resource policy entry values with null dspace_object as value
@Override
public boolean canCreateNewVersion(Context context, Item item) throws SQLException{
if (authorizeService.isAdmin(context, item))
{
return true;
}
*/
if (context.getCurrentUser() != null
&& context.getCurrentUser().equals(item.getSubmitter()))
{
return DSpaceServicesFactory.getInstance().getConfigurationService().getPropertyAsType(
"versioning.submitterCanCreateNewVersion", false);
}
return false;
}
/**
* Add the default policies, which have not been already added to the given DSpace object

View File

@@ -444,7 +444,15 @@ public interface ItemService extends DSpaceObjectService<Item>, DSpaceObjectLega
* @throws SQLException if database error
*/
public boolean canEdit(Context context, Item item) throws java.sql.SQLException;
/**
* return TRUE if context's user can create new version of the item, false
* otherwise.
* @return boolean true = current user can create new version of the item
* @throws SQLException
*/
public boolean canCreateNewVersion(Context context, Item item) throws SQLException;
/**
* Returns an iterator of Items possessing the passed metadata field, or only
* those matching the passed value, if value is not Item.ANY

View File

@@ -96,18 +96,19 @@ public abstract class AbstractVersionProvider {
{
bundleNew.setPrimaryBitstreamID(bitstreamNew);
}
bitstreamService.update(c, bitstreamNew);
}
}
}
protected Bitstream createBitstream(Context context, Bitstream nativeBitstream) throws AuthorizeException, SQLException, IOException {
protected Bitstream createBitstream(Context context, Bitstream nativeBitstream) throws AuthorizeException, SQLException, IOException {
Bitstream newBitstream = bitstreamStorageService.clone(context, nativeBitstream);
List<MetadataValue> bitstreamMeta = bitstreamService.getMetadata(nativeBitstream, Item.ANY, Item.ANY, Item.ANY, Item.ANY);
for (MetadataValue value : bitstreamMeta) {
bitstreamService.addMetadata(context, newBitstream, value.getMetadataField(), value.getLanguage(), value.getValue(), value.getAuthority(), value.getConfidence());
}
bitstreamService.update(context, newBitstream);
return newBitstream;
}

View File

@@ -1196,6 +1196,7 @@ jsp.submit.verify-prune.notproceed.button = Do Not Make th
jsp.submit.verify-prune.proceed.button = Proceed With Changes
jsp.submit.verify-prune.question = Are you sure you want to proceed with the changes?
jsp.submit.verify-prune.title = Answers to Initial Questions Changed
jsp.submittertools = Actions
jsp.suggest.button.cancel = Cancel
jsp.suggest.button.send = Send Recommendation
jsp.suggest.heading = Recommended Item:

View File

@@ -32,6 +32,7 @@ import org.dspace.identifier.service.DOIService;
import org.dspace.identifier.service.IdentifierService;
import org.dspace.plugin.ItemHomeProcessor;
import org.dspace.plugin.PluginException;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.versioning.Version;
import org.dspace.versioning.VersionHistory;
import org.dspace.versioning.factory.VersionServiceFactory;
@@ -66,6 +67,10 @@ public class VersioningItemHome implements ItemHomeProcessor {
AuthorizeException {
boolean versioningEnabled = ConfigurationManager.getBooleanProperty(
"versioning", "enabled");
boolean submitterCanCreateNewVersion = DSpaceServicesFactory
.getInstance()
.getConfigurationService()
.getPropertyAsType("versioning.submitterCanCreateNewVersion", false);
boolean newVersionAvailable = false;
boolean showVersionWorkflowAvailable = false;
boolean hasVersionButton = false;
@@ -81,7 +86,17 @@ public class VersioningItemHome implements ItemHomeProcessor {
if (versionHistoryService.isLastVersion(context, item)
&& item.isArchived()) {
hasVersionButton = true;
}
}
}
else if (submitterCanCreateNewVersion)
{
if (versionHistoryService.isLastVersion(context, item)
&& item.isArchived()
&& itemService.canCreateNewVersion(context, item))
{
hasVersionButton = true;
}
}
if (versionHistoryService.hasVersionHistory(context, item)) {
hasVersionHistory = true;

View File

@@ -389,8 +389,14 @@ public class HandleServlet extends DSpaceServlet
{
// set a variable to create an edit button
request.setAttribute("admin_button", Boolean.TRUE);
}
// show submitters a button to create a new item version
else if (itemService.canCreateNewVersion(context, item))
{
// set a variable to create a button to create a new item version
request.setAttribute("submitter_button", Boolean.TRUE);
}
// Get the collections
List<Collection> collections = item.getCollections();

View File

@@ -92,7 +92,8 @@ public class VersionUtil
Item item = itemService.find(context, itemID);
if (authorizeService.authorizeActionBoolean(context, item,
Constants.WRITE) || itemService.canEdit(context, item))
Constants.WRITE) || itemService.canEdit(context, item)
|| itemService.canCreateNewVersion(context, item))
{
VersioningService versioningService = new DSpace()
.getSingletonService(VersioningService.class);

View File

@@ -22,6 +22,7 @@
- appear yet. If this is omitted, the item display won't
- display any collections.
- admin_button - Boolean, show admin 'edit' button
- submitter_button - Boolean, show submitter "new version" button
--%>
<%@page contentType="text/html;charset=UTF-8" %>
@@ -64,7 +65,8 @@
List<Collection> collections = (List<Collection>) request.getAttribute("collections");
Boolean admin_b = (Boolean)request.getAttribute("admin_button");
boolean admin_button = (admin_b == null ? false : admin_b.booleanValue());
Boolean submitter_b = (Boolean) request.getAttribute("submitter_button");
boolean submitter_button = (submitter_b == null ? false : submitter_b.booleanValue());
// get the workspace id if one has been passed
Integer workspace_id = (Integer) request.getAttribute("workspace_id");
@@ -198,6 +200,22 @@
<% } %>
<%
// submitter create new version button
if (submitter_button && hasVersionButton) {
%>
<dspace:sidebar>
<div class="panel panel-warning">
<div class="panel-heading"><fmt:message key="jsp.submittertools"/></div>
<div class="panel-body">
<form method="get" action="<%= request.getContextPath()%>/tools/version">
<input type="hidden" name="itemID" value="<%= item.getID()%>" />
<input class="btn btn-default col-md-12" type="submit" name="submit" value="<fmt:message key="jsp.general.version.button"/>" />
</form>
</div>
</div>
</dspace:sidebar>
<%
}
}
String displayStyle = (displayAll ? "full" : "");

View File

@@ -14,3 +14,7 @@ versioning.item.history.view.admin=false
# the submitter of a version should be included in the version history of
# an item.
versioning.item.history.include.submitter=false
# If you want to allow submitters to create new versions of there items, set
# the property submitterCanCreateNewVersion true.
versioning.submitterCanCreateNewVersion=true