Skip to content

Commit

Permalink
Fix error message for attempts to delete IP groups that have assinged…
Browse files Browse the repository at this point in the history
… roles
  • Loading branch information
michbarsinai committed Aug 4, 2016
1 parent a336475 commit 2ee3fad
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
12 changes: 12 additions & 0 deletions scripts/issues/1380/02-build-dv-structure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

echo Run this after running setup-users.sh, and making Pete an
echo admin on the root dataverse.


PETE=$(grep :result: users.out | grep Pete | cut -f4 -d: | tr -d \ )
UMA=$(grep :result: users.out | grep Uma | cut -f4 -d: | tr -d \ )

pushd ../../api
./setup-dvs.sh $PETE $UMA
popd
9 changes: 9 additions & 0 deletions scripts/issues/1380/delete-ip-group
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#/bin/bahx
if [ $# -eq 0 ]
then
echo "Please provide IP group id"
echo "e.g $0 845"
exit 1
fi

curl -X DELETE http://localhost:8080/api/admin/groups/ip/$1
3 changes: 3 additions & 0 deletions scripts/issues/1380/keys.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Keys for Pete and Uma. Produced by running setup-all.sh from the /scripts/api folder.
Pete:757a6493-456a-4bf0-943e-9b559d551a3f
Uma:8797f19b-b8aa-4f96-a789-1b99506f2eab
6 changes: 6 additions & 0 deletions scripts/issues/1380/users.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{"status":"OK","data":{"user":{"id":4,"firstName":"Gabbi","lastName":"Guest","userName":"gabbi","affiliation":"low","position":"A Guest","email":"gabbi@malinator.com"},"authenticatedUser":{"id":4,"identifier":"@gabbi","displayName":"Gabbi Guest","firstName":"Gabbi","lastName":"Guest","email":"gabbi@malinator.com","superuser":false,"affiliation":"low","position":"A Guest","persistentUserId":"gabbi","authenticationProviderId":"builtin"},"apiToken":"d1940786-c315-491e-9812-a8ff809289cc"}}
{"status":"OK","data":{"user":{"id":5,"firstName":"Cathy","lastName":"Collaborator","userName":"cathy","affiliation":"mid","position":"Data Scientist","email":"cathy@malinator.com"},"authenticatedUser":{"id":5,"identifier":"@cathy","displayName":"Cathy Collaborator","firstName":"Cathy","lastName":"Collaborator","email":"cathy@malinator.com","superuser":false,"affiliation":"mid","position":"Data Scientist","persistentUserId":"cathy","authenticationProviderId":"builtin"},"apiToken":"0ddfcb1e-fb51-4ce7-88ab-308b23e13e9a"}}
{"status":"OK","data":{"user":{"id":6,"firstName":"Nick","lastName":"NSA","userName":"nick","affiliation":"gov","position":"Signals Intelligence","email":"nick@malinator.com"},"authenticatedUser":{"id":6,"identifier":"@nick","displayName":"Nick NSA","firstName":"Nick","lastName":"NSA","email":"nick@malinator.com","superuser":false,"affiliation":"gov","position":"Signals Intelligence","persistentUserId":"nick","authenticationProviderId":"builtin"},"apiToken":"6d74745d-1733-459a-ae29-422110056ec0"}}
reporting API keys
:result: Pete's key is: 757a6493-456a-4bf0-943e-9b559d551a3f
:result: Uma's key is: 8797f19b-b8aa-4f96-a789-1b99506f2eab
15 changes: 13 additions & 2 deletions src/main/java/edu/harvard/iq/dataverse/api/Groups.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import javax.json.JsonArrayBuilder;
import javax.json.JsonObject;
import javax.json.JsonString;
import javax.transaction.TransactionRolledbackException;
import javax.ws.rs.DELETE;
import javax.ws.rs.POST;
import javax.ws.rs.PathParam;
Expand Down Expand Up @@ -99,8 +100,18 @@ public Response deleteIpGroup( @PathParam("groupIdtf") String groupIdtf ) {
try {
ipGroupPrv.deleteGroup(grp);
return okResponse("Group " + grp.getAlias() + " deleted.");
} catch ( IllegalArgumentException ex ) {
return errorResponse(Response.Status.BAD_REQUEST, ex.getMessage());
} catch ( Exception topExp ) {
// get to the cause (unwraps EJB exception wrappers).
Throwable e = topExp;
while ( e.getCause() != null ) {
e = e.getCause();
}

if ( e instanceof IllegalArgumentException ) {
return errorResponse(Response.Status.BAD_REQUEST, e.getMessage());
} else {
throw topExp;
}
}
}

Expand Down

0 comments on commit 2ee3fad

Please sign in to comment.