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

Consider current api user when updating members in conversation #58

Conversation

albertomardomingo
Copy link
Contributor

When a channel has been imported and the creator may not be the
same as the one making the api calls with the token, two errors
may occur:

  • The provider may try to kick the user from the conversation, which
    results in an error couldn't kick user from conversation: cant_kick_self

  • The provider tries to invite the user to the conversation, which
    results in an error couldn't invite users to conversation: cant_invite
    caused by the actual slack api error cant_invite_self

This addresses those problems by retrieving the user that is making the
api calls using the user_id field from the auth.test endpoint, and
removing the user from the list of users to operate with.

albertomardomingo and others added 2 commits June 30, 2021 15:35
When a channel has been imported and the creator may not be the
same as the one make the api calls with the token, two errors
may occur:

- The provider may try to kick the user from the conversation, which
results in an error `couldn't kick user from conversation: cant_kick_self`

- The provider tries to invite the user to the conversation, which
results in an error `couldn't invite users to conversation: cant_invite`
caused by the actual slack error `cant_invite_self`

This addresses that problems by retrieving the user that is making the
api calls using the `user_id` field from the auth.test endpoint, and
removing the user from the list of users to operate with.
@pablovarela pablovarela self-requested a review July 2, 2021 13:43
Copy link
Owner

@pablovarela pablovarela left a comment

Choose a reason for hiding this comment

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

Thank you very much for your contribution. I have some minor comments that don't need to be addressed, I will take care of them in future refactorings. There were some lint issues that I fixed, I hope that's fine with you.

In general I would not accept PR that do not have tests for the new functionality. But given that the change is straightforward and there is no easy way for you to run the tests at the moment I will accept it as it is and I will add test in the future myself.

The test need a Slack token that is set as a secret. Secrets are not passed to workflows that are triggered by a pull request from a fork so the PR checks will fail for your PR. I run the tests locally and they are still passing so we are good.

I have to think about how others can contribute, run the tests locally, and in the GitHub actions.

if err != nil {
return fmt.Errorf("Error authenticating with slack %w", err)
}
userIds = remove(userIds, apiUserInfo.UserID)
userIds = remove(userIds, channel.Creator)
Copy link
Owner

Choose a reason for hiding this comment

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

Some code repetition here, not a big deal at the moment but we should keep an eye on it

@@ -139,7 +146,7 @@ func updateChannelMembers(ctx context.Context, d *schema.ResourceData, client *s
}

for _, currentMember := range channelUsers {
if currentMember != channel.Creator && !contains(userIds, currentMember) {
if currentMember != channel.Creator && currentMember != apiUserInfo.UserID && !contains(userIds, currentMember) {
Copy link
Owner

Choose a reason for hiding this comment

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

We may want to extract a function with a meaningful name for this conditional to make the intent more clear

@pablovarela pablovarela merged commit aad0a97 into pablovarela:master Jul 2, 2021
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.

2 participants