Skip to content

Commit ec216cc

Browse files
committed
harden exposed views
1 parent 233e231 commit ec216cc

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
create or replace view public.chat_threads_with_participants
2+
with (security_invoker = on) as
3+
select
4+
chat_threads.id,
5+
chat_threads.created_at,
6+
chat_threads.listing_id,
7+
chat_threads.initiator_id,
8+
chat_threads.owner_id,
9+
initiator.first_name as initiator_first_name,
10+
owner.first_name as owner_first_name,
11+
listings.slug as listing_slug,
12+
listings.avatar as listing_avatar,
13+
listings.name as listing_name,
14+
listings.type as listing_type,
15+
listings.area_name as listing_area_name,
16+
owner.avatar as owner_avatar,
17+
initiator.avatar as initiator_avatar,
18+
(
19+
select count(*) >= 2
20+
from public.listings as owner_listings
21+
where owner_listings.owner_id = chat_threads.owner_id
22+
and owner_listings.type in ('community', 'business')
23+
) as owner_has_multiple_non_residential_listings
24+
from public.chat_threads
25+
join public.profiles as initiator on chat_threads.initiator_id = initiator.id
26+
join public.profiles as owner on chat_threads.owner_id = owner.id
27+
join public.listings on chat_threads.listing_id = listings.id;
28+
29+
alter view public.chat_threads_with_participants owner to postgres;
30+
31+
revoke all on table public.chat_threads_with_participants
32+
from anon, authenticated, service_role;
33+
34+
grant select on table public.chat_threads_with_participants
35+
to authenticated, service_role;
36+
37+
alter view public.listings_public_data
38+
set (security_invoker = on);
39+
40+
alter view public.listings_private_data
41+
set (security_invoker = on);
42+
43+
revoke all on table public.listings_public_data
44+
from anon, authenticated, service_role;
45+
46+
revoke all on table public.listings_private_data
47+
from anon, authenticated, service_role;
48+
49+
grant select on table public.listings_public_data
50+
to anon, authenticated, service_role;
51+
52+
grant select on table public.listings_private_data
53+
to authenticated, service_role;

0 commit comments

Comments
 (0)