Phase 13, part 7: the platform's own admin
The people running the multi-tenant service (SUPERMARKET_PLATFORM_ADMINS, with two-factor sign-in) see every team at /platform with its size, people and what failed lately, and can suspend or restore a team, resend its invitations and release its domain. They don't see a team's data unless they view as it: with a reason, for at most an hour, read-only, recorded in the team's own audit log. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+39
-3
@@ -27,6 +27,9 @@ type viewer struct {
|
||||
User *users.User // nil on the local edition
|
||||
Member users.Membership
|
||||
Session *users.Session // nil on the local edition
|
||||
|
||||
Platform bool // runs the multi-tenant platform (SUPERMARKET_PLATFORM_ADMINS)
|
||||
Viewing bool // a platform admin viewing a team, read-only
|
||||
}
|
||||
|
||||
// localOwner is the local edition's one user.
|
||||
@@ -109,6 +112,21 @@ func (s *Server) sessions(next http.Handler) http.Handler {
|
||||
s.toSignIn(w, r)
|
||||
return
|
||||
}
|
||||
if s.multi() && v.Session != nil && !publicPath(r.URL.Path) && !platformPath(r.URL.Path) {
|
||||
// A platform admin outside any team: the platform's pages.
|
||||
if v.Session.Team == 0 {
|
||||
http.Redirect(w, r, "/platform", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
// A team that's suspended or being deleted is closed, but for
|
||||
// switching teams, one's account, and the platform's admins.
|
||||
if !v.Viewing && !strings.HasPrefix(r.URL.Path, "/teams/") {
|
||||
if t, err := users.GetTeam(s.platform(), v.Session.Team); err == nil && t.Status != users.TeamActive {
|
||||
s.teamClosed(w, r, t)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
next.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), viewerKey, v)))
|
||||
})
|
||||
}
|
||||
@@ -119,10 +137,28 @@ func (s *Server) lookupSession(r *http.Request) (*viewer, error) {
|
||||
if err != nil {
|
||||
return nil, users.ErrNoSession
|
||||
}
|
||||
sess, u, err := users.Lookup(s.platform(), c.Value, time.Now())
|
||||
now := time.Now()
|
||||
sess, u, err := users.Lookup(s.platform(), c.Value, now)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pa := s.isPlatformAdmin(u)
|
||||
if s.multi() && !sess.ViewUntil.IsZero() {
|
||||
if pa && now.Before(sess.ViewUntil) {
|
||||
return &viewer{User: u, Member: readOnly(sess.Team), Session: sess, Platform: true, Viewing: true}, nil
|
||||
}
|
||||
// Ran out: back to the platform.
|
||||
if err := users.ViewAs(s.platform(), sess.ID, 0, time.Time{}, ""); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sess.Team, sess.ViewUntil, sess.ViewReason = 0, time.Time{}, ""
|
||||
}
|
||||
if s.multi() && sess.Team == 0 {
|
||||
if !pa {
|
||||
return nil, users.ErrNoSession
|
||||
}
|
||||
return &viewer{User: u, Member: users.Membership{Team: 0, Role: users.Member}, Session: sess, Platform: true}, nil
|
||||
}
|
||||
m, err := users.MembershipOf(s.platform(), sess.Team, u.ID)
|
||||
if errors.Is(err, users.ErrNotFound) {
|
||||
return nil, users.ErrNoSession // no longer in the team
|
||||
@@ -130,7 +166,7 @@ func (s *Server) lookupSession(r *http.Request) (*viewer, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &viewer{User: u, Member: m, Session: sess}, nil
|
||||
return &viewer{User: u, Member: m, Session: sess, Platform: pa}, nil
|
||||
}
|
||||
|
||||
// toSignIn sends someone who isn't signed in to the sign-in page, and
|
||||
@@ -167,7 +203,7 @@ func (s *Server) startSession(w http.ResponseWriter, r *http.Request, u *users.U
|
||||
team = t.ID
|
||||
}
|
||||
}
|
||||
if team == 0 {
|
||||
if team == 0 && !s.isPlatformAdmin(u) {
|
||||
return errors.New("you aren't in any team that's open")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user