diff pkg/controllers/printtemplates.go @ 2267:37ae1bee3e4a

Ajjusted RLS for user templates.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 14 Feb 2019 15:11:00 +0100
parents e6fba449aa3c
children 1c8b8a4476af
line wrap: on
line diff
--- a/pkg/controllers/printtemplates.go	Thu Feb 14 14:47:33 2019 +0100
+++ b/pkg/controllers/printtemplates.go	Thu Feb 14 15:11:00 2019 +0100
@@ -47,8 +47,13 @@
 SELECT template_data FROM users.templates WHERE template_name = $1`
 
 	insertPrintTemplateSQL = `
-INSERT INTO users.templates (template_name, template_data)
-VALUES ($1, $2)`
+INSERT INTO users.templates (template_name, template_data, country)
+SELECT
+  $1,
+  $2,
+  CASE WHEN pg_has_role('sys_admin', 'MEMBER') THEN NULL
+       ELSE users.current_user_country()
+  END`
 
 	updatePrintTemplateSQL = `
 UPDATE user.templates template_data = $2 WHERE template_name = $1`