basyx commited on
Commit
883f3bb
·
1 Parent(s): 0cf9d61

Fix collaboration RLS for dedicated schema (#9)

Browse files

- Fix collaboration RLS for dedicated schema (abfa4027aa9e685145c4d3b9fc286b4198af2470)

app/projects/migrations/0010_collaboration_foundation.sql CHANGED
@@ -94,20 +94,35 @@ create index ix_approval_requests_workflow_id on approval_requests(workflow_id);
94
  create index ix_review_comments_request_id on review_comments(request_id);
95
  create index ix_collaboration_activity_workspace_id on collaboration_activity(workspace_id);
96
 
97
- -- RLS
98
  do $$
99
  declare
100
  table_name text;
 
101
  begin
102
- for table_name in select t.table_name
103
- from information_schema.tables t
104
- where t.table_schema = 'public'
105
- and t.table_name in ('teams', 'team_members', 'invitations', 'project_collaborators', 'approval_workflows', 'approval_requests', 'review_comments', 'collaboration_activity')
 
 
 
 
 
 
 
 
 
 
106
  loop
107
- execute format('alter table %I enable row level security', table_name);
108
- execute format('alter table %I force row level security', table_name);
109
- execute format('drop policy if exists collaboration_workspace_isolation on %I', table_name);
110
- execute format('create policy collaboration_workspace_isolation on %I using (workspace_id = current_setting(''app.workspace_id'', true)) with check (workspace_id = current_setting(''app.workspace_id'', true))', table_name);
 
 
 
 
111
  end loop;
112
  end $$;
113
 
 
94
  create index ix_review_comments_request_id on review_comments(request_id);
95
  create index ix_collaboration_activity_workspace_id on collaboration_activity(workspace_id);
96
 
97
+ -- RLS: discover and alter only tables in the active dedicated schema.
98
  do $$
99
  declare
100
  table_name text;
101
+ schema_name text := current_schema();
102
  begin
103
+ for table_name in
104
+ select t.table_name
105
+ from information_schema.tables t
106
+ where t.table_schema = schema_name
107
+ and t.table_name in (
108
+ 'teams',
109
+ 'team_members',
110
+ 'invitations',
111
+ 'project_collaborators',
112
+ 'approval_workflows',
113
+ 'approval_requests',
114
+ 'review_comments',
115
+ 'collaboration_activity'
116
+ )
117
  loop
118
+ execute format('alter table %I.%I enable row level security', schema_name, table_name);
119
+ execute format('alter table %I.%I force row level security', schema_name, table_name);
120
+ execute format('drop policy if exists collaboration_workspace_isolation on %I.%I', schema_name, table_name);
121
+ execute format(
122
+ 'create policy collaboration_workspace_isolation on %I.%I using (workspace_id = current_setting(''app.workspace_id'', true)) with check (workspace_id = current_setting(''app.workspace_id'', true))',
123
+ schema_name,
124
+ table_name
125
+ );
126
  end loop;
127
  end $$;
128