@@ -21,7 +21,6 @@ type Enqueuer interface {
21
21
}
22
22
23
23
type FakeEnqueuer struct {
24
- // authorizer rbac.Authorizer
25
24
mu sync.Mutex
26
25
sent []* FakeNotification
27
26
Store database.Store
@@ -35,40 +34,6 @@ type FakeNotification struct {
35
34
Targets []uuid.UUID
36
35
}
37
36
38
- /*
39
- // TODO: replace this with actual calls to dbauthz.
40
- // See: https://github.com/coder/coder/issues/15481
41
- func (f *FakeEnqueuer) assertRBACNoLock(ctx context.Context) {
42
- if f.mu.TryLock() {
43
- panic("Developer error: do not call assertRBACNoLock outside of a mutex lock!")
44
- }
45
-
46
- // If we get here, we are locked.
47
- if f.authorizer == nil {
48
- f.authorizer = rbac.NewStrictCachingAuthorizer(prometheus.NewRegistry())
49
- }
50
-
51
- act, ok := dbauthz.ActorFromContext(ctx)
52
- if !ok {
53
- panic("Developer error: no actor in context, you may need to use dbauthz.AsNotifier(ctx)")
54
- }
55
-
56
- for _, a := range []policy.Action{policy.ActionCreate, policy.ActionRead} {
57
- err := f.authorizer.Authorize(ctx, act, a, rbac.ResourceNotificationMessage)
58
- if err == nil {
59
- return
60
- }
61
-
62
- if rbac.IsUnauthorizedError(err) {
63
- panic(fmt.Sprintf("Developer error: not authorized to %s %s. "+
64
- "Ensure that you are using dbauthz.AsXXX with an actor that has "+
65
- "policy.ActionCreate on rbac.ResourceNotificationMessage", a, rbac.ResourceNotificationMessage.Type))
66
- }
67
- panic("Developer error: failed to check auth:" + err.Error())
68
- }
69
- }
70
- */
71
-
72
37
func (f * FakeEnqueuer ) Enqueue (ctx context.Context , userID , templateID uuid.UUID , labels map [string ]string , createdBy string , targets ... uuid.UUID ) ([]uuid.UUID , error ) {
73
38
return f .EnqueueWithData (ctx , userID , templateID , labels , nil , createdBy , targets ... )
74
39
}
@@ -82,11 +47,23 @@ func (f *FakeEnqueuer) enqueueWithDataLock(ctx context.Context, userID, template
82
47
defer f .mu .Unlock ()
83
48
id := uuid .New ()
84
49
var err error
50
+
51
+ // To avoid a duplicate notification, make a unique-enough payload out of what
52
+ // we have.
53
+ fakePayload := make (map [string ]any )
54
+ fakePayload ["template_id" ] = templateID
55
+ fakePayload ["labels" ] = labels
56
+ fakePayload ["data" ] = data
57
+ fakePayloadBytes , err := json .Marshal (fakePayload )
58
+ if err != nil {
59
+ return nil , err
60
+ }
61
+
85
62
if err = f .Store .EnqueueNotificationMessage (ctx , database.EnqueueNotificationMessageParams {
86
63
ID : id ,
87
64
UserID : userID ,
88
65
NotificationTemplateID : templateID ,
89
- Payload : json . RawMessage ( `{}` ) ,
66
+ Payload : fakePayloadBytes ,
90
67
Method : database .NotificationMethodInbox ,
91
68
Targets : targets ,
92
69
CreatedBy : createdBy ,
0 commit comments