Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Dataset DOI in check permissions API request #8995

Merged
merged 25 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
694e510
allow slash in check permissions api request
ErykKul Sep 26, 2022
d57e749
added findDatasetOrDie lookup method in find permissions api
ErykKul Sep 27, 2022
9b64cf5
Merge branch 'IQSS:develop' into 8994_permissions
ErykKul Sep 27, 2022
850f4c6
added a note on listing permissions on a dataset using a persistentId
ErykKul Sep 28, 2022
2c0a230
Merge branch 'IQSS:develop' into 8994_permissions
ErykKul Nov 7, 2022
b4e4833
Merge branch 'IQSS:develop' into 8994_permissions
ErykKul Apr 21, 2023
e0b30b7
Merge branch 'IQSS:develop' into 8994_permissions
ErykKul May 12, 2023
a8b2a2a
Merge branch 'IQSS:develop' into 8994_permissions
ErykKul May 17, 2023
b3457df
Merge branch 'IQSS:develop' into 8994_permissions
ErykKul May 22, 2023
0aedfd8
Merge branch 'IQSS:develop' into 8994_permissions
ErykKul May 26, 2023
378ec4d
Merge branch 'IQSS:develop' into 8994_permissions
ErykKul Jun 9, 2023
d636792
Merge branch 'IQSS:develop' into 8994_permissions
ErykKul Jun 15, 2023
5bdca3a
Merge branch 'IQSS:develop' into 8994_permissions
ErykKul Jun 16, 2023
fbfbd6c
Merge branch 'IQSS:develop' into 8994_permissions
ErykKul Sep 1, 2023
ae5ff7a
Merge branch 'IQSS:develop' into 8994_permissions
ErykKul Sep 6, 2023
6898f4c
Merge branch 'IQSS:develop' into 8994_permissions
ErykKul Sep 18, 2023
9430e27
findPermissionsOn improvements
ErykKul Sep 19, 2023
9adfe84
code format -> removed tabs, etc.
ErykKul Sep 19, 2023
d31596a
removed newline
ErykKul Sep 19, 2023
fad1c82
removed added newlines
ErykKul Sep 19, 2023
fcaeb27
Merge branch 'IQSS:develop' into 8994_permissions
ErykKul Sep 27, 2023
2a59ac7
Merge branch 'IQSS:develop' into 8994_permissions
ErykKul Oct 18, 2023
7fd9960
Merge branch 'IQSS:develop' into 8994_permissions
ErykKul Nov 10, 2023
c526bc6
merged develop branch
ErykKul Apr 17, 2024
b67c731
added missing double quotes
ErykKul Apr 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions doc/sphinx-guides/source/api/native-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5002,6 +5002,17 @@ List permissions a user (based on API Token used) has on a Dataverse collection

The ``$identifier`` can be a Dataverse collection alias or database id or a dataset persistent ID or database id.

.. note:: Datasets can be selected using persistent identifiers. This is done by passing the constant ``:persistentId`` where the numeric id of the dataset is expected, and then passing the actual persistent id as a query parameter with the name ``persistentId``.

Example: List permissions a user (based on API Token used) has on a dataset whose DOI is *10.5072/FK2/J8SJZB*:

.. code-block:: bash

export SERVER_URL=https://demo.dataverse.org
export PERSISTENT_IDENTIFIER=doi:10.5072/FK2/J8SJZB

curl -H "X-Dataverse-key:$API_TOKEN" $SERVER_URL/api/admin/permissions/:persistentId?persistentId=$PERSISTENT_IDENTIFIER

Show Role Assignee
~~~~~~~~~~~~~~~~~~

Expand Down
21 changes: 13 additions & 8 deletions src/main/java/edu/harvard/iq/dataverse/api/AbstractApiBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import jakarta.persistence.NoResultException;
import jakarta.persistence.PersistenceContext;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.container.ContainerRequestContext;
import jakarta.ws.rs.core.*;
import jakarta.ws.rs.core.Response.ResponseBuilder;
Expand Down Expand Up @@ -526,17 +527,21 @@ protected DvObject findDvo( Long id ) {
* with that alias. If that fails, tries to get a {@link Dataset} with that global id.
* @param id a value identifying the DvObject, either numeric of textual.
* @return A DvObject, or {@code null}
* @throws WrappedResponse
*/
protected DvObject findDvo( String id ) {
if ( isNumeric(id) ) {
return findDvo( Long.valueOf(id)) ;
@NotNull
protected DvObject findDvo(@NotNull final String id) throws WrappedResponse {
DvObject d = null;
if (isNumeric(id)) {
d = findDvo(Long.valueOf(id));
} else {
Dataverse d = dataverseSvc.findByAlias(id);
return ( d != null ) ?
d : datasetSvc.findByGlobalId(id);

d = dataverseSvc.findByAlias(id);
}
}
if (d == null) {
return findDatasetOrDie(id);
}
return d;
}

protected <T> T failIfNull( T t, String errorMessage ) throws WrappedResponse {
if ( t != null ) return t;
Expand Down
38 changes: 18 additions & 20 deletions src/main/java/edu/harvard/iq/dataverse/api/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -1327,26 +1327,24 @@ public Response convertUserFromBcryptToSha1(String json) {

}

@Path("permissions/{dvo}")
@AuthRequired
@GET
public Response findPermissonsOn(@Context ContainerRequestContext crc, @PathParam("dvo") String dvo) {
try {
DvObject dvObj = findDvo(dvo);
if (dvObj == null) {
return notFound("DvObject " + dvo + " not found");
}
User aUser = getRequestUser(crc);
JsonObjectBuilder bld = Json.createObjectBuilder();
bld.add("user", aUser.getIdentifier());
bld.add("permissions", json(permissionSvc.permissionsFor(createDataverseRequest(aUser), dvObj)));
return ok(bld);

} catch (Exception e) {
logger.log(Level.SEVERE, "Error while testing permissions", e);
return error(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
}
}
@Path("permissions/{dvo}")
@AuthRequired
@GET
public Response findPermissonsOn(@Context final ContainerRequestContext crc, @PathParam("dvo") final String dvo) {
try {
final DvObject dvObj = findDvo(dvo);
final User aUser = getRequestUser(crc);
final JsonObjectBuilder bld = Json.createObjectBuilder();
bld.add("user", aUser.getIdentifier());
bld.add("permissions", json(permissionSvc.permissionsFor(createDataverseRequest(aUser), dvObj)));
return ok(bld);
} catch (WrappedResponse r) {
return r.getResponse();
} catch (Exception e) {
logger.log(Level.SEVERE, "Error while testing permissions", e);
return error(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
}
}

@Path("assignee/{idtf}")
@GET
Expand Down
Loading