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

[MM-19066] Added user list command #34

Merged
merged 26 commits into from Feb 6, 2020
Merged

[MM-19066] Added user list command #34

merged 26 commits into from Feb 6, 2020

Conversation

njkevlani
Copy link
Contributor

@hanzei hanzei added 2: Dev Review Requires review by a core committer 3: QA Review Requires review by a QA tester labels Nov 1, 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.

Thanks @njkevlani!! It looks very good, a few changes noted.

Would you be open to add some unit tests for these PR? You can take inspiration on the search channel command test

commands/user.go Show resolved Hide resolved
commands/user.go Outdated Show resolved Hide resolved
Co-Authored-By: Miguel de la Cruz <mgdelacroix@gmail.com>
@njkevlani
Copy link
Contributor Author

Would you be open to add some unit tests for these PR? You can take inspiration on the search channel command test

Sure, will do that.

@njkevlani
Copy link
Contributor Author

@mgdelacroix

Tests added. Let me know if this seems fine :)

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.

Thanks for the addition of the tests @njkevlani!!

commands/user_test.go Outdated Show resolved Hide resolved
commands/user_test.go Outdated Show resolved Hide resolved
njkevlani and others added 2 commits November 18, 2019 00:56
Co-Authored-By: Miguel de la Cruz <mgdelacroix@gmail.com>
* Replace printer.Flush() with printer.Clean()
* Added printer.Flush() in first test case as well
* Added one more mock call when --all flag is passed
commands/user_test.go Outdated Show resolved Hide resolved
commands/user_test.go Outdated Show resolved Hide resolved
commands/user_test.go Show resolved Hide resolved
@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

@hanzei
Copy link
Contributor

hanzei commented Nov 29, 2019

@njkevlani Would you please merge master into the branch, when you have the time?

@njkevlani
Copy link
Contributor Author

@hanzei master branch is merged into this branch.

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.

Thanks for the changes @njkevlani, LGTM 👍

@njkevlani
Copy link
Contributor Author

ping @mkraft

commands/user.go Outdated
showAll, _ := command.Flags().GetBool("all")

tpl := `{{.Id}}: {{.Username}} ({{.Email}})`
for users, _ := c.GetUsers(page, perPage, ""); users != nil && len(users) > 0; users, _ = c.GetUsers(page, perPage, "") {
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason we're using the blank identifier for these GetUsers errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no particular reason behind that. I guess we can handle that response like following:

if response.Error != nil {
	printer.PrintError("Unable list all users.\n " + response.Error.Error())
}

Let me know if this seems fine or it can be improved :)

Choose a reason for hiding this comment

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

@njkevlani would you be open to help with @mkraft's question above? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @jasonblais,

Actually I have suggested what should be changed in my last comment, but haven't got any confirmation on that. Can you please check that out?

Copy link
Member

Choose a reason for hiding this comment

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

I also have the same question. We should check the error and bubble that above.

And this logic still uses the page number if showAll is set. What we should probably do is:

if showAll {
page = 0
}
And then loop through c.GetUsers until it runs out of users.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will commit & push soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I'll check for error and bubble that up.

if response.Error != nil {
	return errors.Wrap(response.Error, "Failed to fetch users")
}

@agnivade
Copy link
Member

We are nearly there. Just one outstanding comment to clarify. And please fix the merge conflicts. Thanks !

@njkevlani
Copy link
Contributor Author

We are nearly there. Just one outstanding comment to clarify.

Does this reply answer the question in linked comment?

@agnivade
Copy link
Member

That doesn't link to a comment for me. :( Feel free to just paste the comment.

Copy link
Member

@agnivade agnivade left a comment

Choose a reason for hiding this comment

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

Sorry, perhaps there is some miscommunication amongst us. I meant why do we need to call the GetUsers method twice. Does something like this work ?

for {
	users, res := c.GetUsers(page, perPage, "")
	if res.Error != nil {
		return errors.Wrap(...)
	}
	if len(users) == 0 {
		break
	}
	for _, user := range users {
		printer.PrintT(tpl, user)
	}

	if !showAll {
		break
	}
	page++	
}

check for error in server response outside of loop
@njkevlani
Copy link
Contributor Author

Sorry, perhaps there is some miscommunication amongst us. I meant why do we need to call the GetUsers method twice. Does something like this work ?

for {
	users, res := c.GetUsers(page, perPage, "")
	if res.Error != nil {
		return errors.Wrap(...)
	}
	if len(users) == 0 {
		break
	}
	for _, user := range users {
		printer.PrintT(tpl, user)
	}

	if !showAll {
		break
	}
	page++	
}

Yes, this would work fine. I guess the difference in this approach any my previous code is that,

  • In this approach: for { ... } loop is used. Initialization / assignment occurs inside loop body
  • In my previous approach: for init; condition; post { ... } initialization / assignment were part of loop,

Anyway, I have made changes in code. Let me know if all look good.

Copy link
Member

@agnivade agnivade left a comment

Choose a reason for hiding this comment

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

Thanks for your patience on this @njkevlani !

@njkevlani
Copy link
Contributor Author

Thanks for feedback on this, got to learn some things :) @agnivade

…19066

� Conflicts:
�	client/client.go
�	commands/user_test.go
�	mocks/client_mock.go
@njkevlani
Copy link
Contributor Author

@mgdelacroix any updates?

@mgdelacroix
Copy link
Member

mgdelacroix commented Jan 27, 2020

@njkevlani thanks a lot for all the changes you've implemented! Can you please run make docs and update the PR to fix the CI?

@njkevlani
Copy link
Contributor Author

@njkevlani thanks a lot for all the changes you've implemented! Can you please run make docs and update the PR to fix the CI?

Done :)

Copy link
Contributor

@mkraft mkraft left a comment

Choose a reason for hiding this comment

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

LGTM

@mgdelacroix mgdelacroix added 4: Reviews Complete All reviewers have approved the pull request AutoMerge used by Mattermod to merge PR automatically and removed 2: Dev Review Requires review by a core committer labels Feb 6, 2020
@mattermod
Copy link
Contributor

Will try to auto merge this PR once all tests and checks are passing. This might take up to an hour.

1 similar comment
@mattermod
Copy link
Contributor

Will try to auto merge this PR once all tests and checks are passing. This might take up to an hour.

@mattermod
Copy link
Contributor

Trying to auto merge this PR.

@mattermod mattermod merged commit daf8cb8 into mattermost:master Feb 6, 2020
@mattermod
Copy link
Contributor

Pull Request successfully merged
SHA: daf8cb8

@mattermod mattermod removed the AutoMerge used by Mattermod to merge PR automatically label Feb 6, 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.

Add "user list" subcommand to mmctl
8 participants