Skip to content

Commit

Permalink
add enable_section option for UserGroup API
Browse files Browse the repository at this point in the history
Signed-off-by: sivchari <[email protected]>
  • Loading branch information
sivchari committed Jan 6, 2025
1 parent e764011 commit 8298f6a
Showing 1 changed file with 45 additions and 7 deletions.
52 changes: 45 additions & 7 deletions usergroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package slack
import (
"context"
"net/url"
"strconv"
"strings"
)

Expand Down Expand Up @@ -50,20 +51,45 @@ func (api *Client) userGroupRequest(ctx context.Context, path string, values url
return response, response.Err()
}

// CreateUserGroupParams contains arguments for CreateUserGroup method call
type CreateUserGroupParams struct {
EnableSection bool
}

// CreateUserGroupOption options for the CreateUserGroup method call.
type CreateUserGroupOption func(*CreateUserGroupParams)

// CreateUserGroupOptionEnableSection enable the section for the user group (default: false)
func CreateUserGroupOptionEnableSection(enableSection bool) CreateUserGroupOption {
return func(params *CreateUserGroupParams) {
params.EnableSection = enableSection
}
}

// CreateUserGroup creates a new user group.
// For more information see the CreateUserGroupContext documentation.
func (api *Client) CreateUserGroup(userGroup UserGroup) (UserGroup, error) {
return api.CreateUserGroupContext(context.Background(), userGroup)
func (api *Client) CreateUserGroup(userGroup UserGroup, options ...CreateUserGroupOption) (UserGroup, error) {
return api.CreateUserGroupContext(context.Background(), userGroup, options...)
}

// CreateUserGroupContext creates a new user group with a custom context.
// Slack API docs: https://api.slack.com/methods/usergroups.create
func (api *Client) CreateUserGroupContext(ctx context.Context, userGroup UserGroup) (UserGroup, error) {
func (api *Client) CreateUserGroupContext(ctx context.Context, userGroup UserGroup, options ...CreateUserGroupOption) (UserGroup, error) {
params := CreateUserGroupParams{}

for _, opt := range options {
opt(&params)
}

values := url.Values{
"token": {api.token},
"name": {userGroup.Name},
}

if params.EnableSection {
values["enable_section"] = []string{strconv.FormatBool(params.EnableSection)}
}

if userGroup.TeamID != "" {
values["team_id"] = []string{userGroup.TeamID}
}
Expand Down Expand Up @@ -236,12 +262,20 @@ func UpdateUserGroupsOptionChannels(channels []string) UpdateUserGroupsOption {
}
}

// UpdateUserGroupsOptionEnableSection enable the section for the user group (default: false)
func UpdateUserGroupsOptionEnableSection(enableSection bool) UpdateUserGroupsOption {
return func(params *UpdateUserGroupsParams) {
params.EnableSection = enableSection
}
}

// UpdateUserGroupsParams contains arguments for UpdateUserGroup method call
type UpdateUserGroupsParams struct {
Name string
Handle string
Description *string
Channels *[]string
Name string
Handle string
Description *string
Channels *[]string
EnableSection bool
}

// UpdateUserGroup will update an existing user group.
Expand Down Expand Up @@ -280,6 +314,10 @@ func (api *Client) UpdateUserGroupContext(ctx context.Context, userGroupID strin
values["channels"] = []string{strings.Join(*params.Channels, ",")}
}

if params.EnableSection {
values["enable_section"] = []string{strconv.FormatBool(params.EnableSection)}
}

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

0 comments on commit 8298f6a

Please sign in to comment.