forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added authorization for the `Edit Item - License` menu option. * Created endpoint for updating license of the Item. * Added functionality only for detaching the license.
- Loading branch information
1 parent
7232e97
commit cae7292
Showing
2 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...-server-webapp/src/main/java/org/dspace/app/rest/authorization/impl/CanManageLicense.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* The contents of this file are subject to the license and copyright | ||
* detailed in the LICENSE and NOTICE files at the root of the source | ||
* tree and available online at | ||
* | ||
* http://www.dspace.org/license/ | ||
*/ | ||
package org.dspace.app.rest.authorization.impl; | ||
|
||
import java.sql.SQLException; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
import org.dspace.app.rest.authorization.AuthorizationFeature; | ||
import org.dspace.app.rest.authorization.AuthorizationFeatureDocumentation; | ||
import org.dspace.app.rest.model.BaseObjectRest; | ||
import org.dspace.app.rest.model.ItemRest; | ||
import org.dspace.authorize.service.AuthorizeService; | ||
import org.dspace.content.Item; | ||
import org.dspace.content.service.ItemService; | ||
import org.dspace.core.Context; | ||
import org.dspace.discovery.SearchServiceException; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@AuthorizationFeatureDocumentation(name = CanManageLicense.NAME, | ||
description = "It can be used to verify if the user can attach/detach a license to an Item") | ||
public class CanManageLicense implements AuthorizationFeature { | ||
|
||
public static final String NAME = "canManageLicense"; | ||
|
||
@Autowired | ||
private ItemService itemService; | ||
@Autowired | ||
private AuthorizeService authorizeService; | ||
|
||
@Override | ||
public boolean isAuthorized(Context context, BaseObjectRest object) throws SQLException, SearchServiceException { | ||
Item item = itemService.find(context, UUID.fromString(((ItemRest) object).getUuid())); | ||
if (Objects.nonNull(item)) { | ||
return authorizeService.isAdmin(context, item); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public String[] getSupportedTypes() { | ||
return new String[]{ | ||
ItemRest.CATEGORY + "." + ItemRest.NAME | ||
}; | ||
} | ||
} |