slackapi / deno-slack-sdk

SDK for building Run on Slack apps using Deno
https://api.slack.com/automation
150 stars 27 forks source link

[BUG] RemoveUserFromUsergroup reports `usergroup_id` failed: value is not a string incorrectly #231

Open angus-faethm opened 8 months ago

angus-faethm commented 8 months ago

The deno-slack versions

"deno-slack-sdk/": "https://deno.land/x/deno_slack_sdk@2.2.0/",
"deno-slack-api/": "https://deno.land/x/deno_slack_api@2.1.1/"

Deno runtime version

deno 1.36.4 (release, aarch64-apple-darwin)
v8 11.6.189.12
typescript 5.1.6

OS info

ProductName:    macOS
ProductVersion: 12.6.7
BuildVersion:   21G651
Darwin Kernel Version 21.6.0: Thu Jun  8 23:56:13 PDT 2023; root:xnu-8020.240.18.701.6~1/RELEASE_ARM64_T6000

Describe the bug

RemoveUserFromUsergroup Returns an error for usergroup_id unexpectedly. It happens when

  1. the user group is empty. or
  2. none of user_id in RemoveUserFromUsergroup exist in target user group

Steps to reproduce

Scenario 1

  1. Given that I have an EMPTY user group, S060xxxxxx
  2. Remove users from the user group
    XWorkflow.addStep(
    Schema.slack.functions.RemoveUserFromUsergroup,
    {
    usergroup_id: "S060xxxxxx",
    user_ids: ["U032xxxxxx", "UB6xxxxxxx"],
    },
    );

Scenario 2

  1. Given that I have an S060xxxxxx containing ONE user U00000xxxxxx only
  2. Remove users who are not in the group
    XWorkflow.addStep(
    Schema.slack.functions.RemoveUserFromUsergroup,
    {
    usergroup_id: "S060xxxxxx",
    user_ids: ["U032xxxxxx", "UB6xxxxxxx"],
    },
    );

Expected result

Two options a. return step completed even if no user removed b. return a better error message e.g. "Failed to remove user from the user group"

Actual result

Return error parameter_validation_failed - Validation for parameter ``usergroup_id`` failed: value is not a string

2023-10-19 08:07:19 [error] [Fn010H] (Trace=Tr0625E8BLD7) Function 'Remove someone from a user group' (%!!(MISSING)s(<nil>) function) failed
        parameter_validation_failed
2023-10-19 08:07:19 [error] [Fn010H] (Trace=Tr0625E8BLD7) Function 'Remove someone from a user group' (Slack function) failed
        parameter_validation_failed - Validation for parameter `usergroup_id` failed: value is not a string
2023-10-19 08:07:19 [error] [Wf05T6JFAJTX] (Trace=Tr0625E8BLD7) Workflow step 'Remove someone from a user group' failed

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

filmaj commented 8 months ago

Thanks for the report! I can confirm this issue. Will raise it in internally.

filmaj commented 8 months ago

One thing to note: the Slack client won't let you empty a usergroup out. I have a feeling that the fact you got to a situation where a usergroup is empty is invalid to begin with, and the error you experienced for an empty group is secondary effect from that. How did you create an empty usergroup?

angus-faethm commented 8 months ago

@filmaj I created a placeholder user group via slack app UI. My use case is.

  1. create a oncall-support user group
  2. get the one or many oncall engineers from the external API
  3. clear the oncall-support user group
  4. assign the oncall engineers to the user group.
filmaj commented 8 months ago

I cannot create an empty usergroup via the Slack UI. When I try, I get a UI like this that prevents me from submitting any changes to the usergroup:

Screenshot 2023-10-23 at 8 56 14 AM

Simiarly, the usergroups.users.update API that allows for one to manage the membership in a usergroup states, under its Usage:

You can’t use this method to remove all members from a User Group. Use the usergroups.disable method instead. If you need to reactivate the usergroup later, you can use the usergroups.enable method.

I agree with you that the error message should be better, but I did want to clarify the root of the issue when it comes to creating empty usergroups (that should not ever be possible, and if it is, that in itself is a bug).

angus-faethm commented 8 months ago

@filmaj Previously, I can create a user-group and remove all group members via UI when reporting this issue. I am not able to do it again today.