Skip to content

Commit

Permalink
Merge pull request #2747 from atmire/w2p-70402_Manage-account-profile
Browse files Browse the repository at this point in the history
Account profile management
  • Loading branch information
abollini committed May 10, 2020
2 parents 7934736 + 36914e1 commit ea746e2
Show file tree
Hide file tree
Showing 8 changed files with 268 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ private void add(Context context, DSpaceObject dso, DSpaceObjectService dsoServi

@Override
public boolean supports(Object objectToMatch, Operation operation) {
return ((operation.getPath().startsWith(metadataPatchUtils.OPERATION_METADATA_PATH)
|| operation.getPath().equals(metadataPatchUtils.OPERATION_METADATA_PATH))
return (operation.getPath().startsWith(metadataPatchUtils.OPERATION_METADATA_PATH)
&& operation.getOp().trim().equalsIgnoreCase(OPERATION_ADD)
&& objectToMatch instanceof DSpaceObject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ private void copy(Context context, DSpaceObject dso, DSpaceObjectService dsoServ

@Override
public boolean supports(Object objectToMatch, Operation operation) {
return ((operation.getPath().startsWith(metadataPatchUtils.OPERATION_METADATA_PATH)
|| operation.getPath().equals(metadataPatchUtils.OPERATION_METADATA_PATH))
return (operation.getPath().startsWith(metadataPatchUtils.OPERATION_METADATA_PATH)
&& operation.getOp().trim().equalsIgnoreCase(OPERATION_COPY)
&& objectToMatch instanceof DSpaceObject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ private void move(Context context, DSpaceObject dso,

@Override
public boolean supports(Object objectToMatch, Operation operation) {
return ((operation.getPath().startsWith(metadataPatchUtils.OPERATION_METADATA_PATH)
|| operation.getPath().equals(metadataPatchUtils.OPERATION_METADATA_PATH))
return (operation.getPath().startsWith(metadataPatchUtils.OPERATION_METADATA_PATH)
&& operation.getOp().trim().equalsIgnoreCase(OPERATION_MOVE)
&& objectToMatch instanceof DSpaceObject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class DSpaceObjectMetadataPatchUtils {
/**
* Path in json body of patch that uses these metadata operations
*/
protected static final String OPERATION_METADATA_PATH = "/metadata";
public static final String OPERATION_METADATA_PATH = "/metadata";

private DSpaceObjectMetadataPatchUtils() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ private void remove(Context context, DSpaceObject dso, DSpaceObjectService dsoSe

@Override
public boolean supports(Object objectToMatch, Operation operation) {
return ((operation.getPath().startsWith(metadataPatchUtils.OPERATION_METADATA_PATH)
|| operation.getPath().equals(metadataPatchUtils.OPERATION_METADATA_PATH))
return (operation.getPath().startsWith(metadataPatchUtils.OPERATION_METADATA_PATH)
&& operation.getOp().trim().equalsIgnoreCase(OPERATION_REMOVE)
&& objectToMatch instanceof DSpaceObject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ private void replaceSinglePropertyOfMdValue(DSpaceObject dso, DSpaceObjectServic

@Override
public boolean supports(Object objectToMatch, Operation operation) {
return ((operation.getPath().startsWith(metadataPatchUtils.OPERATION_METADATA_PATH)
|| operation.getPath().equals(metadataPatchUtils.OPERATION_METADATA_PATH))
return (operation.getPath().startsWith(metadataPatchUtils.OPERATION_METADATA_PATH)
&& operation.getOp().trim().equalsIgnoreCase(OPERATION_REPLACE)
&& objectToMatch instanceof DSpaceObject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.dspace.app.rest.model.patch.Operation;
import org.dspace.app.rest.model.patch.Patch;
import org.dspace.app.rest.repository.patch.operation.DSpaceObjectMetadataPatchUtils;
import org.dspace.app.rest.repository.patch.operation.EPersonPasswordReplaceOperation;
import org.dspace.app.rest.utils.ContextUtil;
import org.dspace.authorize.service.AuthorizeService;
Expand Down Expand Up @@ -102,10 +103,11 @@ public boolean hasPatchPermission(Authentication authentication, Serializable ta
/**
* The entire Patch request should be denied if it contains operations that are
* restricted to Dspace administrators. The authenticated user is currently allowed to
* update their own password.
* update their own password and their own metadata.
*/
for (Operation op: operations) {
if (!op.getPath().contentEquals(EPersonPasswordReplaceOperation.OPERATION_PASSWORD_CHANGE)) {
if (!(op.getPath().contentEquals(EPersonPasswordReplaceOperation.OPERATION_PASSWORD_CHANGE)
|| (op.getPath().startsWith(DSpaceObjectMetadataPatchUtils.OPERATION_METADATA_PATH)))) {
return false;
}
}
Expand Down
Loading

0 comments on commit ea746e2

Please sign in to comment.