Skip to content

Commit

Permalink
Merge pull request DSpace#9320 from 4Science/DURACOM-232
Browse files Browse the repository at this point in the history
Community/Collection admins can't edit logo for communities/collections
  • Loading branch information
alanorth authored Feb 22, 2024
2 parents 080a9b8 + d181286 commit 8f8c304
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 0 deletions.
8 changes: 8 additions & 0 deletions dspace-api/src/main/java/org/dspace/content/Bitstream.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,18 @@ public Collection getCollection() {
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
*
Expand Down
3 changes: 3 additions & 0 deletions dspace-api/src/main/java/org/dspace/content/Collection.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ public Bitstream getLogo() {

protected void setLogo(Bitstream logo) {
this.logo = logo;
if (logo != null) {
logo.setCollection(this);
}
setModified();
}

Expand Down
3 changes: 3 additions & 0 deletions dspace-api/src/main/java/org/dspace/content/Community.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ public Bitstream getLogo() {

void setLogo(Bitstream logo) {
this.logo = logo;
if (logo != null) {
logo.setCommunity(this);
}
setModified();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
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;
Expand Down Expand Up @@ -93,6 +96,34 @@ public void createLogoNoRights() throws Exception {
.andExpect(status().isForbidden());
}

@Test
public void createLogoByCollectionAdmin() throws Exception {
context.turnOffAuthorisationSystem();

EPerson collectionAdmin = EPersonBuilder.createEPerson(context)
.withEmail("[email protected]")
.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(
Expand Down Expand Up @@ -142,6 +173,42 @@ public void deleteLogoNoRights() throws Exception {
.andExpect(status().isForbidden());
}

@Test
public void deleteLogoByCollectionAdmin() throws Exception {
context.turnOffAuthorisationSystem();

EPerson collectionAdmin = EPersonBuilder.createEPerson(context)
.withEmail("[email protected]")
.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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
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;
Expand Down Expand Up @@ -88,6 +91,29 @@ public void createLogoNoRights() throws Exception {
.andExpect(status().isForbidden());
}

@Test
public void createLogoBYCommunityAdmin() throws Exception {
context.turnOffAuthorisationSystem();

EPerson communityAdmin = EPersonBuilder.createEPerson(context)
.withEmail("[email protected]")
.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(
Expand Down Expand Up @@ -137,6 +163,38 @@ public void deleteLogoNoRights() throws Exception {
.andExpect(status().isForbidden());
}

@Test
public void deleteLogoByCommunityAdmin() throws Exception {
context.turnOffAuthorisationSystem();

EPerson communityAdmin = EPersonBuilder.createEPerson(context)
.withEmail("[email protected]")
.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";
}
Expand Down

0 comments on commit 8f8c304

Please sign in to comment.