Made accounts and their transaction accessible to account members only.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
CREATE TABLE account_members (
|
||||
id UUID DEFAULT gen_random_uuid (),
|
||||
account_id UUID NOT NULL CONSTRAINT fk_account_members_account REFERENCES accounts (id),
|
||||
account_id UUID NOT NULL CONSTRAINT fk_account_members_account REFERENCES accounts (id) ON DELETE CASCADE,
|
||||
user_id UUID NOT NULL CONSTRAINT fk_account_members_user REFERENCES users (id),
|
||||
PRIMARY KEY (id, account_id),
|
||||
CONSTRAINT uq_account_members_account_user UNIQUE (account_id, user_id)
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
CREATE FUNCTION accessible_accounts (p_user_id UUID) RETURNS SETOF accounts LANGUAGE sql STABLE AS $$
|
||||
SELECT accounts.*
|
||||
FROM accounts
|
||||
WHERE EXISTS (
|
||||
SELECT 1
|
||||
FROM account_members
|
||||
WHERE account_members.account_id = accounts.id
|
||||
AND account_members.user_id = p_user_id
|
||||
)
|
||||
$$;
|
||||
Reference in New Issue
Block a user