Changeset 0.28.0 (#172)
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
-- ==========================================
|
||||
-- Chat Switchboard — 002 Teams & Access Control
|
||||
-- ==========================================
|
||||
-- Teams, team membership, groups (ACLs), and group membership.
|
||||
-- ICD §15 (Teams & Access Control)
|
||||
-- Teams, team membership, groups (with permissions, budgets, source),
|
||||
-- group membership, Everyone group seed.
|
||||
-- Consolidated v0.28.0: merges 002 + 019 (source) + 020 (permissions).
|
||||
-- ==========================================
|
||||
|
||||
-- =========================================
|
||||
@@ -42,9 +43,8 @@ CREATE INDEX IF NOT EXISTS idx_team_members_user ON team_members(user_id);
|
||||
|
||||
|
||||
-- =========================================
|
||||
-- GROUPS (ACLs)
|
||||
-- GROUPS (ACLs + Permissions)
|
||||
-- =========================================
|
||||
-- Pure access-control lists. Decouple resource visibility from team membership.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS groups (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
@@ -53,7 +53,16 @@ CREATE TABLE IF NOT EXISTS groups (
|
||||
scope VARCHAR(20) NOT NULL DEFAULT 'global'
|
||||
CHECK (scope IN ('global', 'team')),
|
||||
team_id UUID REFERENCES teams(id) ON DELETE CASCADE,
|
||||
created_by UUID NOT NULL REFERENCES users(id),
|
||||
created_by UUID REFERENCES users(id), -- nullable for system-seeded
|
||||
source VARCHAR(20) NOT NULL DEFAULT 'manual'
|
||||
CHECK (source IN ('manual', 'oidc', 'system')),
|
||||
|
||||
-- Fine-grained permissions (v0.24.2)
|
||||
permissions JSONB NOT NULL DEFAULT '[]'::jsonb,
|
||||
token_budget_daily BIGINT,
|
||||
token_budget_monthly BIGINT,
|
||||
allowed_models JSONB,
|
||||
|
||||
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
|
||||
@@ -70,8 +79,13 @@ DROP TRIGGER IF EXISTS groups_updated_at ON groups;
|
||||
CREATE TRIGGER groups_updated_at BEFORE UPDATE ON groups
|
||||
FOR EACH ROW EXECUTE FUNCTION update_updated_at();
|
||||
|
||||
COMMENT ON TABLE groups IS 'Access-control groups. Decouple resource visibility from team membership.';
|
||||
COMMENT ON COLUMN groups.scope IS 'global: admin-managed, can span teams. team: team-admin-managed, team-internal.';
|
||||
COMMENT ON TABLE groups IS 'Access-control groups with permission grants. Decouple resource visibility from team membership.';
|
||||
COMMENT ON COLUMN groups.scope IS 'global: admin-managed. team: team-admin-managed.';
|
||||
COMMENT ON COLUMN groups.source IS 'manual=admin-created, oidc=synced from IdP, system=platform-seeded';
|
||||
COMMENT ON COLUMN groups.permissions IS 'Array of permission strings granted to group members';
|
||||
COMMENT ON COLUMN groups.token_budget_daily IS 'Daily token ceiling for members (NULL = unlimited)';
|
||||
COMMENT ON COLUMN groups.token_budget_monthly IS 'Monthly token ceiling for members (NULL = unlimited)';
|
||||
COMMENT ON COLUMN groups.allowed_models IS 'Array of model_id strings this group may use. NULL = unrestricted.';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS group_members (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
@@ -84,3 +98,16 @@ CREATE TABLE IF NOT EXISTS group_members (
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_group_members_group ON group_members(group_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_group_members_user ON group_members(user_id);
|
||||
|
||||
-- Seed the Everyone group with a stable well-known ID.
|
||||
INSERT INTO groups (id, name, description, scope, created_by, source, permissions)
|
||||
VALUES (
|
||||
'00000000-0000-0000-0000-000000000001',
|
||||
'Everyone',
|
||||
'Implicit group — all authenticated users receive these permissions.',
|
||||
'global',
|
||||
NULL,
|
||||
'system',
|
||||
'["model.use","kb.read","channel.create"]'::jsonb
|
||||
)
|
||||
ON CONFLICT (id) DO NOTHING;
|
||||
|
||||
Reference in New Issue
Block a user