feat(auth): add view as user and role functionality for owners
Allow owners to impersonate users or roles for debugging permissions. Add view-as targets to user sessions and resolve effective permissions. Display a persistent banner in the app shell to exit view-as mode.
This commit is contained in:
@@ -724,10 +724,21 @@ CREATE TABLE IF NOT EXISTS user_sessions (
|
||||
id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
user_id integer NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
token_hash text NOT NULL UNIQUE,
|
||||
view_as_user_id integer REFERENCES users(id) ON DELETE SET NULL,
|
||||
view_as_role_id integer REFERENCES roles(id) ON DELETE SET NULL,
|
||||
expires_at timestamptz NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT now()
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
CONSTRAINT user_sessions_view_as_single_target_check CHECK (view_as_user_id IS NULL OR view_as_role_id IS NULL)
|
||||
);
|
||||
|
||||
ALTER TABLE user_sessions
|
||||
ADD COLUMN IF NOT EXISTS view_as_user_id integer REFERENCES users(id) ON DELETE SET NULL,
|
||||
ADD COLUMN IF NOT EXISTS view_as_role_id integer REFERENCES roles(id) ON DELETE SET NULL;
|
||||
|
||||
ALTER TABLE user_sessions
|
||||
DROP CONSTRAINT IF EXISTS user_sessions_view_as_single_target_check,
|
||||
ADD CONSTRAINT user_sessions_view_as_single_target_check CHECK (view_as_user_id IS NULL OR view_as_role_id IS NULL);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS user_sessions_user_id_idx
|
||||
ON user_sessions(user_id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user