Download this file
| 1 | package equipo |
| 2 | |
| 3 | import ( |
| 4 | "amadan.net/oficina/equipo/internal/equipo/notifications" |
| 5 | "amadan.net/oficina/equipo/internal/equipo/personapi" |
| 6 | "gorm.io/gorm" |
| 7 | "net/http" |
| 8 | ) |
| 9 | |
| 10 | type Notification = notifications.Notification |
| 11 | type NotificationSubscription = notifications.NotificationSubscription |
| 12 | type NotificationApplication = notifications.Store |
| 13 | |
| 14 | func (s *Store) notificationApplication() *NotificationApplication { |
| 15 | return ¬ifications.Store{Write: s.write, Read: s.invitationRead, Authorize: func(tx *gorm.DB, a Actor) (string, error) { |
| 16 | if _, err := currentRunnerMember(tx, a.Address); err != nil { |
| 17 | return "", err |
| 18 | } |
| 19 | return runnerInstance(tx) |
| 20 | }, Audit: appendAudit, Devices: s.personDevices, Key: func() string { return s.personKey }, Now: s.runnerClock.Now, Invalid: ErrInvalid, Forbidden: ErrForbidden, NotFound: ErrNotFound, Conflict: ErrConflict, CursorExpired: ErrCursorExpired} |
| 21 | } |
| 22 | func (a *application) allowNotification(r *http.Request, key string) bool { |
| 23 | p, err := a.store.personCookie(r) |
| 24 | if err != nil { |
| 25 | return false |
| 26 | } |
| 27 | return a.store.AllowNotificationTopic(personapi.WithVerifiedPrincipal(r.Context(), p), Actor{Address: p.Address}, key) |
| 28 | } |
| 29 | |