campingmontagut/deploy/policies_company.sql
jordi fita mas 866af09b50 Move the user role down to company_user relation
I was starting to add the public page for campsite types, creating more
granular row-level security policies for select, insert, update, and
delete, because now the guest users needed to SELECT them and they have
no related company to filter the rows with.  Suddenly, i realized that
the role was wrong in the user relation: a user can be an admin to one
company, and employee to another, and guess to yet another company;
the role should be in the company_user relation instead.

That means that to know the role to set to, the user alone is not enough
and have to know the company as well.  Had to change all the
cookie-related function to accept also the company’s host name, as this
is the information that the Go application has.
2023-08-08 02:22:16 +02:00

26 lines
366 B
PL/PgSQL

-- Deploy camper:policies_company to pg
-- requires: company
-- requires: user_profile
begin;
set search_path to camper, public;
alter table company enable row level security;
create policy guest_ok
on company
for select
using (true)
;
create policy update_company
on company
for update
using (
company_id in (select company_id from user_profile)
)
;
commit;