-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from recogito/lwj/fcc-documents
Collections and extensions
- Loading branch information
Showing
35 changed files
with
6,424 additions
and
507 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
es2021: true, | ||
}, | ||
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'], | ||
overrides: [ | ||
{ | ||
env: { | ||
node: true, | ||
}, | ||
files: ['.eslintrc.{js,cjs}'], | ||
parserOptions: { | ||
sourceType: 'script', | ||
}, | ||
}, | ||
], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
}, | ||
plugins: ['@typescript-eslint'], | ||
rules: { | ||
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }], | ||
'no-explicit-any': false, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ node_modules | |
.DS_Store | ||
priivate-scripts | ||
hold | ||
./supabase/functions/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
CREATE | ||
OR REPLACE FUNCTION PUBLIC.UPDATE_DOCUMENT () RETURNS TRIGGER LANGUAGE PLPGSQL SECURITY DEFINER AS $$ | ||
BEGIN | ||
NEW.updated_at = NOW(); | ||
NEW.updated_by = auth.uid(); | ||
-- These should never change -- | ||
NEW.created_at = OLD.created_at; | ||
NEW.created_by = OLD.created_by; | ||
IF NEW.is_private = TRUE AND auth.uid() != OLD.created_by THEN | ||
NEW.is_private = FALSE; | ||
END IF; | ||
RETURN NEW; | ||
END; | ||
$$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
DO $$ | ||
DECLARE | ||
t_row_project public.PROJECT_GROUPS % rowtype; | ||
t_row_layer public.LAYER_GROUPS % rowtype; | ||
BEGIN | ||
|
||
FOR t_row_project IN SELECT * FROM public.PROJECT_GROUPS LOOP | ||
IF t_row_project.name = 'Project Admins' THEN | ||
UPDATE public.PROJECT_GROUPS SET is_admin = TRUE WHERE id = t_row_project.id; | ||
ELSIF t_row_project.name = 'Project Students' THEN | ||
UPDATE public.PROJECT_GROUPS SET is_default = TRUE WHERE id = t_row_project.id; | ||
END IF; | ||
END LOOP; | ||
FOR t_row_layer IN SELECT * FROM public.LAYER_GROUPS LOOP | ||
IF t_row_layer.name = 'Layer Admin' THEN | ||
UPDATE public.LAYER_GROUPS SET is_admin = TRUE WHERE id = t_row_layer.id; | ||
ELSIF t_row_layer.name = 'Layer Student' THEN | ||
UPDATE public.LAYER_GROUPS SET is_default = TRUE WHERE id = t_row_layer.id; | ||
END IF; | ||
END LOOP; | ||
END | ||
$$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
DO $$ | ||
DECLARE | ||
t_row public.layers % rowtype; | ||
BEGIN | ||
FOR t_row IN SELECT * FROM public.layers LOOP | ||
IF NOT EXISTS( | ||
SELECT 1 | ||
FROM public.project_documents | ||
WHERE project_id = t_row.project_id | ||
AND document_id = t_row.document_id | ||
) THEN | ||
INSERT INTO public.project_documents (project_id, document_id) | ||
VALUES ( | ||
t_row.project_id, | ||
t_row.document_id | ||
); | ||
END IF; | ||
END LOOP; | ||
END | ||
$$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
DROP POLICY IF EXISTS "Users with correct policies can SELECT on collections" ON public.collections; | ||
|
||
CREATE POLICY "Users with correct policies can SELECT on collections" ON public.collections FOR SELECT TO authenticated | ||
USING ( | ||
public.check_action_policy_organization(auth.uid(), 'collections', 'SELECT') | ||
); | ||
|
||
DROP POLICY IF EXISTS "Users with correct policies can INSERT on collections" ON public.collections; | ||
|
||
CREATE POLICY "Users with correct policies can INSERT on collections" ON public.collections FOR INSERT TO authenticated | ||
WITH CHECK (public.check_action_policy_organization(auth.uid(), 'collections', 'INSERT')); | ||
|
||
DROP POLICY IF EXISTS "Users with correct policies can UPDATE on collections" ON public.collections; | ||
|
||
CREATE POLICY "Users with correct policies can UPDATE on collections" ON public.collections FOR UPDATE TO authenticated | ||
USING ( | ||
public.check_action_policy_organization(auth.uid(), 'collections', 'UPDATE') | ||
) | ||
WITH CHECK (public.check_action_policy_organization(auth.uid(), 'collections', 'UPDATE')); | ||
|
||
DROP POLICY IF EXISTS "Users with correct policies can DELETE on collections" ON public.collections; | ||
|
||
CREATE POLICY "Users with correct policies can DELETE on collections" ON public.collections FOR DELETE TO authenticated | ||
USING (public.check_action_policy_organization(auth.uid(), 'collections', 'DELETE')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,90 @@ | ||
DROP POLICY IF EXISTS "Users with correct policies can SELECT on documents" ON public.documents; | ||
|
||
CREATE POLICY "Users with correct policies can SELECT on documents" ON public.documents FOR SELECT TO authenticated | ||
USING ( | ||
is_archived IS FALSE AND | ||
(public.check_action_policy_organization(auth.uid(), 'documents', 'SELECT') OR | ||
public.check_action_policy_project_from_document(auth.uid(), 'documents', 'SELECT', id) OR | ||
public.check_action_policy_layer_from_document(auth.uid(), 'documents', 'SELECT', id)) | ||
CREATE POLICY "Users with correct policies can SELECT on documents" ON public.documents FOR | ||
SELECT | ||
TO authenticated USING ( | ||
is_archived IS FALSE | ||
AND ( | ||
( | ||
is_private = FALSE | ||
OR created_by = auth.uid () | ||
) | ||
AND public.check_action_policy_organization (auth.uid (), 'documents', 'SELECT') | ||
OR public.check_action_policy_project_from_document (auth.uid (), 'documents', 'SELECT', id) | ||
OR public.check_action_policy_layer_from_document (auth.uid (), 'documents', 'SELECT', id) | ||
) | ||
); | ||
|
||
DROP POLICY IF EXISTS "Users with correct policies can INSERT on documents" ON public.documents; | ||
|
||
CREATE POLICY "Users with correct policies can INSERT on documents" ON public.documents FOR INSERT TO authenticated | ||
WITH CHECK ( | ||
public.check_action_policy_organization(auth.uid(), 'documents', 'INSERT') OR | ||
public.check_action_policy_project_from_document(auth.uid(), 'documents', 'INSERT', id) OR | ||
public.check_action_policy_layer_from_document(auth.uid(), 'documents', 'INSERT', id) | ||
WITH | ||
CHECK ( | ||
( | ||
( | ||
is_private = FALSE | ||
OR created_by = auth.uid () | ||
) | ||
AND (collection_id ISNULL) | ||
AND public.check_action_policy_organization (auth.uid (), 'documents', 'INSERT') | ||
) | ||
OR public.check_action_policy_project_from_document (auth.uid (), 'documents', 'INSERT', id) | ||
OR public.check_action_policy_layer_from_document (auth.uid (), 'documents', 'INSERT', id) | ||
); | ||
|
||
DROP POLICY IF EXISTS "Users with correct policies can UPDATE on documents" ON public.documents; | ||
|
||
CREATE POLICY "Users with correct policies can UPDATE on documents" ON public.documents FOR UPDATE TO authenticated | ||
USING ( | ||
public.check_action_policy_organization(auth.uid(), 'documents', 'UPDATE') OR | ||
public.check_action_policy_project_from_document(auth.uid(), 'documents', 'UPDATE', id) OR | ||
public.check_action_policy_layer_from_document(auth.uid(), 'documents', 'UPDATE', id) | ||
CREATE POLICY "Users with correct policies can UPDATE on documents" ON public.documents | ||
FOR UPDATE | ||
TO authenticated USING ( | ||
( | ||
( | ||
is_private = FALSE | ||
OR created_by = auth.uid () | ||
) | ||
AND (collection_id ISNULL) | ||
AND public.check_action_policy_organization (auth.uid (), 'documents', 'UPDATE') | ||
) | ||
OR ( | ||
( | ||
is_private = FALSE | ||
OR created_by = auth.uid () | ||
) | ||
AND (collection_id ISNULL) | ||
AND public.check_action_policy_project_from_document (auth.uid (), 'documents', 'UPDATE', id) | ||
) | ||
) | ||
WITH CHECK (public.check_action_policy_organization(auth.uid(), 'documents', 'UPDATE') OR | ||
public.check_action_policy_project_from_document(auth.uid(), 'documents', 'UPDATE', id) OR | ||
public.check_action_policy_layer_from_document(auth.uid(), 'documents', 'UPDATE', id) | ||
WITH | ||
CHECK ( | ||
( | ||
( | ||
is_private = FALSE | ||
OR created_by = auth.uid () | ||
) | ||
AND (collection_id ISNULL) | ||
AND public.check_action_policy_organization (auth.uid (), 'documents', 'UPDATE') | ||
) | ||
OR ( | ||
( | ||
is_private = FALSE | ||
OR created_by = auth.uid () | ||
) | ||
AND (collection_id ISNULL) | ||
AND public.check_action_policy_project_from_document (auth.uid (), 'documents', 'UPDATE', id) | ||
) | ||
); | ||
|
||
DROP POLICY IF EXISTS "Users with correct policies can DELETE on documents" ON public.documents; | ||
|
||
CREATE POLICY "Users with correct policies can DELETE on documents" ON public.documents FOR DELETE TO authenticated | ||
USING (public.check_action_policy_organization(auth.uid(), 'documents', 'DELETE') OR | ||
public.check_action_policy_project_from_document(auth.uid(), 'documents', 'DELETE', id) OR | ||
public.check_action_policy_layer_from_document(auth.uid(), 'documents', 'DELETE', id) | ||
); | ||
CREATE POLICY "Users with correct policies can DELETE on documents" ON public.documents FOR DELETE TO authenticated USING ( | ||
( | ||
( | ||
is_private = FALSE | ||
OR created_by = auth.uid () | ||
) | ||
AND (collection_id ISNULL) | ||
AND public.check_action_policy_organization (auth.uid (), 'documents', 'DELETE') | ||
) | ||
OR public.check_action_policy_project_from_document (auth.uid (), 'documents', 'DELETE', id) | ||
OR public.check_action_policy_layer_from_document (auth.uid (), 'documents', 'DELETE', id) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CREATE TABLE public.collections ( | ||
id uuid NOT NULL DEFAULT uuid_generate_v4 () PRIMARY KEY, | ||
created_at timestamp WITH TIME ZONE DEFAULT NOW(), | ||
created_by uuid REFERENCES public.profiles, | ||
updated_at timestamptz, | ||
updated_by uuid REFERENCES public.profiles, | ||
name varchar NOT NULL, | ||
extension_id uuid REFERENCES public.extensions, | ||
extension_metadata json | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-- extensions table -- | ||
CREATE TYPE activation_types AS ENUM('cron', 'direct_call'); | ||
|
||
CREATE TABLE public.extensions ( | ||
id uuid NOT NULL DEFAULT uuid_generate_v4 () PRIMARY KEY, | ||
created_at timestamp WITH TIME ZONE DEFAULT NOW(), | ||
created_by uuid REFERENCES public.profiles, | ||
updated_at timestamptz, | ||
updated_by uuid REFERENCES public.profiles, | ||
activation_type activation_types NOT NULL, | ||
metadata json | ||
); |
Oops, something went wrong.