gdcc / pyDataverse

Python module for Dataverse Software (dataverse.org).
http://pydataverse.readthedocs.io/
MIT License
63 stars 41 forks source link

Delete Roles via API not working #112

Open veustp opened 3 years ago

veustp commented 3 years ago

using Windows 64bit pydataverse 0.3.0 python 3.7.9 dataverse v. 4.20 build 413-4e07b62

Using NativeApi calls

apiProd = NativeApi(baseUrlProd, apiKeyProd)

To Get A Role:

resp = apiProd.get_request(baseUrlProd+"/api/roles/10")
{'status': 'OK', 'data': {'alias': 'rev', 'name': 'reviewer', 'permissions': [], 'description': 'ReviewerRole', 'id': 11, 'ownerId': 1}}

The role is found - no problem here.

To Delete A Role:

resp = apiProd.delete_request(baseUrlProd+"/api/roles/10")
{'status': 'ERROR', 'message': 'Command edu.harvard.iq.dataverse.engine.command.impl.DeleteRoleCommand@721061c3 failed: Exception thrown from bean: javax.ejb.EJBTransactionRolledbackException: Exception thrown from bean: java.lang.IllegalArgumentException: You have attempted to set a value of type class java.lang.Long for parameter roleId with expected type of class edu.harvard.iq.dataverse.authorization.DataverseRole from query string SELECT r FROM RoleAssignment r WHERE r.role=:roleId.'}

Deleting the role does not work.

Using the standard requests module:

import requests
headers = {'X-Dataverse-key':apiKeyProd,
               'Content-Type':'application/json'}
r = requests.get(baseUrlProd+'/api/roles/11', headers=headers)
# Getting the role works
b'{"status":"OK","data":{"alias":"rev","name":"reviewer","permissions":[],"description":"ReviewerRole","id":11,"ownerId":1}}'

Deleting the role:

r = requests.delete(baseUrlProd+'/api/roles/11', headers=headers)
b'{"status":"ERROR","message":"Command edu.harvard.iq.dataverse.engine.command.impl.DeleteRoleCommand@7bd352e6 failed: Exception thrown from bean: javax.ejb.EJBTransactionRolledbackException: Exception thrown from bean: java.lang.IllegalArgumentException: You have attempted to set a value of type class java.lang.Long for parameter roleId with expected type of class edu.harvard.iq.dataverse.authorization.DataverseRole from query string SELECT r FROM RoleAssignment r WHERE r.role=:roleId."}'

Does not work either.

Additional remark: It was already quite difficult to get the role ID right - I expected it to be the "alias" but it needed to be the id which is nowhere displayed in the dataverse interface. It was not clear from the documentation what the ID should be that needed to be used for the API (https://guides.dataverse.org/en/latest/api/native-api.html#explicit-groups - see the Roles section)

skasberger commented 3 years ago

Thanks for the issue!

This looks like an issue more on the Dataverse side, than from pyDataverse. Have not tested the role functionalities myself, but as you used the basic request functions, they should work as expected.

@pdurbin @djbrooke Can you say more about the Java Exception raised and returned as Error message?

djbrooke commented 3 years ago

Hi @veustp - can you open an issue for this in main issue tracker so that we can take a look?

https://github.com/IQSS/dataverse/issues

pdurbin commented 3 years ago

See https://github.com/IQSS/dataverse/issues/7633 (thanks for opening it, @veustp).

pdurbin commented 4 months ago

As discussed during the 2024-02-14 meeting of the pyDataverse working group, we are closing old milestones in favor of a new project board at https://github.com/orgs/gdcc/projects/1 and removing issues (like this one) from those old milestones. Please feel free to join the working group! You can find us at https://py.gdcc.io and https://dataverse.zulipchat.com/#narrow/stream/377090-python