mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-13 13:03:11 +00:00
Merge pull request #8522 from qzhao-ulb/patch-6
Item/Collection admin can't create new version item
This commit is contained in:
@@ -111,7 +111,7 @@ public class VersionRestRepository extends DSpaceRestRepository<VersionRest, Int
|
|||||||
}
|
}
|
||||||
|
|
||||||
EPerson submitter = item.getSubmitter();
|
EPerson submitter = item.getSubmitter();
|
||||||
boolean isAdmin = authorizeService.isAdmin(context);
|
boolean isAdmin = authorizeService.isAdmin(context, item);
|
||||||
boolean canCreateVersion = configurationService.getBooleanProperty("versioning.submitterCanCreateNewVersion");
|
boolean canCreateVersion = configurationService.getBooleanProperty("versioning.submitterCanCreateNewVersion");
|
||||||
|
|
||||||
if (!isAdmin && !(canCreateVersion && Objects.equals(submitter, context.getCurrentUser()))) {
|
if (!isAdmin && !(canCreateVersion && Objects.equals(submitter, context.getCurrentUser()))) {
|
||||||
|
@@ -850,6 +850,55 @@ public class VersionRestRepositoryIT extends AbstractControllerIntegrationTest {
|
|||||||
.andExpect(status().isUnauthorized());
|
.andExpect(status().isUnauthorized());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createNewVersionItemByCollectionAdminTest() throws Exception {
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
Community rootCommunity = CommunityBuilder.createCommunity(context)
|
||||||
|
.withName("Parent Community")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
EPerson colAdmin = EPersonBuilder.createEPerson(context)
|
||||||
|
.withCanLogin(true)
|
||||||
|
.withEmail("coladmin@email.com")
|
||||||
|
.withPassword(password)
|
||||||
|
.withNameInMetadata("Collection", "Admin")
|
||||||
|
.build();
|
||||||
|
Collection col = CollectionBuilder
|
||||||
|
.createCollection(context, rootCommunity)
|
||||||
|
.withName("Collection 1")
|
||||||
|
.withAdminGroup(colAdmin)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Item item = ItemBuilder.createItem(context, col)
|
||||||
|
.withTitle("Public test item")
|
||||||
|
.withIssueDate("2022-12-19")
|
||||||
|
.withAuthor("Doe, John")
|
||||||
|
.withSubject("ExtraEntry")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
item.setSubmitter(eperson);
|
||||||
|
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
AtomicReference<Integer> idRef = new AtomicReference<Integer>();
|
||||||
|
String token = getAuthToken(colAdmin.getEmail(), password);
|
||||||
|
try {
|
||||||
|
getClient(token).perform(post("/api/versioning/versions")
|
||||||
|
.param("summary", "test summary!")
|
||||||
|
.contentType(MediaType.parseMediaType(RestMediaTypes.TEXT_URI_LIST_VALUE))
|
||||||
|
.content("/api/core/items/" + item.getID()))
|
||||||
|
.andExpect(status().isCreated())
|
||||||
|
.andExpect(jsonPath("$", Matchers.allOf(
|
||||||
|
hasJsonPath("$.version", is(2)),
|
||||||
|
hasJsonPath("$.summary", is("test summary!")),
|
||||||
|
hasJsonPath("$.type", is("version"))
|
||||||
|
)))
|
||||||
|
.andDo(result -> idRef.set(read(result.getResponse().getContentAsString(), "$.id")));
|
||||||
|
} finally {
|
||||||
|
VersionBuilder.delete(idRef.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void patchReplaceSummaryTest() throws Exception {
|
public void patchReplaceSummaryTest() throws Exception {
|
||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
|
Reference in New Issue
Block a user