mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-15 05:53:08 +00:00
DS-1814: Don't allow submitters to update all of their own items
This commit is contained in:
@@ -408,7 +408,7 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
|
|||||||
public void update(Context context, Item item) throws SQLException, AuthorizeException {
|
public void update(Context context, Item item) throws SQLException, AuthorizeException {
|
||||||
// Check authorisation
|
// Check authorisation
|
||||||
// only do write authorization if user is not an editor
|
// only do write authorization if user is not an editor
|
||||||
if (!canEdit(context, item) && !canCreateNewVersion(context, item))
|
if (!canEdit(context, item))
|
||||||
{
|
{
|
||||||
authorizeService.authorizeAction(context, item, Constants.WRITE);
|
authorizeService.authorizeAction(context, item, Constants.WRITE);
|
||||||
}
|
}
|
||||||
|
@@ -23,6 +23,7 @@ import java.util.List;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.authorize.ResourcePolicy;
|
import org.dspace.authorize.ResourcePolicy;
|
||||||
import org.dspace.versioning.service.VersioningService;
|
import org.dspace.versioning.service.VersioningService;
|
||||||
|
import org.dspace.workflow.WorkflowItemService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -39,6 +40,8 @@ public class DefaultItemVersionProvider extends AbstractVersionProvider implemen
|
|||||||
@Autowired(required = true)
|
@Autowired(required = true)
|
||||||
protected WorkspaceItemService workspaceItemService;
|
protected WorkspaceItemService workspaceItemService;
|
||||||
@Autowired(required = true)
|
@Autowired(required = true)
|
||||||
|
protected WorkflowItemService workflowItemService;
|
||||||
|
@Autowired(required = true)
|
||||||
protected VersionHistoryService versionHistoryService;
|
protected VersionHistoryService versionHistoryService;
|
||||||
@Autowired(required = true)
|
@Autowired(required = true)
|
||||||
protected VersioningService versioningService;
|
protected VersioningService versioningService;
|
||||||
@@ -69,11 +72,21 @@ public class DefaultItemVersionProvider extends AbstractVersionProvider implemen
|
|||||||
if(versionHistoryService.isLastVersion(c, history, versionToDelete)
|
if(versionHistoryService.isLastVersion(c, history, versionToDelete)
|
||||||
&& versioningService.getVersionsByHistory(c, history).size() > 1)
|
&& versioningService.getVersionsByHistory(c, history).size() > 1)
|
||||||
{
|
{
|
||||||
// reset the previous version to archived
|
// if a new version gets archived, the old one is set to false.
|
||||||
|
// we need to do the oposite now, if the old version was previously
|
||||||
|
// unarchived. If the old version is still archived, the new
|
||||||
|
// version is a WorkspaceItem or WorkflowItem we should skip this,
|
||||||
|
// as unarchiving of previous versions is done only when a newer
|
||||||
|
// version gets archived.
|
||||||
Item item = versionHistoryService.getPrevious(c, history, versionToDelete).getItem();
|
Item item = versionHistoryService.getPrevious(c, history, versionToDelete).getItem();
|
||||||
|
if (!item.isArchived()
|
||||||
|
|| workspaceItemService.findByItem(c, versionToDelete.getItem()) != null
|
||||||
|
|| workflowItemService.findByItem(c, versionToDelete.getItem()) != null)
|
||||||
|
{
|
||||||
item.setArchived(true);
|
item.setArchived(true);
|
||||||
itemService.update(c, item);
|
itemService.update(c, item);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// assign tombstone to the Identifier and reset canonical to the previous version only if there is a previous version
|
// assign tombstone to the Identifier and reset canonical to the previous version only if there is a previous version
|
||||||
Item itemToDelete=versionToDelete.getItem();
|
Item itemToDelete=versionToDelete.getItem();
|
||||||
|
@@ -22,6 +22,8 @@ import org.springframework.beans.factory.annotation.Required;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.dspace.content.WorkspaceItem;
|
||||||
|
import org.dspace.content.service.WorkspaceItemService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -39,6 +41,8 @@ public class VersioningServiceImpl implements VersioningService {
|
|||||||
protected VersionDAO versionDAO;
|
protected VersionDAO versionDAO;
|
||||||
@Autowired(required = true)
|
@Autowired(required = true)
|
||||||
private ItemService itemService;
|
private ItemService itemService;
|
||||||
|
@Autowired(required = true)
|
||||||
|
private WorkspaceItemService workspaceItemService;
|
||||||
private DefaultItemVersionProvider provider;
|
private DefaultItemVersionProvider provider;
|
||||||
|
|
||||||
@Required
|
@Required
|
||||||
@@ -129,8 +133,17 @@ public class VersioningServiceImpl implements VersioningService {
|
|||||||
|
|
||||||
// Completely delete the item
|
// Completely delete the item
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
|
// DS-1814 introduce the possibility that submitter can create
|
||||||
|
// new versions. To avoid authorithation problems we need to
|
||||||
|
// check whether a corresponding workspaceItem exists.
|
||||||
|
WorkspaceItem wsi = workspaceItemService.findByItem(c, item);
|
||||||
|
if (wsi != null)
|
||||||
|
{
|
||||||
|
workspaceItemService.deleteAll(c, wsi);
|
||||||
|
} else {
|
||||||
itemService.delete(c, item);
|
itemService.delete(c, item);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
c.abort();
|
c.abort();
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
|
Reference in New Issue
Block a user