@@ -81,6 +81,14 @@ type NotificationConfigurationList struct {
81
81
Items []* NotificationConfiguration
82
82
}
83
83
84
+ // NotificationConfigurationSubscribableChoice is a choice type struct that represents the possible values
85
+ // within a polymorphic relation. If a value is available, exactly one field
86
+ // will be non-nil.
87
+ type NotificationConfigurationSubscribableChoice struct {
88
+ Team * Team
89
+ Workspace * Workspace
90
+ }
91
+
84
92
// NotificationConfiguration represents a Notification Configuration.
85
93
type NotificationConfiguration struct {
86
94
ID string `jsonapi:"primary,notification-configurations"`
@@ -98,8 +106,11 @@ type NotificationConfiguration struct {
98
106
EmailAddresses []string `jsonapi:"attr,email-addresses"`
99
107
100
108
// Relations
101
- Subscribable * Workspace `jsonapi:"relation,subscribable"`
102
- EmailUsers []* User `jsonapi:"relation,users"`
109
+ // DEPRECATED. The subscribable field is polymorphic. Use NotificationConfigurationSubscribableChoice instead.
110
+ Subscribable * Workspace `jsonapi:"relation,subscribable"`
111
+ SubscribableChoice * NotificationConfigurationSubscribableChoice `jsonapi:"polyrelation,subscribable"`
112
+
113
+ EmailUsers []* User `jsonapi:"relation,users"`
103
114
}
104
115
105
116
// DeliveryResponse represents a notification configuration delivery response.
@@ -116,6 +127,8 @@ type DeliveryResponse struct {
116
127
// notification configurations.
117
128
type NotificationConfigurationListOptions struct {
118
129
ListOptions
130
+
131
+ SubscribableChoice * NotificationConfigurationSubscribableChoice `jsonapi:"polyrelation,subscribable"`
119
132
}
120
133
121
134
// NotificationConfigurationCreateOptions represents the options for
@@ -151,6 +164,9 @@ type NotificationConfigurationCreateOptions struct {
151
164
152
165
// Optional: The list of users belonging to the organization that will receive notification emails.
153
166
EmailUsers []* User `jsonapi:"relation,users,omitempty"`
167
+
168
+ // Required: The workspace or team that the notification configuration is associated with.
169
+ SubscribableChoice * NotificationConfigurationSubscribableChoice `jsonapi:"polyrelation,subscribable"`
154
170
}
155
171
156
172
// NotificationConfigurationUpdateOptions represents the options for
@@ -186,12 +202,22 @@ type NotificationConfigurationUpdateOptions struct {
186
202
}
187
203
188
204
// List all the notification configurations associated with a workspace.
189
- func (s * notificationConfigurations ) List (ctx context.Context , workspaceID string , options * NotificationConfigurationListOptions ) (* NotificationConfigurationList , error ) {
190
- if ! validStringID (& workspaceID ) {
191
- return nil , ErrInvalidWorkspaceID
205
+ func (s * notificationConfigurations ) List (ctx context.Context , subscribableID string , options * NotificationConfigurationListOptions ) (* NotificationConfigurationList , error ) {
206
+ var u string
207
+ if options == nil || options .SubscribableChoice == nil || options .SubscribableChoice .Workspace != nil {
208
+ if ! validStringID (& subscribableID ) {
209
+ return nil , ErrInvalidWorkspaceID
210
+ }
211
+ u = fmt .Sprintf ("workspaces/%s/notification-configurations" , url .PathEscape (subscribableID ))
212
+ } else if options .SubscribableChoice .Team != nil {
213
+ if ! validStringID (& subscribableID ) {
214
+ return nil , ErrInvalidTeamID
215
+ }
216
+ u = fmt .Sprintf ("teams/%s/notification-configurations" , url .PathEscape (subscribableID ))
217
+ } else {
218
+ return nil , ErrInvalidNotificationConfigSubscribableChoice
192
219
}
193
220
194
- u := fmt .Sprintf ("workspaces/%s/notification-configurations" , url .PathEscape (workspaceID ))
195
221
req , err := s .client .NewRequest ("GET" , u , options )
196
222
if err != nil {
197
223
return nil , err
@@ -207,22 +233,39 @@ func (s *notificationConfigurations) List(ctx context.Context, workspaceID strin
207
233
}
208
234
209
235
// Create a notification configuration with the given options.
210
- func (s * notificationConfigurations ) Create (ctx context.Context , workspaceID string , options NotificationConfigurationCreateOptions ) (* NotificationConfiguration , error ) {
211
- if ! validStringID (& workspaceID ) {
212
- return nil , ErrInvalidWorkspaceID
213
- }
236
+ func (s * notificationConfigurations ) Create (ctx context.Context , subscribableID string , options NotificationConfigurationCreateOptions ) (* NotificationConfiguration , error ) {
214
237
if err := options .valid (); err != nil {
215
238
return nil , err
216
239
}
217
240
218
- u := fmt .Sprintf ("workspaces/%s/notification-configurations" , url .PathEscape (workspaceID ))
241
+ var u string
242
+ var subscribableChoice * NotificationConfigurationSubscribableChoice
243
+ if options .SubscribableChoice == nil || options .SubscribableChoice .Workspace != nil {
244
+ if ! validStringID (& subscribableID ) {
245
+ return nil , ErrInvalidWorkspaceID
246
+ }
247
+
248
+ u = fmt .Sprintf ("workspaces/%s/notification-configurations" , url .PathEscape (subscribableID ))
249
+ subscribableChoice = & NotificationConfigurationSubscribableChoice {Workspace : & Workspace {ID : subscribableID }}
250
+ } else if options .SubscribableChoice != nil && options .SubscribableChoice .Team != nil {
251
+ if ! validStringID (& subscribableID ) {
252
+ return nil , ErrInvalidTeamID
253
+ }
254
+
255
+ u = fmt .Sprintf ("teams/%s/notification-configurations" , url .PathEscape (subscribableID ))
256
+ subscribableChoice = & NotificationConfigurationSubscribableChoice {Team : & Team {ID : subscribableID }}
257
+ } else {
258
+ return nil , ErrInvalidNotificationConfigSubscribableChoice
259
+ }
260
+
219
261
req , err := s .client .NewRequest ("POST" , u , & options )
220
262
if err != nil {
221
263
return nil , err
222
264
}
223
265
224
- nc := & NotificationConfiguration {}
266
+ nc := & NotificationConfiguration {SubscribableChoice : subscribableChoice }
225
267
err = req .Do (ctx , nc )
268
+
226
269
if err != nil {
227
270
return nil , err
228
271
}
@@ -364,6 +407,7 @@ func validNotificationTriggerType(triggers []NotificationTriggerType) bool {
364
407
NotificationTriggerAssessmentFailed ,
365
408
NotificationTriggerWorkspaceAutoDestroyReminder ,
366
409
NotificationTriggerWorkspaceAutoDestroyRunResults ,
410
+ NotificationTriggerChangeRequestCreated ,
367
411
NotificationTriggerAssessmentCheckFailed :
368
412
continue
369
413
default :
0 commit comments