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

Add methods supporting teamID to usergroups #37

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions usergroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,31 @@ func (api *Client) DisableUserGroupContext(ctx context.Context, userGroup string
return response.UserGroup, nil
}

// DisableUserGroup disables an existing user group, including an optional teamID for enterprise grid setups.
// For more information see the DisableUserGroupContext documentation.
func (api *Client) DisableUserGroupWithTeamID(userGroup, teamID string) (UserGroup, error) {
return api.DisableUserGroupContextWithTeamID(context.Background(), userGroup, teamID)
}

// DisableUserGroupContextWithTeamID disables an existing user group with a custom context.
// Slack API docs: https://api.slack.com/methods/usergroups.disable
func (api *Client) DisableUserGroupContextWithTeamID(ctx context.Context, userGroup, teamID string) (UserGroup, error) {
values := url.Values{
"token": {api.token},
"usergroup": {userGroup},
}

if teamID != "" {
values.Add("team_id", teamID)
}

response, err := api.userGroupRequest(ctx, "usergroups.disable", values)
if err != nil {
return UserGroup{}, err
}
return response.UserGroup, nil
}

// EnableUserGroup enables an existing user group.
// For more information see the EnableUserGroupContext documentation.
func (api *Client) EnableUserGroup(userGroup string) (UserGroup, error) {
Expand All @@ -129,6 +154,31 @@ func (api *Client) EnableUserGroupContext(ctx context.Context, userGroup string)
return response.UserGroup, nil
}

// EnableUserGroup enables an existing user group, including an optional teamID for enterprise grid setups.
// For more information see the EnableUserGroupContext documentation.
func (api *Client) EnableUserGroupWithTeamID(userGroup string, teamID string) (UserGroup, error) {
return api.EnableUserGroupContextWithTeamID(context.Background(), userGroup, teamID)
}

// EnableUserGroupContext enables an existing user group with a custom context.
// Slack API docs: https://api.slack.com/methods/usergroups.enable
func (api *Client) EnableUserGroupContextWithTeamID(ctx context.Context, userGroup string, teamID string) (UserGroup, error) {
values := url.Values{
"token": {api.token},
"usergroup": {userGroup},
}

if teamID != "" {
values.Add("team_id", teamID)
}

response, err := api.userGroupRequest(ctx, "usergroups.enable", values)
if err != nil {
return UserGroup{}, err
}
return response.UserGroup, nil
}

// GetUserGroupsOption options for the GetUserGroups method call.
type GetUserGroupsOption func(*GetUserGroupsParams)

Expand Down Expand Up @@ -248,6 +298,7 @@ func UpdateUserGroupsOptionChannels(channels []string) UpdateUserGroupsOption {

// UpdateUserGroupsParams contains arguments for UpdateUserGroup method call
type UpdateUserGroupsParams struct {
TeamID string
Name string
Handle string
Description *string
Expand All @@ -274,6 +325,10 @@ func (api *Client) UpdateUserGroupContext(ctx context.Context, userGroupID strin
"usergroup": {userGroupID},
}

if params.TeamID != "" {
values.Add("team_id", params.TeamID)
}

if params.Name != "" {
values["name"] = []string{params.Name}
}
Expand Down Expand Up @@ -318,6 +373,32 @@ func (api *Client) GetUserGroupMembersContext(ctx context.Context, userGroup str
return response.Users, nil
}

// GetUserGroupMembers will retrieve the current list of users in a group,
// including an optional teamID for enterprise grid setups.
// For more information see the GetUserGroupMembersContext documentation.
func (api *Client) GetUserGroupMembersWithTeamID(userGroup, teamID string) ([]string, error) {
return api.GetUserGroupMembersContextWithTeamID(context.Background(), userGroup, teamID)
}

// GetUserGroupMembersContextWithTeamID will retrieve the current list of users in a group with a custom context.
// Slack API docs: https://api.slack.com/methods/usergroups.users.list
func (api *Client) GetUserGroupMembersContextWithTeamID(ctx context.Context, userGroup, teamID string) ([]string, error) {
values := url.Values{
"token": {api.token},
"usergroup": {userGroup},
}

if teamID != "" {
values.Add("team_id", teamID)
}

response, err := api.userGroupRequest(ctx, "usergroups.users.list", values)
if err != nil {
return []string{}, err
}
return response.Users, nil
}

// UpdateUserGroupMembers will update the members of an existing user group.
// For more information see the UpdateUserGroupMembersContext documentation.
func (api *Client) UpdateUserGroupMembers(userGroup string, members string) (UserGroup, error) {
Expand All @@ -339,3 +420,30 @@ func (api *Client) UpdateUserGroupMembersContext(ctx context.Context, userGroup
}
return response.UserGroup, nil
}

// UpdateUserGroupMembers will update the members of an existing user group,
// including an optional teamID for enterprise grid setups.
// For more information see the UpdateUserGroupMembersContext documentation.
func (api *Client) UpdateUserGroupMembersWithTeamID(userGroup string, members string, teamID string) (UserGroup, error) {
return api.UpdateUserGroupMembersContextWithTeamID(context.Background(), userGroup, members, teamID)
}

// UpdateUserGroupMembersContextWithTeamID will update the members of an existing user group with a custom context.
// Slack API docs: https://api.slack.com/methods/usergroups.update
func (api *Client) UpdateUserGroupMembersContextWithTeamID(ctx context.Context, userGroup string, members string, teamID string) (UserGroup, error) {
values := url.Values{
"token": {api.token},
"usergroup": {userGroup},
"users": {members},
}

if teamID != "" {
values.Add("team_id", teamID)
}

response, err := api.userGroupRequest(ctx, "usergroups.users.update", values)
if err != nil {
return UserGroup{}, err
}
return response.UserGroup, nil
}
Loading