@@ -76,7 +76,7 @@ func (c *Consumer) consumeAlertsConfigs(ctx context.Context,
76
76
ctxLog := c .logger (ctx ).WithField ("followedUserID" , cfg .FollowedUserID )
77
77
ctx = log .NewContextWithLogger (ctx , ctxLog )
78
78
79
- notes , err := c .Evaluator .Evaluate (ctx , cfg .FollowedUserID )
79
+ notes , err := c .Evaluator .Evaluate (ctx , cfg .FollowedUserID , cfg . UploadID )
80
80
if err != nil {
81
81
format := "Unable to evalaute alerts configs triggered event for user %s"
82
82
return errors .Wrapf (err , format , cfg .UserID )
@@ -103,8 +103,11 @@ func (c *Consumer) consumeDeviceData(ctx context.Context,
103
103
if datum .UserID == nil {
104
104
return errors .New ("Unable to retrieve alerts configs: userID is nil" )
105
105
}
106
+ if datum .UploadID == nil {
107
+ return errors .New ("Unable to retrieve alerts configs: uploadID is nil" )
108
+ }
106
109
ctx = log .NewContextWithLogger (ctx , lgr .WithField ("followedUserID" , * datum .UserID ))
107
- notes , err := c .Evaluator .Evaluate (ctx , * datum .UserID )
110
+ notes , err := c .Evaluator .Evaluate (ctx , * datum .UserID , * datum . UploadID )
108
111
if err != nil {
109
112
format := "Unable to evalaute device data triggered event for user %s"
110
113
return errors .Wrapf (err , format , * datum .UserID )
@@ -162,7 +165,7 @@ func (c *Consumer) logger(ctx context.Context) log.Logger {
162
165
}
163
166
164
167
type AlertsEvaluator interface {
165
- Evaluate (ctx context.Context , followedUserID string ) ([]* alerts.Notification , error )
168
+ Evaluate (ctx context.Context , followedUserID , dataSetID string ) ([]* alerts.Notification , error )
166
169
}
167
170
168
171
func NewAlertsEvaluator (alerts AlertsClient , data store.DataRepository ,
@@ -198,10 +201,10 @@ func (e *evaluator) logger(ctx context.Context) log.Logger {
198
201
}
199
202
200
203
// Evaluate followers' alerts.Configs to generate alert notifications.
201
- func (e * evaluator ) Evaluate (ctx context.Context , followedUserID string ) (
204
+ func (e * evaluator ) Evaluate (ctx context.Context , followedUserID , dataSetID string ) (
202
205
[]* alerts.Notification , error ) {
203
206
204
- alertsConfigs , err := e .gatherAlertsConfigs (ctx , followedUserID )
207
+ alertsConfigs , err := e .gatherAlertsConfigs (ctx , followedUserID , dataSetID )
205
208
if err != nil {
206
209
return nil , err
207
210
}
@@ -231,14 +234,21 @@ func (e *evaluator) mapAlertsConfigsByUploadID(cfgs []*alerts.Config) map[string
231
234
return mapped
232
235
}
233
236
237
+ // gatherAlertsConfigs for the given followed user and data set.
238
+ //
239
+ // Those configs which don't match the data set or whose owners don't have permission are
240
+ // removed.
234
241
func (e * evaluator ) gatherAlertsConfigs (ctx context.Context ,
235
- followedUserID string ) ([]* alerts.Config , error ) {
242
+ followedUserID , dataSetID string ) ([]* alerts.Config , error ) {
236
243
237
244
alertsConfigs , err := e .Alerts .List (ctx , followedUserID )
238
245
if err != nil {
239
246
return nil , err
240
247
}
241
248
alertsConfigs = slices .DeleteFunc (alertsConfigs , e .authDenied (ctx ))
249
+ alertsConfigs = slices .DeleteFunc (alertsConfigs , func (c * alerts.Config ) bool {
250
+ return c .UploadID != dataSetID
251
+ })
242
252
return alertsConfigs , nil
243
253
}
244
254
@@ -297,10 +307,6 @@ func (e *evaluator) gatherData(ctx context.Context, followedUserID, uploadID str
297
307
func (e * evaluator ) generateNotes (ctx context.Context ,
298
308
alertsConfigs []* alerts.Config , resp * store.AlertableResponse ) []* alerts.Notification {
299
309
300
- if len (alertsConfigs ) == 0 {
301
- return nil
302
- }
303
-
304
310
lgr := e .logger (ctx )
305
311
notifications := []* alerts.Notification {}
306
312
for _ , alertsConfig := range alertsConfigs {
@@ -313,7 +319,6 @@ func (e *evaluator) generateNotes(ctx context.Context,
313
319
note := alertsConfig .Evaluate (c , resp .Glucose , resp .DosingDecisions )
314
320
if note != nil {
315
321
notifications = append (notifications , note )
316
- continue
317
322
}
318
323
}
319
324
0 commit comments