feat: material managers get a realtime token

- jz.bm.realtime-access admits holders of jz.bm.access_materials
  (Assumption A5), so every editor can follow materials:{id}
- README documents the materials channel, event and authorizer
This commit is contained in:
Jakub Zych
2026-11-09 01:14:56 +01:00
parent 2a47186a7a
commit 8bef2d7acf
5 changed files with 51 additions and 9 deletions

View File

@@ -48,6 +48,15 @@ func chatGroupMember(_ context.Context, _ *gorm.DB, userID uint, group string) (
return group == "studenci" && userID == 7, nil
}
// materialManager is the injected material-manager check: user 9 holds
// jz.bm.access_materials, user 14 makes the check fail.
func materialManager(_ context.Context, _ *gorm.DB, userID uint) (bool, error) {
if userID == 14 {
return false, errors.New("database down")
}
return userID == 9, nil
}
// accessPlugin builds jz.bm on an app with the given active plugin ids, a
// published (fake) database unless noDB, and golem15.presentations in the
// activated list when withOwnerGuard.
@@ -71,7 +80,7 @@ func accessPlugin(t *testing.T, ids []string, noDB, withOwnerGuard bool) *Plugin
if err := app.Publish(activated); err != nil {
t.Fatal(err)
}
return &Plugin{app: app, chatMember: chatGroupMember}
return &Plugin{app: app, chatMember: chatGroupMember, materialManager: materialManager}
}
func TestRealtimeAccess(t *testing.T) {
@@ -96,6 +105,10 @@ func TestRealtimeAccess(t *testing.T) {
{"no database", both, true, true, 7, http.StatusServiceUnavailable},
{"membership check fails", both, false, true, 13, http.StatusServiceUnavailable},
{"no consumer", []string{"golem15.user", "jz.bm"}, false, false, 7, http.StatusForbidden},
{"material manager", both, false, true, 9, http.StatusOK},
{"material manager without chat", presOnly, false, true, 9, http.StatusOK},
{"material manager without presentations", chatOnly, false, false, 9, http.StatusOK},
{"manager check fails", both, false, true, 14, http.StatusServiceUnavailable},
} {
p := accessPlugin(t, c.ids, c.noDB, c.guard)
mw, ok := p.Middlewares()[MiddlewareRealtimeAccess]