changeset 2147:b66cfcde8ff7

Print templates: Stubbed endpoints under /api/templates/print/{name}
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 08 Feb 2019 11:02:05 +0100
parents 7267f8168176
children 4057a1f15174
files pkg/controllers/routes.go schema/auth.sql schema/auth_tests.sql schema/gemma.sql schema/tap_tests_data.sql
diffstat 5 files changed, 67 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/routes.go	Thu Feb 07 17:45:00 2019 +0100
+++ b/pkg/controllers/routes.go	Fri Feb 08 11:02:05 2019 +0100
@@ -95,6 +95,27 @@
 		NoConn: true,
 	}).Methods(http.MethodGet)
 
+	// Print templates
+	api.Handle("/templates/print", any(&JSONHandler{
+		Handle: listPrintTemplates,
+	})).Methods(http.MethodGet)
+
+	api.Handle("/templates/print/{name}", any(&JSONHandler{
+		Handle: fetchPrintTemplate,
+	})).Methods(http.MethodGet)
+
+	api.Handle("/templates/print/{name}", waterwayAdmin(&JSONHandler{
+		Handle: createPrintTemplate,
+	})).Methods(http.MethodPost)
+
+	api.Handle("/templates/print/{name}", waterwayAdmin(&JSONHandler{
+		Handle: deletePrintTemplate,
+	})).Methods(http.MethodDelete)
+
+	api.Handle("/templates/print/{name}", waterwayAdmin(&JSONHandler{
+		Handle: updatePrintTemplate,
+	})).Methods(http.MethodPatch)
+
 	// External proxies.
 	external := middleware.NotFound(&httputil.ReverseProxy{
 		Director:       proxyDirector(models.ExternalServices.Find),
--- a/schema/auth.sql	Thu Feb 07 17:45:00 2019 +0100
+++ b/schema/auth.sql	Fri Feb 08 11:02:05 2019 +0100
@@ -40,7 +40,8 @@
 -- imported data due to historicisation? Special tables like
 -- import_configuration will further need UPDATE and DELETE privileges.
 GRANT INSERT, UPDATE, DELETE ON
-    users.templates, users.user_templates TO waterway_admin;
+    users.templates TO waterway_admin;
+    -- users.templates, users.user_templates TO waterway_admin;
 
 GRANT USAGE ON SCHEMA import TO waterway_admin;
 GRANT SELECT, INSERT ON ALL TABLES IN SCHEMA import TO waterway_admin;
@@ -104,14 +105,14 @@
 $$;
 
 -- templates
-CREATE POLICY user_templates ON users.user_templates FOR ALL TO waterway_user
-    USING (username IN(SELECT username FROM users.list_users));
-ALTER TABLE users.user_templates ENABLE ROW LEVEL SECURITY;
+-- CREATE POLICY user_templates ON users.user_templates FOR ALL TO waterway_user
+--    USING (username IN(SELECT username FROM users.list_users));
+-- ALTER TABLE users.user_templates ENABLE ROW LEVEL SECURITY;
 
-CREATE POLICY user_templates ON users.templates FOR ALL TO waterway_user
-    USING (template_name IN(SELECT template_name FROM users.user_templates))
-    WITH CHECK (true);
-ALTER TABLE users.templates ENABLE ROW LEVEL SECURITY;
+-- CREATE POLICY user_templates ON users.templates FOR ALL TO waterway_user
+--     USING (template_name IN(SELECT template_name FROM users.user_templates))
+--     WITH CHECK (true);
+-- ALTER TABLE users.templates ENABLE ROW LEVEL SECURITY;
 
 --
 -- RLS policies for waterway_admin
--- a/schema/auth_tests.sql	Thu Feb 07 17:45:00 2019 +0100
+++ b/schema/auth_tests.sql	Fri Feb 08 11:02:05 2019 +0100
@@ -36,16 +36,16 @@
     $$,
     'Only staged data should be visible');
 
-SELECT isnt_empty($$
-    SELECT * FROM users.templates
-    $$,
-    'User should see templates associated to him');
-SELECT is_empty($$
-    SELECT * FROM users.templates
-        JOIN users.user_templates USING (template_name)
-        WHERE username <> current_user
-    $$,
-    'User should only see templates associated to him');
+--SELECT isnt_empty($$
+--    SELECT * FROM users.templates
+--    $$,
+--    'User should see templates associated to him');
+--SELECT is_empty($$
+--    SELECT * FROM users.templates
+--        JOIN users.user_templates USING (template_name)
+--        WHERE username <> current_user
+--    $$,
+--    'User should only see templates associated to him');
 
 --
 -- Run tests as waterway administrator
@@ -79,26 +79,26 @@
     'Waterway admin cannot insert data outside his region');
 
 -- template management
-SELECT isnt_empty($$
-    SELECT * FROM users.templates
-        JOIN users.user_templates USING (template_name)
-        WHERE username <> current_user
-    $$,
-    'Waterway admin should see templates of other users');
+--SELECT isnt_empty($$
+--    SELECT * FROM users.templates
+--        JOIN users.user_templates USING (template_name)
+--        WHERE username <> current_user
+--    $$,
+--    'Waterway admin should see templates of other users');
 
-SELECT lives_ok($$
-    INSERT INTO users.templates (template_name, template_data)
-        VALUES ('New AT', '\x');
-        INSERT INTO users.user_templates
-        VALUES ('test_user_at', 'New AT')
-    $$,
-    'Waterway admin can add templates for users in his country');
+--SELECT lives_ok($$
+--    INSERT INTO users.templates (template_name, template_data)
+--        VALUES ('New AT', '\x');
+--        INSERT INTO users.user_templates
+--        VALUES ('test_user_at', 'New AT')
+--    $$,
+--    'Waterway admin can add templates for users in his country');
 
-SELECT throws_ok($$
-    INSERT INTO users.user_templates VALUES ('waterway_user2', 'AT')
-    $$,
-    42501, NULL,
-    'Waterway admin cannot add template for other country');
+--SELECT throws_ok($$
+--    INSERT INTO users.user_templates VALUES ('waterway_user2', 'AT')
+--    $$,
+--    42501, NULL,
+--    'Waterway admin cannot add template for other country');
 
 SELECT isnt_empty($$
     UPDATE users.templates SET template_data = '\xDABE'
--- a/schema/gemma.sql	Thu Feb 07 17:45:00 2019 +0100
+++ b/schema/gemma.sql	Fri Feb 08 11:02:05 2019 +0100
@@ -188,13 +188,13 @@
     CREATE TRIGGER templates_date_info BEFORE UPDATE ON templates
         FOR EACH ROW EXECUTE PROCEDURE update_date_info()
 
-    CREATE TABLE user_templates (
-        username varchar NOT NULL
-            REFERENCES internal.user_profiles
-                ON DELETE CASCADE ON UPDATE CASCADE,
-        template_name varchar NOT NULL REFERENCES templates ON DELETE CASCADE,
-        PRIMARY KEY (username, template_name)
-    )
+    -- CREATE TABLE user_templates (
+    --    username varchar NOT NULL
+    --        REFERENCES internal.user_profiles
+    --            ON DELETE CASCADE ON UPDATE CASCADE,
+    --    template_name varchar NOT NULL REFERENCES templates ON DELETE CASCADE,
+    --    PRIMARY KEY (username, template_name)
+    --)
 ;
 ALTER TABLE internal.user_profiles ADD
     country char(2) NOT NULL REFERENCES users.responsibility_areas;
--- a/schema/tap_tests_data.sql	Thu Feb 07 17:45:00 2019 +0100
+++ b/schema/tap_tests_data.sql	Fri Feb 08 11:02:05 2019 +0100
@@ -90,8 +90,8 @@
 
 INSERT INTO users.templates (template_name, template_data)
     VALUES ('AT', '\x'), ('RO', '\x');
-INSERT INTO users.user_templates
-    VALUES ('test_user_at', 'AT'), ('test_user_ro', 'RO');
+--INSERT INTO users.user_templates
+--    VALUES ('test_user_at', 'AT'), ('test_user_ro', 'RO');
 
 WITH
 job AS (