Skip to content

Users command: Functionality to add/remove roles + Users user guide #283

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

Merged
merged 8 commits into from
May 27, 2021

Conversation

maddie-vargo
Copy link
Contributor

This PR addresses a portion of Issue #259 by adding functionality to add and remove user roles to an individual user. This command takes a username and a user role name as two positional arguments.

Testing Procedure:

cod42 users add-role <username> <role name>
code42 users remove-role <username> <role name>

PR Checklist
Did you remember to do the below?

  • Add unit tests to verify this change
  • Add an entry to CHANGELOG.md describing this change
  • Add docstrings for any new public parameters / methods / classes

@github-actions
Copy link

github-actions bot commented May 14, 2021

CLA Assistant Lite bot All contributors have signed the CLA ✍️

@@ -60,6 +61,50 @@ def list_users(state, org_uid, role_name, active, inactive, format):
formatter.echo_formatted_dataframe(df)


@users.command()
@click.argument("username")
Copy link
Contributor

Choose a reason for hiding this comment

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

When commands have multiple arguments, we elect to use required options instead.
This is because then the order does not matter, like I don't have to use --help to see if the username goes first or the role name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, I added them as functions with flexible help text, assuming that they would be re-used in further expansions of the users command.


def _add_user_role(sdk, role_name, username):
user_id = _get_user_id(sdk, username)
try:
Copy link
Contributor

@antazoey antazoey May 17, 2021

Choose a reason for hiding this comment

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

I don't understand what this try / except is doing.
It looks like it catches an error just to raise it again.
Is there any technical difference of just letting the error raise naturally? If so, we should add a comment explaining what it is because it is not obvious.

Copy link
Contributor Author

@maddie-vargo maddie-vargo May 17, 2021

Choose a reason for hiding this comment

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

The try/except block isn't doing anything, actually - I will remove it.

We don't actually even need the roleID from _get_role_id to proceed. However, I like the error handling Cecilia had built for an invalid role name. It handles cases where an invalid role name was entered and provides the following error message:

Error: Role with name Fake_Role not found.

Otherwise, the error is:

Error: Problem making request to server.

Py42 doesn't really have a method for determining if a role name is valid.

Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth adding a comment about that, or even extracting the error handling into a separate method
(still approved but thought I'd mention that)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a comment. I had trouble extracting the error handling, since 95% of what that method doing is error handling. Extracting the error handling didn't add clarity or reduce redundancy.

Copy link
Contributor

@antazoey antazoey left a comment

Choose a reason for hiding this comment

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

Some missing periods in help text but otherwise looks good.

@antazoey antazoey merged commit a7a521f into code42:master May 27, 2021
@github-actions github-actions bot locked and limited conversation to collaborators May 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants