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

DD-1605 Implement several dd-dataverse-cli dataset commands #4

Conversation

aliassheikh
Copy link
Contributor

@aliassheikh aliassheikh commented Aug 5, 2024

Fixes DD-1605 Implement several dd-dataverse-cli dataset commands

Description of changes

Most recent changes:

  • Merged also changes of Paul for truncate-notifications
  • Merged also changes of Ali for validate-files
  • Implemented deleteRoleAssignment functions for collection and dataset in dans-dataverse-client-lib
  • The structure of sub-command role-assignment is now same for both collection and dataset.
  • The role-assignment has sub-commands: list, add and remove.

other changes:

  • All UnitTest + code changes of Joke has been merged in my code and did pull request again.
  • Small Changes in CollectionAssignRole class: assignment.cvs should have the columns: PID, ASSIGNEE, ROLE like in DatasetAssignRole.

[vagrant@archaeology ~]$ dataverse --help
Usage: dataverse [-hV] [COMMAND]
Command-line client for the Dataverse API
  -h, --help      Show this help message and exit.
  -V, --version   Print version information and exit.
Commands:
  collection              Manage Dataverse collections (i.e. 'dataverses')
  dataset                 Manage Dataverse datasets
  truncate-notifications  Remove user notifications but keep up to a specified
                            amount.
  generate-completion     Generate bash/zsh completion script for dataverse.

[vagrant@archaeology ~]$ dataverse  dataset --help
Usage: dataverse dataset [-hV] [-d=<delay>] targets [COMMAND]
Manage Dataverse datasets
      targets           The target(s) of the operation; this is either an ID a
                          file with a with a list of IDs, or - if the
                          subcommand supports it - a parameters file.
  -d, --delay=<delay>   Delay in milliseconds between requests to the server
                          (default: 1000).
  -h, --help            Show this help message and exit.
  -V, --version         Print version information and exit.
Commands:
  delete-draft        Delete the draft version of a dataset.
  get-files           Get a list of file metadata.
  get-latest-version  A JSON object that starts at the dataset level, most
                        fields are replicated at the dataset version level.
  get-version         Returns an object containing the dataset version metadata.
  publish             Dataset publication result.
  role-assignment     Manage role assignments.
  validate-files      Make sure that all files are correctly stored in object
                        storage.

[vagrant@archaeology ~]$ dataverse  dataset role-assignment --help
Usage: dataverse dataset role-assignment [-hV] [COMMAND]
Manage role assignments.
  -h, --help      Show this help message and exit.
  -V, --version   Print version information and exit.
Commands:
  list    List role assignments for the specified dataset.
  add     Assign a role to a user in a dataset.
  remove  remove role assignment from specified dataset(s)

[vagrant@archaeology ~]$ dataverse  dataset role-assignment add --help
Usage: dataverse dataset role-assignment add [-hV] (<assignment> |
       -f=<parameterFile>)
Assign a role to a user in a dataset.
      <assignment>   Alias and role assignee (example:
                       @dataverseAdmin=contributor)
  -f, --parameter-file=<parameterFile>
                     CSV file to read parameters from. The file should have a
                       header row with columns 'PID', 'ASSIGNEE' and 'ROLE'.
  -h, --help         Show this help message and exit.
  -V, --version      Print version information and exit.

[vagrant@archaeology ~]$ dataverse  dataset role-assignment remove --help
Usage: dataverse dataset role-assignment remove [-hV] (<assignment> |
       -f=<parameterFile>)
remove role assignment from specified dataset(s)
      <assignment>   Alias and role assignee (example:
                       @dataverseAdmin=contributor)
  -f, --parameter-file=<parameterFile>
                     CSV file to read parameters from. The file should have a
                       header row with columns 'PID', 'ASSIGNEE' and 'ROLE'.
  -h, --help         Show this help message and exit.
  -V, --version      Print version information and exit.

How to test

  • Local: start.sh dataset --help
  • Commands usage and examples:
    • dataverse dataset pid delete-draft [-hV]
      • dataverse dataset pid delete-draft
    • dataverse dataset get-files [-hV] version
      • dataverse dataset pid version 01
    • dataverse dataset pid get-latest-version [-hV]
      • dataverse dataset pid get-latest-version
    • dataverse dataset pid get-version [-hV] (<version> | --all)
    • dataverse dataset pid get-version 01
    • dataverse dataset pid get-version --all
    • dataverse dataset pid publish [-hV] [[-a] [--major | --minor]]
      • dataverse dataset pid publish --major
      • dataverse dataset pid publish --minor
      • dataverse dataset pid publish --minor -a=true
      • dataverse dataset pid publish --major -a=false
      • dataverse dataset pid publish -a=true
***************************************************************************************
 [vagrant@archaeology ~]$ dataverse dataset doi:10.5072/DAR/AO7VWF role-assignment list 

doi:10.5072/DAR/AO7VWF: OK. {"status":"OK","data":[{"id":7,"assignee":"@sword2-secret-user","roleId":11,"_roleAlias":"contributorplus","definitionPointId":8},{"id":8,"assignee":"@user001","roleId":13,"_roleAlias":"swordupdater","definitionPointId":8},{"id":1,"assignee":"@dataverseAdmin","roleId":1,"_roleAlias":"admin","definitionPointId":1},{"id":2,"assignee":":authenticated-users","roleId":5,"_roleAlias":"dsContributor","definitionPointId":1},{"id":3,"assignee":"@user001","roleId":12,"_roleAlias":"swordpublisher","definitionPointId":1},{"id":4,"assignee":"@user002","roleId":9,"_roleAlias":"datamanager","definitionPointId":1},{"id":5,"assignee":"@datamanager001","roleId":9,"_roleAlias":"datamanager","definitionPointId":1}]}

Test an invalid account name:

 [vagrant@archaeology ~]$ dataverse dataset doi:10.5072/DAR/AO7VWF role-assignment add  @ussser002=dsContributor

doi:10.5072/DAR/AO7VWF: FAILED: Exception type = DataverseException, message = status: 400; message: {"status":"ERROR","message":"Assignee not found"}
[vagrant@archaeology ~]$ dataverse dataset doi:10.5072/DAR/AO7VWF role-assignment add @user002=dsContributor

doi:10.5072/DAR/AO7VWF: OK. {"status":"OK","data":{"id":9,"assignee":"@user002","roleId":5,"_roleAlias":"dsContributor","definitionPointId":8}}
[vagrant@archaeology ~]$ dataverse dataset doi:10.5072/DAR/AO7VWF list-role-assignments

doi:10.5072/DAR/AO7VWF: OK. {"status":"OK","data":[{"id":7,"assignee":"@sword2-secret-user","roleId":11,"_roleAlias":"contributorplus","definitionPointId":8},{"id":8,"assignee":"@user001","roleId":13,"_roleAlias":"swordupdater","definitionPointId":8},{"id":9,"assignee":"@user002","roleId":5,"_roleAlias":"dsContributor","definitionPointId":8},{"id":1,"assignee":"@dataverseAdmin","roleId":1,"_roleAlias":"admin","definitionPointId":1},{"id":2,"assignee":":authenticated-users","roleId":5,"_roleAlias":"dsContributor","definitionPointId":1},{"id":3,"assignee":"@user001","roleId":12,"_roleAlias":"swordpublisher","definitionPointId":1},{"id":4,"assignee":"@user002","roleId":9,"_roleAlias":"datamanager","definitionPointId":1},{"id":5,"assignee":"@datamanager001","roleId":9,"_roleAlias":"datamanager","definitionPointId":1}]}
          { 
             "id": 9,
             "assignee": "@user002",
             "roleId": 5,
             "_roleAlias": "dsContributor",
            "definitionPointId": 8
          }, 

[vagrant@archaeology ~]$ dataverse dataset doi:10.5072/DAR/AO7VWF role-assignment remove @user002=dsContributor

doi:10.5072/DAR/AO7VWF: OK. {"status":"OK","data":[{"id":7,"assignee":"@sword2-secret-user","roleId":11,"_roleAlias":"contributorplus","definitionPointId":8},{"id":8,"assignee":"@user001","roleId":13,"_roleAlias":"swordupdater","definitionPointId":8},{"id":1,"assignee":"@dataverseAdmin","roleId":1,"_roleAlias":"admin","definitionPointId":1},{"id":2,"assignee":":authenticated-users","roleId":5,"_roleAlias":"dsContributor","definitionPointId":1},{"id":3,"assignee":"@user001","roleId":12,"_roleAlias":"swordpublisher","definitionPointId":1},{"id":4,"assignee":"@user002","roleId":9,"_roleAlias":"datamanager","definitionPointId":1},{"id":5,"assignee":"@datamanager001","roleId":9,"_roleAlias":"datamanager","definitionPointId":1}]}

~/.../dd-dataverse-cli> start.sh  collection 01 role-assignment list
01: OK. {"status":"OK","data":[{"id":1,"assignee":"@dataverseAdmin","roleId":1,"_roleAlias":"admin","definitionPointId":1},{"id":2,"assignee":":authenticated-users","roleId":5,"_roleAlias":"dsContributor","definitionPointId":1},{"id":3,"assignee":"@user001","roleId":12,"_roleAlias":"swordpublisher","definitionPointId":1},{"id":4,"assignee":"@user002","roleId":9,"_roleAlias":"datamanager","definitionPointId":1},{"id":5,"assignee":"@datamanager001","roleId":9,"_roleAlias":"datamanager","definitionPointId":1}]}

~/.../dd-dataverse-cli> start.sh  collection 01 role-assignment add @user002=contributorplus
01: OK. {"status":"OK","data":{"assignee":"@user002","roleId":11,"_roleAlias":"contributorplus","definitionPointId":1}}

~/.../dd-dataverse-cli> start.sh  collection 01 role-assignment list
01: OK. {"status":"OK","data":[{"id":1,"assignee":"@dataverseAdmin","roleId":1,"_roleAlias":"admin","definitionPointId":1},{"id":2,"assignee":":authenticated-users","roleId":5,"_roleAlias":"dsContributor","definitionPointId":1},{"id":3,"assignee":"@user001","roleId":12,"_roleAlias":"swordpublisher","definitionPointId":1},{"id":4,"assignee":"@user002","roleId":9,"_roleAlias":"datamanager","definitionPointId":1},{"id":5,"assignee":"@datamanager001","roleId":9,"_roleAlias":"datamanager","definitionPointId":1},{"id":11,"assignee":"@user002","roleId":11,"_roleAlias":"contributorplus","definitionPointId":1}]}

~/.../dd-dataverse-cli> start.sh  collection 01 role-assignment remove @user002=contributorplus
01: OK. {"status":"OK","data":{"message":"Role Contributor with ManageFilePermissions revoked for assignee @user002 in DANS Data Station Archaeology (dev)"}}

~/.../dd-dataverse-cli> start.sh  collection 01 role-assignment list

01: OK. {"status":"OK","data":[{"id":1,"assignee":"@dataverseAdmin","roleId":1,"_roleAlias":"admin","definitionPointId":1},{"id":2,"assignee":":authenticated-users","roleId":5,"_roleAlias":"dsContributor","definitionPointId":1},{"id":3,"assignee":"@user001","roleId":12,"_roleAlias":"swordpublisher","definitionPointId":1},{"id":4,"assignee":"@user002","roleId":9,"_roleAlias":"datamanager","definitionPointId":1},{"id":5,"assignee":"@datamanager001","roleId":9,"_roleAlias":"datamanager","definitionPointId":1}]}

Related PRs

(Add links)
*

Notify

@DANS-KNAW/core-systems

@aliassheikh aliassheikh marked this pull request as ready for review August 14, 2024 08:16
@aliassheikh aliassheikh requested a review from a team as a code owner August 14, 2024 08:16
Copy link
Contributor

@janvanmansum janvanmansum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment.


static class AssignmentCommand {
static class AssignmentAction {
@Option(names = "add", description = "add role assignment to specified dataset(s)'")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hack is unnecessary. The picocli library supports subcommands. add, remove and list are not options but subcommands and should be implemented that way.

Copy link
Contributor Author

@aliassheikh aliassheikh Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Role Assignment commands are separated in sub-commands now.
See also 'Description of changes' and 'How to test'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@janvanmansum If you are satisfied with the changes, you could close this conversation and accept the PR.

Copy link

codecov bot commented Sep 3, 2024

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

Copy link
Contributor

@PaulBoon PaulBoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like remove-role is not implemented, does that need to be fixed in this PR?
Personally I like tools that allow removal of X when they have an add X, also makes testing easier ...
Did you test all those command on the commandline, to see if the CLI handling is correct and params are passed to the API as expected.
Or maybe it is usefull to unit test this by mocking the API


remove Role Assignment is also implemented in as sub-command of role-assignment.
deleteRoleAssignment is also implemented for collection and dataset in dans-dataverse-client-lib.

@aliassheikh
Copy link
Contributor Author

Looks like remove-role is not implemented, does that need to be fixed in this PR? Personally I like tools that allow removal of X when they have an add X, also makes testing easier ... Did you test all those command on the commandline, to see if the CLI handling is correct and params are passed to the API as expected. Or maybe it is usefull to unit test this by mocking the API

  • About remove-role, see my answer to your another comment about 'TODOs', here above.
  • Add X is implemented
  • I have tested all of these command on the command-line.
  • I have also added in the start of the pull request 'How to test' for all of these command. Have you tried one of them? Did you see failed ones?

@aliassheikh aliassheikh marked this pull request as draft September 6, 2024 07:09
jo-pol and others added 6 commits September 10, 2024 09:51
generic AbstractAssignmentRole
…et-commnads' into DD-1605-implement-several-dataset-commnads
…subcommand remove for RoleAssignmnet command (collection and dataset)
@aliassheikh aliassheikh marked this pull request as ready for review September 18, 2024 08:43
@janvanmansum
Copy link
Contributor

@aliassheikh , @PaulBoon , @jo-pol : I am merging this now, but will be merging a large refactoring as well, later today. There are some good ideas in this PR, but on the other hand some unwarranted complexity.

@janvanmansum janvanmansum merged commit 04037d9 into DANS-KNAW:master Sep 25, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants