Mercurial > gemma
comparison schema/auth_tests.sql @ 4740:2440d2f86f4e
Authorize sections based on country of creator
Disregarding the area of resposibility will allow to create sections
outside of the country of the user in order to allow data analysis
and aggregation based on sections spanning over multiple countries.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Fri, 18 Oct 2019 12:04:04 +0200 |
parents | 5466562cca60 |
children | dfd990a4ac64 |
comparison
equal
deleted
inserted
replaced
4739:257dd6039a28 | 4740:2440d2f86f4e |
---|---|
12 -- * Tom Gottfried <tom@intevation.de> | 12 -- * Tom Gottfried <tom@intevation.de> |
13 | 13 |
14 -- | 14 -- |
15 -- pgTAP test script for privileges and RLS policies | 15 -- pgTAP test script for privileges and RLS policies |
16 -- | 16 -- |
17 | |
18 -- Helper function: | |
19 CREATE OR REPLACE FUNCTION users.current_user_country() | |
20 RETURNS internal.user_profiles.country%TYPE | |
21 AS $$ | |
22 SELECT country FROM users.list_users | |
23 WHERE username = current_user | |
24 $$ | |
25 LANGUAGE SQL | |
26 STABLE PARALLEL SAFE; | |
27 | |
28 | 17 |
29 CREATE FUNCTION test_privs() RETURNS SETOF TEXT AS | 18 CREATE FUNCTION test_privs() RETURNS SETOF TEXT AS |
30 $$ | 19 $$ |
31 DECLARE the_schema CONSTANT varchar = 'waterway'; | 20 DECLARE the_schema CONSTANT varchar = 'waterway'; |
32 DECLARE the_table varchar; | 21 DECLARE the_table varchar; |
73 SELECT * FROM users.templates | 62 SELECT * FROM users.templates |
74 $$, | 63 $$, |
75 'User should see templates associated to his country'); | 64 'User should see templates associated to his country'); |
76 | 65 |
77 SELECT ok( | 66 SELECT ok( |
78 users.current_user_country() = ALL( | 67 users.user_country() = ALL( |
79 SELECT country FROM users.templates), | 68 SELECT country FROM users.templates), |
80 'User should only see templates associated to his country'); | 69 'User should only see templates associated to his country'); |
81 | 70 |
82 -- | 71 -- |
83 -- Run tests as waterway administrator | 72 -- Run tests as waterway administrator |