comparison schema/auth_tests.sql @ 2230:4374d942b23d

Remove debris and associate templates to country While the original idea was to associate templates to users, managed by a waterway admin per country, the new intention was to share templates between users per country. Just removing any constraints on readability and management of the templates did not fulfill this idea.
author Tom Gottfried <tom@intevation.de>
date Wed, 13 Feb 2019 10:52:14 +0100
parents b66cfcde8ff7
children 5470aa3ffb9a
comparison
equal deleted inserted replaced
2229:6cce66a6ceb5 2230:4374d942b23d
34 SELECT is_empty($$ 34 SELECT is_empty($$
35 SELECT * FROM waterway.bottlenecks WHERE NOT staging_done 35 SELECT * FROM waterway.bottlenecks WHERE NOT staging_done
36 $$, 36 $$,
37 'Only staged data should be visible'); 37 'Only staged data should be visible');
38 38
39 --SELECT isnt_empty($$ 39 SELECT isnt_empty($$
40 -- SELECT * FROM users.templates 40 SELECT * FROM users.templates
41 -- $$, 41 $$,
42 -- 'User should see templates associated to him'); 42 'User should see templates associated to his country');
43 --SELECT is_empty($$ 43
44 -- SELECT * FROM users.templates 44 SELECT ok(
45 -- JOIN users.user_templates USING (template_name) 45 users.current_user_country() = ALL(
46 -- WHERE username <> current_user 46 SELECT country FROM users.templates),
47 -- $$, 47 'User should only see templates associated to his country');
48 -- 'User should only see templates associated to him');
49 48
50 -- 49 --
51 -- Run tests as waterway administrator 50 -- Run tests as waterway administrator
52 -- 51 --
53 SET SESSION AUTHORIZATION test_admin_at; 52 SET SESSION AUTHORIZATION test_admin_at;
77 $$, 76 $$,
78 42501, NULL, 77 42501, NULL,
79 'Waterway admin cannot insert data outside his region'); 78 'Waterway admin cannot insert data outside his region');
80 79
81 -- template management 80 -- template management
82 --SELECT isnt_empty($$ 81 SELECT results_eq($$
83 -- SELECT * FROM users.templates 82 SELECT users.current_user_country()
84 -- JOIN users.user_templates USING (template_name) 83 $$,
85 -- WHERE username <> current_user 84 $$
86 -- $$, 85 INSERT INTO users.templates (template_name, template_data)
87 -- 'Waterway admin should see templates of other users'); 86 VALUES ('New AT', '\x')
88 87 RETURNING country
89 --SELECT lives_ok($$ 88 $$,
90 -- INSERT INTO users.templates (template_name, template_data) 89 'Waterway admin can add templates for his country');
91 -- VALUES ('New AT', '\x'); 90
92 -- INSERT INTO users.user_templates 91 SELECT throws_ok($$
93 -- VALUES ('test_user_at', 'New AT') 92 INSERT INTO users.templates (template_name, template_data, country)
94 -- $$, 93 VALUES ('New RO', '\x', 'RO')
95 -- 'Waterway admin can add templates for users in his country'); 94 $$,
96 95 42501, NULL,
97 --SELECT throws_ok($$ 96 'Waterway admin cannot add template for other country');
98 -- INSERT INTO users.user_templates VALUES ('waterway_user2', 'AT')
99 -- $$,
100 -- 42501, NULL,
101 -- 'Waterway admin cannot add template for other country');
102 97
103 SELECT isnt_empty($$ 98 SELECT isnt_empty($$
104 UPDATE users.templates SET template_data = '\xDABE' 99 UPDATE users.templates SET template_data = '\xDABE'
105 WHERE template_name = 'AT' RETURNING * 100 WHERE template_name = 'AT' RETURNING *
106 $$, 101 $$,