mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Merge pull request #9320 from 4Science/DURACOM-232
Community/Collection admins can't edit logo for communities/collections
This commit is contained in:
@@ -307,10 +307,18 @@ public class Bitstream extends DSpaceObject implements DSpaceObjectLegacySupport
|
||||
return collection;
|
||||
}
|
||||
|
||||
public void setCollection(Collection collection) {
|
||||
this.collection = collection;
|
||||
}
|
||||
|
||||
public Community getCommunity() {
|
||||
return community;
|
||||
}
|
||||
|
||||
public void setCommunity(Community community) {
|
||||
this.community = community;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the asset store number where this bitstream is stored
|
||||
*
|
||||
|
@@ -135,6 +135,9 @@ public class Collection extends DSpaceObject implements DSpaceObjectLegacySuppor
|
||||
|
||||
protected void setLogo(Bitstream logo) {
|
||||
this.logo = logo;
|
||||
if (logo != null) {
|
||||
logo.setCollection(this);
|
||||
}
|
||||
setModified();
|
||||
}
|
||||
|
||||
|
@@ -123,6 +123,9 @@ public class Community extends DSpaceObject implements DSpaceObjectLegacySupport
|
||||
|
||||
void setLogo(Bitstream logo) {
|
||||
this.logo = logo;
|
||||
if (logo != null) {
|
||||
logo.setCommunity(this);
|
||||
}
|
||||
setModified();
|
||||
}
|
||||
|
||||
|
@@ -17,7 +17,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||
import org.dspace.builder.CollectionBuilder;
|
||||
import org.dspace.builder.CommunityBuilder;
|
||||
import org.dspace.builder.EPersonBuilder;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -93,6 +96,34 @@ public class CollectionLogoControllerIT extends AbstractControllerIntegrationTes
|
||||
.andExpect(status().isForbidden());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createLogoByCollectionAdmin() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
EPerson collectionAdmin = EPersonBuilder.createEPerson(context)
|
||||
.withEmail("test4@mail.com")
|
||||
.withPassword(password)
|
||||
.withCanLogin(true)
|
||||
.build();
|
||||
|
||||
Community community = CommunityBuilder.createCommunity(context)
|
||||
.withName("New Community")
|
||||
.build();
|
||||
|
||||
childCollection = CollectionBuilder.createCollection(context, community)
|
||||
.withName("name of collection")
|
||||
.withAdminGroup(collectionAdmin)
|
||||
.build();
|
||||
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
String userToken = getAuthToken(collectionAdmin.getEmail(), password);
|
||||
getClient(userToken).perform(
|
||||
MockMvcRequestBuilders.multipart(getLogoUrlTemplate(childCollection.getID().toString()))
|
||||
.file(bitstreamFile))
|
||||
.andExpect(status().isCreated());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDuplicateLogo() throws Exception {
|
||||
getClient(adminAuthToken).perform(
|
||||
@@ -142,6 +173,42 @@ public class CollectionLogoControllerIT extends AbstractControllerIntegrationTes
|
||||
.andExpect(status().isForbidden());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteLogoByCollectionAdmin() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
EPerson collectionAdmin = EPersonBuilder.createEPerson(context)
|
||||
.withEmail("test4@mail.com")
|
||||
.withPassword(password)
|
||||
.withCanLogin(true)
|
||||
.build();
|
||||
|
||||
Community community = CommunityBuilder.createCommunity(context)
|
||||
.withName("New Community")
|
||||
.build();
|
||||
|
||||
childCollection = CollectionBuilder.createCollection(context, community)
|
||||
.withName("name of collection")
|
||||
.withAdminGroup(collectionAdmin)
|
||||
.build();
|
||||
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
String userToken = getAuthToken(collectionAdmin.getEmail(), password);
|
||||
MvcResult mvcPostResult = getClient(userToken).perform(
|
||||
MockMvcRequestBuilders.multipart(getLogoUrlTemplate(childCollection.getID().toString()))
|
||||
.file(bitstreamFile))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
|
||||
String postContent = mvcPostResult.getResponse().getContentAsString();
|
||||
Map<String, Object> mapPostResult = mapper.readValue(postContent, Map.class);
|
||||
|
||||
getClient(userToken)
|
||||
.perform(delete(getBitstreamUrlTemplate(String.valueOf(mapPostResult.get("uuid")))))
|
||||
.andExpect(status().isNoContent());
|
||||
}
|
||||
|
||||
private String getLogoUrlTemplate(String uuid) {
|
||||
return "/api/core/collections/" + uuid + "/logo";
|
||||
}
|
||||
|
@@ -16,6 +16,9 @@ import java.util.Map;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||
import org.dspace.builder.CommunityBuilder;
|
||||
import org.dspace.builder.EPersonBuilder;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -88,6 +91,29 @@ public class CommunityLogoControllerIT extends AbstractControllerIntegrationTest
|
||||
.andExpect(status().isForbidden());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createLogoBYCommunityAdmin() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
EPerson communityAdmin = EPersonBuilder.createEPerson(context)
|
||||
.withEmail("test4@mail.com")
|
||||
.withPassword(password)
|
||||
.withCanLogin(true)
|
||||
.build();
|
||||
|
||||
Community community = CommunityBuilder.createCommunity(context)
|
||||
.withName("New Community")
|
||||
.withAdminGroup(communityAdmin)
|
||||
.build();
|
||||
|
||||
context.restoreAuthSystemState();
|
||||
String userToken = getAuthToken(communityAdmin.getEmail(), password);
|
||||
getClient(userToken).perform(
|
||||
MockMvcRequestBuilders.multipart(getLogoUrlTemplate(community.getID().toString()))
|
||||
.file(bitstreamFile))
|
||||
.andExpect(status().isCreated());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDuplicateLogo() throws Exception {
|
||||
getClient(adminAuthToken).perform(
|
||||
@@ -137,6 +163,38 @@ public class CommunityLogoControllerIT extends AbstractControllerIntegrationTest
|
||||
.andExpect(status().isForbidden());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteLogoByCommunityAdmin() throws Exception {
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
EPerson communityAdmin = EPersonBuilder.createEPerson(context)
|
||||
.withEmail("test4@mail.com")
|
||||
.withPassword(password)
|
||||
.withCanLogin(true)
|
||||
.build();
|
||||
|
||||
Community community = CommunityBuilder.createCommunity(context)
|
||||
.withName("New Community")
|
||||
.withAdminGroup(communityAdmin)
|
||||
.build();
|
||||
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
String userToken = getAuthToken(communityAdmin.getEmail(), password);
|
||||
MvcResult mvcPostResult = getClient(userToken).perform(
|
||||
MockMvcRequestBuilders.multipart(getLogoUrlTemplate(community.getID().toString()))
|
||||
.file(bitstreamFile))
|
||||
.andExpect(status().isCreated())
|
||||
.andReturn();
|
||||
|
||||
String postContent = mvcPostResult.getResponse().getContentAsString();
|
||||
Map<String, Object> mapPostResult = mapper.readValue(postContent, Map.class);
|
||||
|
||||
getClient(userToken)
|
||||
.perform(delete(getBitstreamUrlTemplate(String.valueOf(mapPostResult.get("uuid")))))
|
||||
.andExpect(status().isNoContent());
|
||||
}
|
||||
|
||||
private String getLogoUrlTemplate(String uuid) {
|
||||
return "/api/core/communities/" + uuid + "/logo";
|
||||
}
|
||||
|
Reference in New Issue
Block a user