An organization's admin, and forms only for those who may send them
C1. A membership of an organization may be admin as well as member and manager. An admin sees /org as a manager does and changes the organization from it: its teams and projects, who of the approved accounts is in them, its members' roles, and the keys spent in its projects. Every id a form names is checked against the organization; limits, accounts, the organization's name and the cluster stay with the cluster's staff, and an admin cannot take their own role away. A group from OIDC, SCIM or a directory no longer rewrites a membership it names as a plain member at every sign-in, which took a manager's role away (EnsureMembership). Pages draw a form only for someone who may send it: Nav.May asks the staff rule staffMay keeps, and a page whose forms a person may not send gets no form token. A viewer sees the people, limits and mirror pages without forms; an operator the mirror's. Forms are compact: labels close to their fields, fields as wide as what goes in them, smaller buttons, and the short forms on one line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2cb1afda55
commit
102ca9556f
37 files changed
+1204
-212
No files matched your search
+24
-10
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -92,7 +93,10 @@ type adminUsersData struct {
|
||||
// Open is the project whose section is shown expanded: the one just acted
|
||||
// on, so the result of a change is in view without the reader hunting for
|
||||
// it. Scripted pages keep every open section open; this is for the rest.
|
||||
Open string
|
||||
Open string
|
||||
// Edit is whether this person may change what the page shows: a viewer
|
||||
// is drawn the page without its forms.
|
||||
Edit bool
|
||||
AdminID string
|
||||
Message string
|
||||
Error string
|
||||
@@ -173,23 +177,19 @@ func (p *AccountPages) RegisterAdminUsers(mux *http.ServeMux, s AccountAdmin) {
|
||||
return say("users.msg.added_to", scopeLabel(ctx, s, store.Scope(scope), scopeID)), nil
|
||||
}))
|
||||
|
||||
// Managing is a role on an organization membership: it lets the person see
|
||||
// that organization's page, and nothing else changes.
|
||||
// A role on an organization membership: a manager sees that organization's
|
||||
// page, an admin also changes it; a member neither.
|
||||
mux.HandleFunc("POST /admin/users/{id}/role", p.adminAction(s,
|
||||
func(ctx context.Context, admin store.User, id string, r *http.Request) (notice, error) {
|
||||
scope, scopeID, ok := strings.Cut(r.FormValue("scope"), ":")
|
||||
role := r.FormValue("role")
|
||||
if !ok || store.Scope(scope) != store.ScopeOrg || (role != store.RoleManager && role != store.RoleMember) {
|
||||
if !ok || store.Scope(scope) != store.ScopeOrg || !slices.Contains(store.MembershipRoles, role) {
|
||||
return notice{}, refuse("users.err.manager_role")
|
||||
}
|
||||
if err := s.AddMembership(ctx, id, store.ScopeOrg, scopeID, role, admin.Email, time.Now()); err != nil {
|
||||
return notice{}, err
|
||||
}
|
||||
label := scopeLabel(ctx, s, store.ScopeOrg, scopeID)
|
||||
if role == store.RoleManager {
|
||||
return say("users.msg.now_manages", label), nil
|
||||
}
|
||||
return say("users.msg.no_longer_manages", label), nil
|
||||
return roleNotice(role, scopeLabel(ctx, s, store.ScopeOrg, scopeID)), nil
|
||||
}))
|
||||
|
||||
mux.HandleFunc("POST /admin/users/{id}/leave", p.adminAction(s,
|
||||
@@ -351,6 +351,17 @@ func (p *AccountPages) RegisterAdminUsers(mux *http.ServeMux, s AccountAdmin) {
|
||||
}))
|
||||
}
|
||||
|
||||
// roleNotice says what a person may now do in an organization.
|
||||
func roleNotice(role, org string) notice {
|
||||
switch role {
|
||||
case store.RoleManager:
|
||||
return say("users.msg.now_manages", org)
|
||||
case store.RoleOrgAdmin:
|
||||
return say("users.msg.now_administers", org)
|
||||
}
|
||||
return say("users.msg.no_longer_manages", org)
|
||||
}
|
||||
|
||||
// notice is what the page says about a change, kept as a catalogue key and
|
||||
// its arguments rather than as text: the log and the audit record take it in
|
||||
// English, which is what they are searched in, and the page in the language
|
||||
@@ -394,7 +405,7 @@ func init() {
|
||||
registerKeys(
|
||||
"users.msg.approved_alone", "users.msg.approved_into", "users.msg.suspended",
|
||||
"users.msg.reinstated", "users.msg.added_to", "users.msg.now_manages",
|
||||
"users.msg.no_longer_manages", "users.msg.removed_from", "users.msg.removed_from_one_key",
|
||||
"users.msg.no_longer_manages", "users.msg.now_administers", "users.msg.removed_from", "users.msg.removed_from_one_key",
|
||||
"users.msg.removed_from_keys", "users.msg.removed_keys_revoked", "users.msg.org_created",
|
||||
"users.msg.team_created", "users.msg.project_created", "users.msg.renamed",
|
||||
"users.msg.team_moved", "users.msg.project_moved", "users.msg.removed",
|
||||
@@ -408,6 +419,8 @@ func init() {
|
||||
// state, which is also the row's class.
|
||||
"users.state.active", "users.state.pending", "users.state.suspended",
|
||||
"users.key_state.active", "users.key_state.revoked", "users.key_state.expired",
|
||||
// A membership's role, looked up by the role.
|
||||
"users.role.member", "users.role.manager", "users.role.admin",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -573,6 +586,7 @@ func (p *AccountPages) buildUsers(r *http.Request, s AccountAdmin, admin store.U
|
||||
Members: map[string][]userRow{},
|
||||
Keys: map[string][]keyRow{},
|
||||
}
|
||||
d.Edit = d.Nav.May("/admin/users")
|
||||
var err error
|
||||
// logErr logs what could not be read in English and says so on the page,
|
||||
// once, in the reader's language.
|
||||
|
||||
Reference in new issue
Block a user