Implement complete Organizations feature with RBAC

- Add owner/admin/member roles with proper permissions
- Implement invite links and join requests system
- Add organization settings dialog with member management
- Create database migrations for invitations and invite links
- Update backend API with org management endpoints
- Fix compilation errors and audit logging
- Update frontend models and API integration
This commit is contained in:
Leon Bösche
2026-01-23 23:21:23 +01:00
parent a03b0dfe33
commit 20bc0ac757
15 changed files with 1461 additions and 42 deletions

View File

@@ -0,0 +1,29 @@
-- Add invitations and join_requests tables for organization management
CREATE TABLE invitations (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
org_id UUID NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
invited_by UUID NOT NULL REFERENCES users(id),
username TEXT NOT NULL, -- username of the invited user
role TEXT NOT NULL CHECK (role IN ('owner', 'admin', 'member')),
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
expires_at TIMESTAMP WITH TIME ZONE DEFAULT (NOW() + INTERVAL '7 days'),
accepted_at TIMESTAMP WITH TIME ZONE,
UNIQUE(org_id, username) -- prevent duplicate invites for same user in org
);
CREATE TABLE join_requests (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
org_id UUID NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
user_id UUID NOT NULL REFERENCES users(id),
invite_token TEXT, -- optional, if from invite link
requested_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'accepted', 'rejected')),
UNIQUE(org_id, user_id) -- prevent duplicate requests
);
-- Index for faster lookups
CREATE INDEX idx_invitations_org_id ON invitations(org_id);
CREATE INDEX idx_invitations_username ON invitations(username);
CREATE INDEX idx_join_requests_org_id ON join_requests(org_id);
CREATE INDEX idx_join_requests_user_id ON join_requests(user_id);

View File

@@ -0,0 +1,4 @@
-- Add invite_link_token to organizations for shareable invite links
ALTER TABLE organizations ADD COLUMN invite_link_token TEXT UNIQUE;
CREATE INDEX idx_organizations_invite_link_token ON organizations(invite_link_token);

View File

@@ -31,20 +31,28 @@ run_migration() {
}
# Run migrations in order
echo "Step 1/4: Initial schema..."
echo "Step 1/6: Initial schema..."
run_migration "$SCRIPT_DIR/0001_initial.sql"
echo
echo "Step 2/4: Passkeys and authentication..."
echo "Step 2/6: Passkeys and authentication..."
run_migration "$SCRIPT_DIR/0002_passkeys.sql"
echo
echo "Step 3/4: Files and storage..."
echo "Step 3/6: Files and storage..."
run_migration "$SCRIPT_DIR/0003_files.sql"
echo
echo "Step 4/4: Organization ownership and slug scope..."
echo "Step 4/6: Organization ownership and slug scope..."
run_migration "$SCRIPT_DIR/0004_org_owner_slug.sql"
echo
echo "Step 5/6: Organization invitations and join requests..."
run_migration "$SCRIPT_DIR/0005_org_invitations.sql"
echo
echo "Step 6/6: Organization invite links..."
run_migration "$SCRIPT_DIR/0006_org_invite_link.sql"
echo
echo "=== All migrations completed successfully! ==="