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:
@@ -40,6 +40,7 @@ var routeAreas = map[string]string{
|
||||
"=/profile": areaSignedIn, "=/core": areaSignedIn,
|
||||
|
||||
"/settings": areaAdmin,
|
||||
"/platform": areaPlatform,
|
||||
// Signing in to a posting account: admins for the company's, anyone
|
||||
// with Content for their own (oauthStart checks which).
|
||||
"/auth": areaSignedIn,
|
||||
@@ -91,6 +92,8 @@ func (v *viewer) can(area string, write bool) bool {
|
||||
return v.User != nil || v == localOwner
|
||||
case areaAdmin:
|
||||
return v.Member.Admin()
|
||||
case areaPlatform:
|
||||
return v.Platform
|
||||
}
|
||||
return v.Member.Can(area, write)
|
||||
}
|
||||
|
||||
@@ -180,7 +180,8 @@ var actionLabels = map[string]string{
|
||||
"key-made": "made a new key for", "key-revoked": "revoked a key of",
|
||||
"asked-approval": "asked for approval to", "did-on-its-own": "did on its own:", "approved": "approved", "refused": "refused",
|
||||
"allowed-on-its-own": "let an agent act on its own:", "withdrew-on-its-own": "took back what an agent may do on its own:",
|
||||
"team-created": "set up the team", "domain-proved": "proved the domain", "agent-paused": "paused the agent", "agent-resumed": "resumed the agent", "agent-limits": "changed the limits of",
|
||||
"team-created": "set up the team", "viewed-as": "looked at the team's data:", "team-suspended": "suspended the team", "team-restored": "restored the team",
|
||||
"domain-released": "released the domain", "invitations-resent": "sent the invitations again:", "domain-proved": "proved the domain", "agent-paused": "paused the agent", "agent-resumed": "resumed the agent", "agent-limits": "changed the limits of",
|
||||
"wrote-draft": "wrote a draft:", "edited-draft": "edited a draft:", "edited-change": "edited a proposed change to", "market-added": "added to the Market", "market-changed": "changed in the Market",
|
||||
}
|
||||
|
||||
|
||||
+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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,224 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"supermarket/internal/audit"
|
||||
"supermarket/internal/users"
|
||||
)
|
||||
|
||||
// The platform's own admin (multi-tenant): the people running the service,
|
||||
// listed in SUPERMARKET_PLATFORM_ADMINS, at /platform, with two-factor
|
||||
// sign-in. They see the teams and their health, suspend a team, resend its
|
||||
// invitations, release a proved domain; they don't see a team's data,
|
||||
// unless they *view as* it: with a reason, for at most an hour, read-only,
|
||||
// and recorded in the team's own audit log.
|
||||
|
||||
const areaPlatform = "platform"
|
||||
|
||||
// maxViewAs is the longest a platform admin views a team.
|
||||
const maxViewAs = time.Hour
|
||||
|
||||
// isPlatformAdmin says whether a person runs the platform.
|
||||
func (s *Server) isPlatformAdmin(u *users.User) bool {
|
||||
if !s.multi() || s.Config == nil || u == nil || u.Kind != users.Person {
|
||||
return false
|
||||
}
|
||||
for _, a := range s.Config.PlatformAdmins {
|
||||
if strings.EqualFold(a, u.Email) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// readOnly is a membership that sees every module and changes nothing:
|
||||
// a platform admin viewing a team.
|
||||
func readOnly(team int64) users.Membership {
|
||||
m := users.Membership{Team: team, Role: users.Member, Modules: map[string]users.Access{}}
|
||||
for _, g := range grants() {
|
||||
m.Modules[g.ID] = users.View
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// platformPaths are what a platform admin's session outside any team may
|
||||
// reach.
|
||||
func platformPath(p string) bool {
|
||||
return strings.HasPrefix(p, "/platform") || strings.HasPrefix(p, "/settings/account") || p == "/signout" ||
|
||||
strings.HasPrefix(p, "/users/") || strings.HasPrefix(p, "/static/") || p == "/favicon.ico"
|
||||
}
|
||||
|
||||
// teamRow is a team on the platform page.
|
||||
type teamRow struct {
|
||||
users.TeamInfo
|
||||
Members, Invited int
|
||||
Bytes int64
|
||||
FailedPosts int
|
||||
FailedEmails int
|
||||
FailedRequests int
|
||||
LastActivity time.Time
|
||||
Err string
|
||||
}
|
||||
|
||||
func (s *Server) platformPage(w http.ResponseWriter, r *http.Request) {
|
||||
v := viewerOf(r)
|
||||
if !v.Platform {
|
||||
s.forbidden(w, r)
|
||||
return
|
||||
}
|
||||
u, err := users.ByID(s.platform(), v.User.ID)
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
if !u.TwoFactor {
|
||||
s.render(w, r, "platform", page{Title: "Platform", Nav: "platform", Data: map[string]any{"Need2FA": true}})
|
||||
return
|
||||
}
|
||||
list, err := users.ListTeams(s.platform())
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
week := time.Now().AddDate(0, 0, -7).UTC()
|
||||
var rows []teamRow
|
||||
for _, t := range list {
|
||||
row := teamRow{TeamInfo: t}
|
||||
row.Members, row.Invited, _ = users.TeamCounts(s.platform(), t.ID)
|
||||
_ = s.platform().QueryRow(`SELECT coalesce(sum(pg_total_relation_size(c.oid)), 0) FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace
|
||||
WHERE n.nspname = ? AND c.relkind = 'r'`, s.Teams.Schema(t.ID)).Scan(&row.Bytes)
|
||||
// Health: what failed in the last week, counted, never read.
|
||||
if ts, err := s.forTeam(t.ID); err != nil {
|
||||
row.Err = err.Error()
|
||||
} else {
|
||||
wk := week.Format("2006-01-02T15:04:05Z")
|
||||
_ = ts.DB.QueryRow(`SELECT count(*) FROM drafts WHERE status = 'failed' AND updated_at >= ?`, wk).Scan(&row.FailedPosts)
|
||||
_ = ts.DB.QueryRow(`SELECT count(*) FROM outreach WHERE status = 'failed' AND created_at >= ?`, wk).Scan(&row.FailedEmails)
|
||||
_ = ts.DB.QueryRow(`SELECT count(*) FROM approvals WHERE status = 'failed' AND created_at >= ?`, week.Format("2006-01-02T15:04:05.000Z")).Scan(&row.FailedRequests)
|
||||
var last string
|
||||
_ = ts.DB.QueryRow(`SELECT coalesce(max(at), '') FROM audit_log`).Scan(&last)
|
||||
row.LastActivity, _ = time.Parse("2006-01-02T15:04:05.000Z", last)
|
||||
}
|
||||
rows = append(rows, row)
|
||||
}
|
||||
s.render(w, r, "platform", page{Title: "Platform", Nav: "platform", Data: map[string]any{"Teams": rows, "MaxView": int(maxViewAs / time.Minute)}})
|
||||
}
|
||||
|
||||
// platformAction: suspend, restore, resend, release-domain, view-as.
|
||||
func (s *Server) platformAction(w http.ResponseWriter, r *http.Request) {
|
||||
v := viewerOf(r)
|
||||
if !v.Platform {
|
||||
s.forbidden(w, r)
|
||||
return
|
||||
}
|
||||
if u, err := users.ByID(s.platform(), v.User.ID); err != nil || !u.TwoFactor {
|
||||
http.Redirect(w, r, "/platform", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
id, _ := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
||||
t, err := users.GetTeam(s.platform(), id)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
ts, err := s.forTeam(id)
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
who := displayName(v.User) + " (the platform's admin)"
|
||||
log := func(action, detail string) {
|
||||
ts.record(audit.Entry{UserID: v.User.ID, UserName: who, Action: action, Target: t.Name, Detail: detail, IP: clientIP(r)})
|
||||
s.Log.Info("platform: "+action, "team", t.ID, "by", v.User.Email, "detail", detail)
|
||||
}
|
||||
now := time.Now()
|
||||
switch r.PathValue("action") {
|
||||
case "suspend":
|
||||
if err := users.SetTeamStatus(s.platform(), id, users.TeamSuspended, time.Time{}); err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
log("team-suspended", r.PostFormValue("reason"))
|
||||
redirect(w, r, "/platform", "team-suspended")
|
||||
case "restore":
|
||||
if err := users.SetTeamStatus(s.platform(), id, users.TeamActive, time.Time{}); err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
log("team-restored", "")
|
||||
redirect(w, r, "/platform", "team-restored")
|
||||
case "release-domain":
|
||||
if err := users.ReleaseDomain(s.platform(), id); err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
log("domain-released", t.Domain)
|
||||
redirect(w, r, "/platform", "domain-released")
|
||||
case "resend":
|
||||
members, err := users.Members(s.platform(), id)
|
||||
if err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
n := 0
|
||||
for _, m := range members {
|
||||
if m.Status == users.Invited && m.Kind == users.Person {
|
||||
if err := ts.sendInvitation(v, m.User); err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
n++
|
||||
}
|
||||
}
|
||||
log("invitations-resent", fmt.Sprintf("%d", n))
|
||||
redirectCounts(w, r, "/platform", "invitations-resent", n)
|
||||
case "view-as":
|
||||
reason := strings.TrimSpace(r.PostFormValue("reason"))
|
||||
mins, _ := strconv.Atoi(r.PostFormValue("minutes"))
|
||||
if reason == "" || mins <= 0 {
|
||||
redirect(w, r, "/platform", "view-needs-reason")
|
||||
return
|
||||
}
|
||||
d := time.Duration(mins) * time.Minute
|
||||
if d > maxViewAs {
|
||||
d = maxViewAs
|
||||
}
|
||||
if err := users.ViewAs(s.platform(), v.Session.ID, id, now.Add(d), reason); err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
log("viewed-as", fmt.Sprintf("%s (for %d minutes)", reason, int(d/time.Minute)))
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
// platformStopViewing ends a view-as.
|
||||
func (s *Server) platformStopViewing(w http.ResponseWriter, r *http.Request) {
|
||||
v := viewerOf(r)
|
||||
if !v.Platform || v.Session == nil {
|
||||
s.forbidden(w, r)
|
||||
return
|
||||
}
|
||||
if err := users.ViewAs(s.platform(), v.Session.ID, 0, time.Time{}, ""); err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, "/platform", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// teamClosed is what a suspended team's people see.
|
||||
func (s *Server) teamClosed(w http.ResponseWriter, r *http.Request, t *users.TeamInfo) {
|
||||
if r.Header.Get("HX-Request") != "" || !safeMethod(r.Method) {
|
||||
http.Error(w, "This team is "+t.Status+".", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
s.render(w, r, "team-closed", page{Title: t.Name, Bare: true, Data: t})
|
||||
}
|
||||
@@ -331,6 +331,9 @@ func (s *Server) Handler() (http.Handler, error) {
|
||||
// Signing in (the server edition).
|
||||
mux.HandleFunc("GET /setup/{token}", (*Server).setupPage)
|
||||
mux.HandleFunc("POST /setup/{token}", (*Server).setupSave)
|
||||
mux.HandleFunc("GET /platform", (*Server).platformPage)
|
||||
mux.HandleFunc("POST /platform/stop-viewing", (*Server).platformStopViewing)
|
||||
mux.HandleFunc("POST /platform/teams/{id}/{action}", (*Server).platformAction)
|
||||
mux.HandleFunc("GET /signup", (*Server).signupPage)
|
||||
mux.HandleFunc("POST /signup", (*Server).signup)
|
||||
mux.HandleFunc("POST /teams/switch", (*Server).teamSwitch)
|
||||
@@ -920,6 +923,11 @@ var flashes = map[string]string{
|
||||
"added": "Added: they're told by email, and sign in as they do.",
|
||||
"prove-first": "First prove the team's domain is yours: Supermarket only crawls, reads or publishes to a website its team has proved.",
|
||||
"domain-proved": "Proved: the domain is the team's.",
|
||||
"team-suspended": "Suspended: its people see that it is, and its work waits.",
|
||||
"team-restored": "Restored.",
|
||||
"domain-released": "Released: another team can prove the domain now.",
|
||||
"invitations-resent": "Sent %d invitations again.",
|
||||
"view-needs-reason": "Give a reason and how long: it's recorded in the team's own log.",
|
||||
"account-removed": "Signed out: posts scheduled to it are back in Posts.",
|
||||
"own-account-connected": "Connected: you can post as it, and an admin can let others.",
|
||||
"deleted": "Deleted.",
|
||||
|
||||
@@ -116,7 +116,7 @@ func (s *Server) cannotSignIn(u *users.User) string {
|
||||
return badSignIn
|
||||
}
|
||||
if s.multi() {
|
||||
if list, err := users.TeamsOf(s.platform(), u.ID); err != nil || len(list) == 0 {
|
||||
if list, err := users.TeamsOf(s.platform(), u.ID); (err != nil || len(list) == 0) && !s.isPlatformAdmin(u) {
|
||||
return "This account isn't part of any team any more."
|
||||
}
|
||||
return ""
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"supermarket/internal/audit"
|
||||
"supermarket/internal/config"
|
||||
"supermarket/internal/content"
|
||||
"supermarket/internal/db"
|
||||
@@ -380,3 +381,74 @@ func TestCorePerTeam(t *testing.T) {
|
||||
t.Error("not on Connections")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlatformAdmin(t *testing.T) {
|
||||
s, h := newMultiEdition(t)
|
||||
s.Config.PlatformAdmins = []string{"ops@platform.example"}
|
||||
a, _, ac := newTeam(t, s, "Acme", "olu@acme.example")
|
||||
as(h, ac, http.MethodPost, "/settings/profile", url.Values{"name": {"Acme Inc"}, "description": {"Secret plans"}})
|
||||
as(h, ac, http.MethodPost, "/market/save", url.Values{"name": {"Rival"}, "relationship": {"competitor"}, "description": {"x"}})
|
||||
|
||||
ops := &users.User{Email: "ops@platform.example", Name: "Ops", Status: users.Active}
|
||||
users.Create(s.platform(), ops, time.Now())
|
||||
users.SetPassword(s.platform(), ops, "a long enough one")
|
||||
// Not in any team, they can still sign in, to the platform.
|
||||
rec := signin(h, "203.0.113.9", url.Values{"email": {"ops@platform.example"}, "password": {"a long enough one"}})
|
||||
oc := cookieOf(rec, sessionCookie)
|
||||
if oc == nil {
|
||||
t.Fatalf("sign in: %d %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
if rec := as(h, oc, http.MethodGet, "/market", nil); rec.Code != http.StatusSeeOther || rec.Header().Get("Location") != "/platform" {
|
||||
t.Errorf("a team page: %d %s", rec.Code, rec.Header().Get("Location"))
|
||||
}
|
||||
if body := as(h, oc, http.MethodGet, "/platform", nil).Body.String(); !strings.Contains(body, "two-factor") {
|
||||
t.Error("no two-factor demanded")
|
||||
}
|
||||
users.SetTwoFactor(s.platform(), ops, true, []string{"x"})
|
||||
body := as(h, oc, http.MethodGet, "/platform", nil).Body.String()
|
||||
if !strings.Contains(body, "Acme") || !strings.Contains(body, "acme.example") || strings.Contains(body, "Secret plans") || strings.Contains(body, "Rival") {
|
||||
t.Errorf("platform page: %s", body)
|
||||
}
|
||||
// A team's owner isn't a platform admin.
|
||||
if rec := as(h, ac, http.MethodGet, "/platform", nil); rec.Code != http.StatusForbidden {
|
||||
t.Errorf("owner on /platform: %d", rec.Code)
|
||||
}
|
||||
|
||||
id := strconv.FormatInt(a.ID, 10)
|
||||
// Suspend: the team's people see it closed; restore.
|
||||
as(h, oc, http.MethodPost, "/platform/teams/"+id+"/suspend", url.Values{"reason": {"unpaid"}})
|
||||
if rec := as(h, ac, http.MethodGet, "/market", nil); rec.Code != http.StatusForbidden || !strings.Contains(rec.Body.String(), "suspended") {
|
||||
t.Errorf("suspended: %d", rec.Code)
|
||||
}
|
||||
as(h, oc, http.MethodPost, "/platform/teams/"+id+"/restore", url.Values{})
|
||||
if rec := as(h, ac, http.MethodGet, "/market", nil); rec.Code != http.StatusOK {
|
||||
t.Errorf("restored: %d", rec.Code)
|
||||
}
|
||||
|
||||
// View as: a reason, a while, read-only, and in the team's log.
|
||||
if rec := as(h, oc, http.MethodPost, "/platform/teams/"+id+"/view-as", url.Values{"minutes": {"10"}}); !strings.Contains(rec.Header().Get("Location"), "view-needs-reason") {
|
||||
t.Error("viewed without a reason")
|
||||
}
|
||||
as(h, oc, http.MethodPost, "/platform/teams/"+id+"/view-as", url.Values{"reason": {"ticket 42"}, "minutes": {"600"}})
|
||||
body = as(h, oc, http.MethodGet, "/market", nil).Body.String()
|
||||
if !strings.Contains(body, "Rival") || !strings.Contains(body, "Viewing this team as the platform") || !strings.Contains(body, "ticket 42") {
|
||||
t.Errorf("view as: %s", body)
|
||||
}
|
||||
if rec := as(h, oc, http.MethodPost, "/market/save", url.Values{"name": {"X"}, "relationship": {"partner"}}); rec.Code != http.StatusForbidden {
|
||||
t.Errorf("changed while viewing: %d", rec.Code)
|
||||
}
|
||||
if rec := as(h, oc, http.MethodGet, "/settings/profile", nil); rec.Code != http.StatusForbidden {
|
||||
t.Errorf("Settings while viewing: %d", rec.Code)
|
||||
}
|
||||
ts, _ := s.forTeam(a.ID)
|
||||
entries, _ := audit.List(ts.DB, audit.Filter{Action: "viewed-as"}, 5)
|
||||
if len(entries) != 1 || !strings.Contains(entries[0].Detail, "ticket 42 (for 60 minutes)") || !strings.Contains(entries[0].UserName, "platform") {
|
||||
t.Errorf("team's log: %+v", entries)
|
||||
}
|
||||
// It runs out.
|
||||
sess, _, _ := users.Lookup(s.platform(), oc.Value, time.Now())
|
||||
users.ViewAs(s.platform(), sess.ID, a.ID, time.Now().Add(-time.Minute), "ticket 42")
|
||||
if rec := as(h, oc, http.MethodGet, "/market", nil); rec.Header().Get("Location") != "/platform" {
|
||||
t.Errorf("after the time: %d", rec.Code)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
</form>
|
||||
<nav class="nav" aria-label="Main">
|
||||
<a href="/" {{if eq .Nav "home"}}aria-current="page"{{end}}>{{template "icon" "overview"}}<span>Overview</span></a>
|
||||
{{with .Viewer}}{{if .Platform}}<a href="/platform" {{if eq $.Nav "platform"}}aria-current="page"{{end}}>{{template "icon" "info"}}<span>Platform</span></a>{{end}}{{end}}
|
||||
<a href="/approvals" {{if eq .Nav "approvals"}}aria-current="page"{{end}}>{{template "icon" "ai"}}<span>Approvals</span>{{with .Approvals}} <span class="count-badge" title="{{.}} waiting for you">{{.}}</span>{{end}}</a>
|
||||
{{if .Can "market"}}<a href="/market" {{if eq .Nav "inventory"}}aria-current="page"{{end}}>{{template "icon" "inventory"}}<span>Market</span></a>{{end}}
|
||||
|
||||
@@ -125,6 +126,8 @@
|
||||
</nav>
|
||||
</header>
|
||||
<main>
|
||||
{{with .Viewer}}{{if .Viewing}}<div class="card warn viewing" role="status"><p><strong>Viewing this team as the platform's admin</strong>, read-only, until {{.Session.ViewUntil.Local.Format "15:04"}}: {{.Session.ViewReason}}</p>
|
||||
<form method="post" action="/platform/stop-viewing"><button type="submit" class="secondary small">Stop viewing</button></form></div>{{end}}{{end}}
|
||||
{{if .Flash}}<p class="flash" role="status">{{.Flash}}</p>{{end}}
|
||||
{{if .Error}}<p class="error" role="alert">{{.Error}}</p>{{end}}
|
||||
{{template "content" .}}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
{{define "content"}}{{with .Data}}
|
||||
<div class="page-head"><h1>Platform</h1>
|
||||
<p class="lede">The teams on this Supermarket, and how they're doing. You don't see a team's data: to look, <em>view as</em> it, with a reason, for a while; it's recorded in the team's own log.</p></div>
|
||||
{{if .Need2FA}}
|
||||
<section class="card warn"><p>The platform's admin pages need two-factor sign-in. <a href="/settings/account/two-factor">Turn it on</a>, then come back.</p></section>
|
||||
{{else}}
|
||||
<section class="card">
|
||||
<table class="list">
|
||||
<thead><tr><th>Team</th><th>Domain</th><th>People</th><th class="num">Data</th><th>Last week</th><th>Last active</th><th></th></tr></thead>
|
||||
<tbody>{{range .Teams}}<tr>
|
||||
<td><strong>{{.Name}}</strong> {{if ne .Status "active"}}<span class="pill warn">{{.Status}}</span>{{end}}<br><span class="muted small">since {{.Created.Local.Format "2 Jan 2006"}}</span>{{with .Err}}<br><span class="error-text small">{{.}}</span>{{end}}</td>
|
||||
<td>{{.Domain}} {{if .Proved}}<span class="pill ok">proved</span>{{else}}<span class="pill">not proved</span>{{end}}</td>
|
||||
<td>{{.Members}}{{if .Invited}} <span class="muted small">({{.Invited}} invited)</span>{{end}}</td>
|
||||
<td class="num">{{bytes .Bytes}}</td>
|
||||
<td>{{if or .FailedPosts .FailedEmails .FailedRequests}}<span class="error-text small">{{with .FailedPosts}}{{.}} posts failed. {{end}}{{with .FailedEmails}}{{.}} emails failed. {{end}}{{with .FailedRequests}}{{.}} agent requests failed.{{end}}</span>{{else}}<span class="muted small">nothing failed</span>{{end}}</td>
|
||||
<td>{{ago .LastActivity}}</td>
|
||||
<td><details><summary class="small">Act</summary>
|
||||
<div class="actions">
|
||||
{{if eq .Status "active"}}<form method="post" action="/platform/teams/{{.ID}}/suspend" data-confirm="Suspend {{.Name}}? Its people can't use it, and its work waits."><input name="reason" placeholder="Why" class="small" required><button type="submit" class="secondary small danger">Suspend</button></form>
|
||||
{{else}}<form method="post" action="/platform/teams/{{.ID}}/restore"><button type="submit" class="secondary small">Restore</button></form>{{end}}
|
||||
{{if .Invited}}<form method="post" action="/platform/teams/{{.ID}}/resend"><button type="submit" class="secondary small">Resend invitations</button></form>{{end}}
|
||||
{{if .Proved}}<form method="post" action="/platform/teams/{{.ID}}/release-domain" data-confirm="Release {{.Domain}}? Another team could then prove it."><button type="submit" class="secondary small">Release the domain</button></form>{{end}}
|
||||
<form method="post" action="/platform/teams/{{.ID}}/view-as"><input name="reason" placeholder="Why you need to look" required class="small"> <input name="minutes" type="number" min="1" max="{{$.Data.MaxView}}" value="15" class="tiny"> min <button type="submit" class="secondary small">View as</button></form>
|
||||
</div>
|
||||
</details></td>
|
||||
</tr>{{else}}<tr><td colspan="7" class="muted">No teams yet.</td></tr>{{end}}</tbody>
|
||||
</table>
|
||||
</section>
|
||||
{{end}}
|
||||
{{end}}{{end}}
|
||||
@@ -0,0 +1,8 @@
|
||||
{{define "content"}}{{with .Data}}
|
||||
<h1>{{.Name}} is {{.Status}}</h1>
|
||||
<section class="card">
|
||||
{{if eq .Status "suspended"}}<p>The people running Supermarket have suspended this team. Its data is kept, and its work waits. Ask them why, or for it to be restored.</p>
|
||||
{{else}}<p>This team is being deleted. Its owner can still undo it, until {{.DeleteAt.Local.Format "2 Jan 2006"}}.</p>{{end}}
|
||||
<p><a href="/settings/account">Your account</a> · <form class="inline" method="post" action="/signout"><button type="submit" class="secondary small">Sign out</button></form></p>
|
||||
</section>
|
||||
{{end}}{{end}}
|
||||
Reference in New Issue
Block a user