Skip to content

Commit

Permalink
fix: improve security - apply security invoker to views
Browse files Browse the repository at this point in the history
  • Loading branch information
michalstruck committed May 30, 2024
1 parent 405ae78 commit 5c1b550
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions supabase/migrations/20240530101557_view_security_improvements.sql
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;

0 comments on commit 5c1b550

Please sign in to comment.