diff --git a/backend/migrations/20230131143413_more_folders_privilege.down.sql b/backend/migrations/20230131143413_more_folders_privilege.down.sql new file mode 100644 index 0000000000..d2f607c5b8 --- /dev/null +++ b/backend/migrations/20230131143413_more_folders_privilege.down.sql @@ -0,0 +1 @@ +-- Add down migration script here diff --git a/backend/migrations/20230131143413_more_folders_privilege.up.sql b/backend/migrations/20230131143413_more_folders_privilege.up.sql new file mode 100644 index 0000000000..2f2d22e70f --- /dev/null +++ b/backend/migrations/20230131143413_more_folders_privilege.up.sql @@ -0,0 +1,25 @@ +-- Add up migration script here + + +CREATE POLICY see_folder_extra_perms_user ON capture FOR ALL +USING (SPLIT_PART(capture.path, '/', 1) = 'f' AND SPLIT_PART(capture.path, '/', 2) = any(regexp_split_to_array(current_setting('session.folders_read'), ',')::text[])) +WITH CHECK (SPLIT_PART(capture.path, '/', 1) = 'f' AND SPLIT_PART(capture.path, '/', 2) = any(regexp_split_to_array(current_setting('session.folders_write'), ',')::text[])); + +DO +$do$ + DECLARE + i text; + arr text[] := array['queue', 'completed_job']; + BEGIN + FOREACH i IN ARRAY arr + LOOP + EXECUTE FORMAT( + $$ + CREATE POLICY see_folder_extra_perms_user ON %1$I FOR ALL + USING (%1$I.visible_to_owner IS true AND SPLIT_PART(%1$I.script_path, '/', 1) = 'f' AND SPLIT_PART(%1$I.script_path, '/', 2) = any(regexp_split_to_array(current_setting('session.folders_read'), ',')::text[])); + $$, + i + ); + END LOOP; + END +$do$; \ No newline at end of file diff --git a/backend/migrations/20230131145602_more_folders_privilege_2.down.sql b/backend/migrations/20230131145602_more_folders_privilege_2.down.sql new file mode 100644 index 0000000000..d2f607c5b8 --- /dev/null +++ b/backend/migrations/20230131145602_more_folders_privilege_2.down.sql @@ -0,0 +1 @@ +-- Add down migration script here diff --git a/backend/migrations/20230131145602_more_folders_privilege_2.up.sql b/backend/migrations/20230131145602_more_folders_privilege_2.up.sql new file mode 100644 index 0000000000..d3ab0e729f --- /dev/null +++ b/backend/migrations/20230131145602_more_folders_privilege_2.up.sql @@ -0,0 +1,5 @@ +-- Add up migration script here + +CREATE POLICY see_folder_extra_perms_user ON account FOR ALL +USING (SPLIT_PART(account.owner, '/', 1) = 'f' AND SPLIT_PART(account.owner, '/', 2) = any(regexp_split_to_array(current_setting('session.folders_read'), ',')::text[])) +WITH CHECK (SPLIT_PART(account.owner, '/', 1) = 'f' AND SPLIT_PART(account.owner, '/', 2) = any(regexp_split_to_array(current_setting('session.folders_write'), ',')::text[]));