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:
@@ -9,11 +9,15 @@ import (
|
||||
"git.golem15.com/golem15/summercms/modules/party"
|
||||
"git.golem15.com/golem15/summercms/modules/wire"
|
||||
"git.golem15.com/jakub/sm-bm-plugin/classes"
|
||||
"git.golem15.com/jakub/sm-bm-plugin/controllers/api"
|
||||
)
|
||||
|
||||
// MiddlewareRealtimeAccess guards the realtime connection-token route: a
|
||||
// token is minted only for someone with a realtime consumer, a chat-group
|
||||
// member or a presentation owner. It runs after jwt.auth.
|
||||
// member, a material manager (jz.bm.access_materials, for the live revision
|
||||
// heads-up of the materials they edit) or a presentation owner. It runs
|
||||
// after jwt.auth. The token only opens the socket: every channel is still
|
||||
// authorized by its namespace's authorizer.
|
||||
const MiddlewareRealtimeAccess = "jz.bm.realtime-access"
|
||||
|
||||
// presentationsOwnerGuard is golem15.presentations' owner guard, named
|
||||
@@ -28,9 +32,9 @@ func (p *Plugin) Middlewares() map[string]pact.Middleware {
|
||||
}
|
||||
}
|
||||
|
||||
// realtimeAccess lets a chat-group member through, otherwise, when
|
||||
// golem15.presentations is active, whoever its owner guard lets through
|
||||
// (it answers its own refusals), and refuses everyone else. The owner guard
|
||||
// realtimeAccess lets a chat-group member or a material manager through,
|
||||
// otherwise, when golem15.presentations is active, whoever its owner guard
|
||||
// lets through (it answers its own refusals), and refuses everyone else. The owner guard
|
||||
// is looked up once, by name, among the activated plugins. With BM's own
|
||||
// Centrifugo instance the tokens it mints are valid for BM only.
|
||||
func (p *Plugin) realtimeAccess(next http.Handler) http.Handler {
|
||||
@@ -70,6 +74,19 @@ func (p *Plugin) realtimeAccess(next http.Handler) http.Handler {
|
||||
return
|
||||
}
|
||||
}
|
||||
isManager := p.materialManager
|
||||
if isManager == nil {
|
||||
isManager = api.ManagesMaterials
|
||||
}
|
||||
manager, err := isManager(r.Context(), db, user.ID)
|
||||
if err != nil {
|
||||
writeRealtimeGuard(w, http.StatusServiceUnavailable, "Service unavailable")
|
||||
return
|
||||
}
|
||||
if manager {
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
if p.app.HasPlugin("golem15.presentations") {
|
||||
if h := ownerGuard(); h != nil {
|
||||
h.ServeHTTP(w, r)
|
||||
|
||||
Reference in New Issue
Block a user