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

[GH-13278] Port the "user activate" subcommand from Mattermost CLI to mmctl #67

Merged
merged 6 commits into from Jan 7, 2020

Conversation

larkox
Copy link
Contributor

@larkox larkox commented Dec 3, 2019

Summary:
Port the "user activate" subcommand from Mattermost CLI to mmctl

Link:
Fixes mattermost/mattermost#13278

@hanzei hanzei added 2: Dev Review Requires review by a core committer 3: QA Review Requires review by a QA tester labels Dec 4, 2019
@lindy65 lindy65 self-requested a review December 11, 2019 07:40
Copy link
Contributor

@lindy65 lindy65 left a comment

Choose a reason for hiding this comment

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

Thanks @larkox - this will be QA'd post-merge 👍

@lindy65 lindy65 added QA Review Done and removed 3: QA Review Requires review by a QA tester labels Dec 11, 2019
Copy link
Member

@mgdelacroix mgdelacroix left a comment

Choose a reason for hiding this comment

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

This is great! Thanks a lot for these changes @larkox!! 🎊

commands/user.go Outdated
Comment on lines 118 to 120
if len(args) < 1 {
return errors.New("Expected at least one argument. See help text for details.")
}
Copy link
Member

Choose a reason for hiding this comment

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

This check can be replaced using Args: cobra.MinimumNArgs(1), in the command struct

commands/user.go Outdated
Comment on lines 139 to 141
if user == nil {
return fmt.Errorf("Can't find user '%v'", userArg)
}
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer this check to be made right after getting the user, and for the changeUserActiveStatus function to trust the arguments so it's simpler and the errors are handled right where they occur. 3/5

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this is the only workflow that is expected (changeUsersActiveStatus->changeUserActiveStatus) this work. If at any moment we decide to expose or use in other place the "changeUserActiveStatus" function, it may result in a panic. That is why I generally prefer to check things just before using them.

Nevertheless, if we want to enforce that changeUserActiveStatus to trust the arguments and expect a panic if someone or something is using it wrong, we can make the change.

Copy link
Member

Choose a reason for hiding this comment

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

For me is the other way around, if we retrieve something but don't check that we got a value, that could cause a panic. Now we are doing changeUsersActiveStatus -> changeUserActiveStatus, but if we decide to do something else with those users before (or even after) going through the function that checks the nils, we would be operating with usafe values.

Checking something as part of getting it is safe, as it doesn't matter where you use it, you know that it has already been checked, hence the rest of the functions can trust that value (or check it for double safety if the functions are exposed as part of an API).

s.Require().Equal(fmt.Errorf("Unable to change activation status of user: %v", emailArg).Error(), printer.GetErrorLines()[0])
})

s.Run("Activate several users with unexistent ones and failure ones", func() {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
s.Run("Activate several users with unexistent ones and failure ones", func() {
s.Run("Activate several users with unexistent ones and failed ones", func() {

commands/user.go Outdated
return fmt.Errorf("Unable to change activation status of user: %v", userArg)
}

return nil
}

func userDeactivateCmdF(c client.Client, cmd *cobra.Command, args []string) error {
if len(args) < 1 {
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't belong specifically to this ticket, but it would be great if you could apply the Args: cobra.MinimumNArgs(1) to this command as well

if _, response := c.DeleteUser(user.Id); response.Error != nil {
printer.PrintError("Unable to deactivate user " + userArgs[i] + ". Error: " + response.Error.Error())
}
func changeUserActiveStatus(c client.Client, user *model.User, userArg string, activate bool) error {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we are using c.DeleteUser anywhere else. If so, would you mind removing it from the Client and updating the mocks?

@mattermod
Copy link
Contributor

This issue has been automatically labelled "stale" because it hasn't had recent activity.
A core team member will check in on the status of the PR to help with questions.
Thank you for your contribution!

/cc @jasonblais @hanzei

Copy link
Member

@mgdelacroix mgdelacroix left a comment

Choose a reason for hiding this comment

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

Sorry for the late review! LGTM, thanks a lot for the changes @larkox!!! 🎊

@mgdelacroix mgdelacroix added 4: Reviews Complete All reviewers have approved the pull request and removed 2: Dev Review Requires review by a core committer QA Review Done labels Jan 7, 2020
@mgdelacroix mgdelacroix merged commit 01a790a into mattermost:master Jan 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4: Reviews Complete All reviewers have approved the pull request QA Review Done
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Port the "user activate" subcommand from Mattermost CLI to mmctl
5 participants