2023-07-29 02:25:56 +00:00
|
|
|
-- Test company_user
|
|
|
|
set client_min_messages to warning;
|
|
|
|
create extension if not exists pgtap;
|
|
|
|
reset client_min_messages;
|
|
|
|
|
|
|
|
begin;
|
|
|
|
|
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 00:22:16 +00:00
|
|
|
select plan(23);
|
2023-07-29 02:25:56 +00:00
|
|
|
|
|
|
|
set search_path to camper, public;
|
|
|
|
|
|
|
|
select has_table('company_user');
|
|
|
|
select has_pk('company_user' );
|
|
|
|
select col_is_pk('company_user', array['company_id', 'user_id']);
|
|
|
|
select table_privs_are('company_user', 'guest', array []::text[]);
|
|
|
|
select table_privs_are('company_user', 'employee', array ['SELECT']);
|
|
|
|
select table_privs_are('company_user', 'admin', array ['SELECT']);
|
|
|
|
select table_privs_are('company_user', 'authenticator', array []::text[]);
|
|
|
|
|
|
|
|
select has_column('company_user', 'company_id');
|
|
|
|
select col_is_fk('company_user', 'company_id');
|
|
|
|
select fk_ok('company_user', 'company_id', 'company', 'company_id');
|
|
|
|
select col_type_is('company_user', 'company_id', 'integer');
|
|
|
|
select col_not_null('company_user', 'company_id');
|
|
|
|
select col_hasnt_default('company_user', 'company_id');
|
|
|
|
|
|
|
|
select has_column('company_user', 'user_id');
|
|
|
|
select col_is_fk('company_user', 'user_id');
|
|
|
|
select fk_ok('company_user', 'user_id', 'user', 'user_id');
|
|
|
|
select col_type_is('company_user', 'user_id', 'integer');
|
|
|
|
select col_not_null('company_user', 'user_id');
|
|
|
|
select col_hasnt_default('company_user', 'user_id');
|
|
|
|
|
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 00:22:16 +00:00
|
|
|
select has_column('company_user', 'role');
|
|
|
|
select col_type_is('company_user', 'role', 'name');
|
|
|
|
select col_not_null('company_user', 'role');
|
|
|
|
select col_hasnt_default('company_user', 'role');
|
|
|
|
|
|
|
|
|
2023-07-29 02:25:56 +00:00
|
|
|
|
|
|
|
select *
|
|
|
|
from finish();
|
|
|
|
|
|
|
|
rollback;
|
|
|
|
|