Skip to content

Commit

Permalink
allow invites to set an upload id
Browse files Browse the repository at this point in the history
The upload id is necessary to ensure that only the proper device data uploads
are evaluated for care partner alert conditions.

BACK-2554
  • Loading branch information
ewollesen committed Jul 8, 2024
1 parent 9ee4360 commit b3fe600
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions data/service/api/v1/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,13 @@ func UpsertAlert(dCtx service.Context) {
return
}

a := &alerts.Alerts{}
if err := request.DecodeRequestBody(r.Request, a); err != nil {
incomingCfg := &alerts.Config{}
var bodyReceiver interface{} = &incomingCfg.Alerts
if authDetails.IsService() && authDetails.UserID() == "" {
// Accept upload id only from services.
bodyReceiver = incomingCfg
}
if err := request.DecodeRequestBody(r.Request, bodyReceiver); err != nil {
dCtx.RespondWithError(platform.ErrorJSONMalformed())
return
}
Expand All @@ -127,7 +132,12 @@ func UpsertAlert(dCtx service.Context) {
return
}

cfg := &alerts.Config{UserID: path.UserID, FollowedUserID: path.FollowedUserID, Alerts: *a}
cfg := &alerts.Config{
UserID: path.UserID,
FollowedUserID: path.FollowedUserID,
UploadID: incomingCfg.UploadID,
Alerts: incomingCfg.Alerts,
}
if err := repo.Upsert(ctx, cfg); err != nil {
dCtx.RespondWithError(platform.ErrorInternalServerFailure())
lgr.WithError(err).Error("upserting alerts config")
Expand Down

0 comments on commit b3fe600

Please sign in to comment.