|
| 1 | +package slack |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "encoding/json" |
| 6 | + "fmt" |
| 7 | +) |
| 8 | + |
| 9 | +type ( |
| 10 | + WorkflowsTriggersPermissionsAddInput struct { |
| 11 | + TriggerId string `json:"trigger_id"` |
| 12 | + ChannelIds []string `json:"channel_ids,omitempty"` |
| 13 | + OrgIds []string `json:"org_ids,omitempty"` |
| 14 | + TeamIds []string `json:"team_ids,omitempty"` |
| 15 | + UserIds []string `json:"user_ids,omitempty"` |
| 16 | + } |
| 17 | + |
| 18 | + WorkflowsTriggersPermissionsAddOutput struct { |
| 19 | + PermissionType string `json:"permission_type"` |
| 20 | + ChannelIds []string `json:"channel_ids,omitempty"` |
| 21 | + OrgIds []string `json:"org_ids,omitempty"` |
| 22 | + TeamIds []string `json:"team_ids,omitempty"` |
| 23 | + UserIds []string `json:"user_ids,omitempty"` |
| 24 | + } |
| 25 | + |
| 26 | + WorkflowsTriggersPermissionsListInput struct { |
| 27 | + TriggerId string `json:"trigger_id"` |
| 28 | + } |
| 29 | + |
| 30 | + WorkflowsTriggersPermissionsListOutput struct { |
| 31 | + PermissionType string `json:"permission_type"` |
| 32 | + ChannelIds []string `json:"channel_ids,omitempty"` |
| 33 | + OrgIds []string `json:"org_ids,omitempty"` |
| 34 | + TeamIds []string `json:"team_ids,omitempty"` |
| 35 | + UserIds []string `json:"user_ids,omitempty"` |
| 36 | + } |
| 37 | + |
| 38 | + WorkflowsTriggersPermissionsRemoveInput struct { |
| 39 | + TriggerId string `json:"trigger_id"` |
| 40 | + ChannelIds []string `json:"channel_ids,omitempty"` |
| 41 | + OrgIds []string `json:"org_ids,omitempty"` |
| 42 | + TeamIds []string `json:"team_ids,omitempty"` |
| 43 | + UserIds []string `json:"user_ids,omitempty"` |
| 44 | + } |
| 45 | + |
| 46 | + WorkflowsTriggersPermissionsRemoveOutput struct { |
| 47 | + PermissionType string `json:"permission_type"` |
| 48 | + ChannelIds []string `json:"channel_ids,omitempty"` |
| 49 | + OrgIds []string `json:"org_ids,omitempty"` |
| 50 | + TeamIds []string `json:"team_ids,omitempty"` |
| 51 | + UserIds []string `json:"user_ids,omitempty"` |
| 52 | + } |
| 53 | + |
| 54 | + WorkflowsTriggersPermissionsSetInput struct { |
| 55 | + PermissionType string `json:"permission_type"` |
| 56 | + TriggerId string `json:"trigger_id"` |
| 57 | + ChannelIds []string `json:"channel_ids,omitempty"` |
| 58 | + OrgIds []string `json:"org_ids,omitempty"` |
| 59 | + TeamIds []string `json:"team_ids,omitempty"` |
| 60 | + UserIds []string `json:"user_ids,omitempty"` |
| 61 | + } |
| 62 | + |
| 63 | + WorkflowsTriggersPermissionsSetOutput struct { |
| 64 | + PermissionType string `json:"permission_type"` |
| 65 | + ChannelIds []string `json:"channel_ids,omitempty"` |
| 66 | + OrgIds []string `json:"org_ids,omitempty"` |
| 67 | + TeamIds []string `json:"team_ids,omitempty"` |
| 68 | + UserIds []string `json:"user_ids,omitempty"` |
| 69 | + } |
| 70 | +) |
| 71 | + |
| 72 | +// WorkflowsTriggersPermissionsAdd allows users to run a trigger that has its permission |
| 73 | +// type set to named_entities. |
| 74 | +// |
| 75 | +// Slack API Docs:https://api.slack.com/methods/workflows.triggers.permissions.add |
| 76 | +func (api *Client) WorkflowsTriggersPermissionsAdd(ctx context.Context, input *WorkflowsTriggersPermissionsAddInput) (*WorkflowsTriggersPermissionsAddOutput, error) { |
| 77 | + response := struct { |
| 78 | + SlackResponse |
| 79 | + *WorkflowsTriggersPermissionsAddOutput |
| 80 | + }{} |
| 81 | + |
| 82 | + jsonPayload, err := json.Marshal(input) |
| 83 | + if err != nil { |
| 84 | + return nil, fmt.Errorf("failed to marshal WorkflowsTriggersPermissionsAddInput: %w", err) |
| 85 | + } |
| 86 | + |
| 87 | + err = postJSON(ctx, api.httpclient, api.endpoint+"workflows.triggers.permissions.add", api.token, jsonPayload, &response, api) |
| 88 | + if err != nil { |
| 89 | + return nil, err |
| 90 | + } |
| 91 | + |
| 92 | + if err := response.Err(); err != nil { |
| 93 | + return nil, err |
| 94 | + } |
| 95 | + |
| 96 | + return response.WorkflowsTriggersPermissionsAddOutput, nil |
| 97 | +} |
| 98 | + |
| 99 | +// WorkflowsTriggersPermissionsList returns the permission type of a trigger and if |
| 100 | +// applicable, includes the entities that have been granted access. |
| 101 | +// |
| 102 | +// Slack API Docs:https://api.slack.com/methods/workflows.triggers.permissions.list |
| 103 | +func (api *Client) WorkflowsTriggersPermissionsList(ctx context.Context, input *WorkflowsTriggersPermissionsListInput) (*WorkflowsTriggersPermissionsListOutput, error) { |
| 104 | + response := struct { |
| 105 | + SlackResponse |
| 106 | + *WorkflowsTriggersPermissionsListOutput |
| 107 | + }{} |
| 108 | + |
| 109 | + jsonPayload, err := json.Marshal(input) |
| 110 | + if err != nil { |
| 111 | + return nil, fmt.Errorf("failed to marshal WorkflowsTriggersPermissionsListInput: %w", err) |
| 112 | + } |
| 113 | + |
| 114 | + err = postJSON(ctx, api.httpclient, api.endpoint+"workflows.triggers.permissions.list", api.token, jsonPayload, &response, api) |
| 115 | + if err != nil { |
| 116 | + return nil, err |
| 117 | + } |
| 118 | + |
| 119 | + if err := response.Err(); err != nil { |
| 120 | + return nil, err |
| 121 | + } |
| 122 | + |
| 123 | + return response.WorkflowsTriggersPermissionsListOutput, nil |
| 124 | +} |
| 125 | + |
| 126 | +// WorkflowsTriggersPermissionsRemove revoke an entity's access to a trigger that has its |
| 127 | +// permission type set to named_entities. |
| 128 | +// |
| 129 | +// Slack API Docs:https://api.slack.com/methods/workflows.triggers.permissions.remove |
| 130 | +func (api *Client) WorkflowsTriggersPermissionsRemove(ctx context.Context, input *WorkflowsTriggersPermissionsRemoveInput) (*WorkflowsTriggersPermissionsRemoveOutput, error) { |
| 131 | + response := struct { |
| 132 | + SlackResponse |
| 133 | + *WorkflowsTriggersPermissionsRemoveOutput |
| 134 | + }{} |
| 135 | + |
| 136 | + jsonPayload, err := json.Marshal(input) |
| 137 | + if err != nil { |
| 138 | + return nil, fmt.Errorf("failed to marshal WorkflowsTriggersPermissionsRemoveInput: %w", err) |
| 139 | + } |
| 140 | + |
| 141 | + err = postJSON(ctx, api.httpclient, api.endpoint+"workflows.triggers.permissions.remove", api.token, jsonPayload, &response, api) |
| 142 | + if err != nil { |
| 143 | + return nil, err |
| 144 | + } |
| 145 | + |
| 146 | + if err := response.Err(); err != nil { |
| 147 | + return nil, err |
| 148 | + } |
| 149 | + |
| 150 | + return response.WorkflowsTriggersPermissionsRemoveOutput, nil |
| 151 | +} |
| 152 | + |
| 153 | +// WorkflowsTriggersPermissionsSet sets the permission type for who can run a trigger. |
| 154 | +// |
| 155 | +// Slack API Docs:https://api.slack.com/methods/workflows.triggers.permissions.set |
| 156 | +func (api *Client) WorkflowsTriggersPermissionsSet(ctx context.Context, input *WorkflowsTriggersPermissionsSetInput) (*WorkflowsTriggersPermissionsSetOutput, error) { |
| 157 | + response := struct { |
| 158 | + SlackResponse |
| 159 | + *WorkflowsTriggersPermissionsSetOutput |
| 160 | + }{} |
| 161 | + |
| 162 | + jsonPayload, err := json.Marshal(input) |
| 163 | + if err != nil { |
| 164 | + return nil, fmt.Errorf("failed to marshal WorkflowsTriggersPermissionsSetInput: %w", err) |
| 165 | + } |
| 166 | + |
| 167 | + err = postJSON(ctx, api.httpclient, api.endpoint+"workflows.triggers.permissions.set", api.token, jsonPayload, &response, api) |
| 168 | + if err != nil { |
| 169 | + return nil, err |
| 170 | + } |
| 171 | + |
| 172 | + if err := response.Err(); err != nil { |
| 173 | + return nil, err |
| 174 | + } |
| 175 | + |
| 176 | + return response.WorkflowsTriggersPermissionsSetOutput, nil |
| 177 | +} |
0 commit comments