-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve security - apply security invoker to views
- Loading branch information
1 parent
405ae78
commit 5c1b550
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
supabase/migrations/20240530101557_view_security_improvements.sql
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,44 @@ | ||
CREATE OR REPLACE VIEW "public"."worker_for_current_user" WITH ("security_invoker"='true') AS | ||
SELECT "worker"."id", | ||
"worker"."created_at", | ||
"worker"."name", | ||
"worker"."company_id", | ||
"worker"."is_admin", | ||
"worker"."email" | ||
FROM "public"."worker" | ||
WHERE ("worker"."id" = "auth"."uid"()) | ||
LIMIT 1; | ||
|
||
CREATE OR REPLACE VIEW "public"."current_company_id" WITH ("security_invoker"='true') AS | ||
SELECT "worker"."company_id" AS "id" | ||
FROM "public"."worker" | ||
WHERE ("worker"."id" = "auth"."uid"()); | ||
|
||
CREATE OR REPLACE VIEW public.existing_products WITH ("security_invoker"='true') AS | ||
SELECT * FROM public.product | ||
WHERE deleted_at IS NULL; | ||
|
||
CREATE OR REPLACE VIEW public.deleted_products WITH ("security_invoker"='true') AS | ||
SELECT * FROM public.product | ||
WHERE deleted_at IS NOT NULL; | ||
|
||
create view | ||
public.record_view with ("security_invoker"='true') as | ||
select | ||
product.name, | ||
product.unit, | ||
product.steps, | ||
product_record.price_per_unit, | ||
product_record.quantity, | ||
product_record.inventory_id, | ||
product_record.id, | ||
product_record.product_id, | ||
barcode.code as barcode, | ||
product_category.name as category_name, | ||
product_category.display_order as category_display_order, | ||
product.display_order | ||
from | ||
product_record | ||
left join product on product_record.product_id = product.id | ||
left join barcode on product_record.product_id = barcode.product_id | ||
left join product_category on product.category_id = product_category.id; |