[Formed-commits] r337 - in trunk: . formed/formed/plugins/export

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Jun 18 14:15:50 CEST 2009


Author: torsten
Date: 2009-06-18 14:15:49 +0200 (Thu, 18 Jun 2009)
New Revision: 337

Modified:
   trunk/ChangeLog
   trunk/formed/formed/plugins/export/new_sql.py
   trunk/formed/formed/plugins/export/rg_sql.py
Log:
Fixes of permission in SQL


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2009-06-18 07:00:01 UTC (rev 336)
+++ trunk/ChangeLog	2009-06-18 12:15:49 UTC (rev 337)
@@ -1,5 +1,11 @@
 2009-06-18	Torsten Irländer <torsten.irlaender at intevation.de>
 
+	* formed/formed/plugins/export/new_sql.py,
+	  formed/formed/plugins/export/rg_sql.py: Fixed some sql errors, and
+	  added permissions.
+
+2009-06-18	Torsten Irländer <torsten.irlaender at intevation.de>
+
 	* formed/formed/plugins/export/new_sql.py: Commented out generation of
 	page_views, as they do not work with rgroups.
 

Modified: trunk/formed/formed/plugins/export/new_sql.py
===================================================================
--- trunk/formed/formed/plugins/export/new_sql.py	2009-06-18 07:00:01 UTC (rev 336)
+++ trunk/formed/formed/plugins/export/new_sql.py	2009-06-18 12:15:49 UTC (rev 337)
@@ -539,7 +539,7 @@
             table.appendColumn(Column("%s_id" % removeTbl(parent.name), "INTEGER NOT NULL", False))
             table.appendColumn(Column("uuid_id", "CHAR(36)", False))
             table.appendConstraint(
-                "FOREIGN KEY (%s_id) REFERENCES %s (id)" % (
+                "FOREIGN KEY (%s_id) REFERENCES %s (id) ON DELETE CASCADE" % (
                     removeTbl(parent.name), parent.name))
             table.appendConstraint("UNIQUE (uuid_id)")
             table.addDependency(parent.name)

Modified: trunk/formed/formed/plugins/export/rg_sql.py
===================================================================
--- trunk/formed/formed/plugins/export/rg_sql.py	2009-06-18 07:00:01 UTC (rev 336)
+++ trunk/formed/formed/plugins/export/rg_sql.py	2009-06-18 12:15:49 UTC (rev 337)
@@ -58,13 +58,14 @@
 -- ------ end of static code -------
 
 -- PLPython is an untrusted language. -> Need to be postgres.
+SET ROLE postgres;
 
 -- DROP FUNCTION get_case_structure(int4);
 CREATE OR REPLACE FUNCTION get_case_structure(case_id int4) RETURNS TEXT AS $$$$
 
 class Node(object):
 
-    def __init__(self, name, id = None, children = None):
+    def __init__(self, name, id = None, children = []):
         self.name     = name
         self.id       = id
         self.children = children
@@ -92,7 +93,7 @@
                 child.recursive_build(id, sub_children)
             children.append(node)
 
-TREE_STRUCTURE = \    
+TREE_STRUCTURE = \
 $TREE_STRUCTURE
 
 r = plpy.execute(
@@ -118,8 +119,12 @@
 
 return r['cache']
 
-$$$$ LANGUAGE plpythonu;
+$$$$ LANGUAGE plpythonu EXTERNAL SECURITY DEFINER;
 
+-- Continue as db-owner from here
+ALTER FUNCTION get_case_structure(int4) OWNER TO :adm_ka_owner;
+SET ROLE :adm_ka_owner;
+
 --
 -- These triggers are used to keep case_structure table in sync.
 -- Each time a repeat group is created or deleted the case_structure
@@ -135,44 +140,44 @@
 
 TRIGGER_TMPL = Template(
 '''
--- DROP TRIGGER ${RELATION}_insert_trigger ON master_tbl CASCADE;
+-- DROP TRIGGER ${RELATION}_insert_trigger ON ${RELATION} CASCADE;
 -- DROP FUNCTION ${RELATION}_insert_func();
--- DROP TRIGGER ${RELATION}_delete_trigger ON master_tbl CASCADE;
+-- DROP TRIGGER ${RELATION}_delete_trigger ON ${RELATION} CASCADE;
 -- DROP FUNCTION ${RELATION}_delete_func();
 
 CREATE OR REPLACE FUNCTION ${RELATION}_insert_func() RETURNS TRIGGER AS $$$$
 BEGIN
     UPDATE case_structure SET modified = true WHERE master_id
-    ${SUBSELECT_INSERT}
+    ${SUBSELECT_INSERT};
     RETURN NEW;
 END;
 $$$$ LANGUAGE plpgsql;
 
-CREATE TRIGGER ${RELATION}_insert_trigger AFTER INSERT ON rg1_rg
+CREATE TRIGGER ${RELATION}_insert_trigger AFTER INSERT ON ${RELATION}
     FOR EACH ROW EXECUTE PROCEDURE ${RELATION}_insert_func();
 
 CREATE OR REPLACE FUNCTION ${RELATION}_delete_func() RETURNS TRIGGER AS $$$$
 BEGIN
     UPDATE case_structure SET modified = true WHERE master_id
-    ${SUBSELECT_DELETE}
+    ${SUBSELECT_DELETE};
     RETURN OLD;
 END;
 $$$$ LANGUAGE plpgsql;
 
-CREATE TRIGGER ${RELATION}_delete_trigger AFTER DELETE ON rg1_rg
+CREATE TRIGGER ${RELATION}_delete_trigger BEFORE DELETE ON ${RELATION}
     FOR EACH ROW EXECUTE PROCEDURE ${RELATION}_delete_func();
 ''')
 
 SUBSELECT_TMPL = Template(
 '''IN (
-        SELECT master_tbl.id FROM $RELATION 
+        SELECT master_tbl.id FROM $RELATION
         $INNER_JOINS
         WHERE $RELATION.id = $NEW_OLD.id
     )''')
 
 CREATE_DELETE_TMPL = Template(
 '''
-CREATE OR REPLACE FUNCTION create_${RELATION}(pid integer, nuuid char(36)) 
+CREATE OR REPLACE FUNCTION create_${RELATION}(pid integer, nuuid char(36))
 RETURNS integer
 LANGUAGE 'plpgsql' VOLATILE EXTERNAL SECURITY DEFINER AS
 $$$$
@@ -191,8 +196,8 @@
     SELECT INTO rid currval('${RELATION}_id_seq');
 
     IF nuuid IS NOT NULL THEN
-        UPDATE ${RELATION} 
-        SET    uuid_id = nuuid 
+        UPDATE ${RELATION}
+        SET    uuid_id = nuuid
         WHERE  id = rid;
     ELSE
         PERFORM set_uuid('${RELATION}', rid);
@@ -203,7 +208,7 @@
 END;
 $$$$;
 
-CREATE OR REPLACE FUNCTION delete_${RELATION}(rid integer) 
+CREATE OR REPLACE FUNCTION delete_${RELATION}(rid integer)
 RETURNS void
 LANGUAGE 'plpgsql' VOLATILE EXTERNAL SECURITY DEFINER AS
 $$$$
@@ -222,9 +227,9 @@
 ''')
 
 CREATE_DELETE_MASTER_TMPL = Template('''
-CREATE OR REPLACE FUNCTION create_master_tbl(nuuid char(36)) 
+CREATE OR REPLACE FUNCTION create_master_tbl(nuuid char(36))
     RETURNS integer
-    LANGUAGE 'plpgsql' VOLATILE EXTERNAL SECURITY DEFINER AS 
+    LANGUAGE 'plpgsql' VOLATILE EXTERNAL SECURITY DEFINER AS
 $$$$
 DECLARE
     standin integer;
@@ -233,9 +238,9 @@
     INSERT INTO master_tbl (bearbeiter_id) VALUES (getuserid());
     SELECT INTO standin vertreter from ka_benutzer_tbl WHERE id = getuserid();
 
-    SELECT INTO rid currval('master_tbl_id_seq'); 
+    SELECT INTO rid currval('master_tbl_id_seq');
 
-    IF standin IS NOT NULL THEN 
+    IF standin IS NOT NULL THEN
         INSERT INTO nm_benutzer_master_tbl(benutzer_id, master_id) VALUES (standin, rid);
     END IF;
 
@@ -252,7 +257,11 @@
 END;
 $$$$;
 
-CREATE OR REPLACE FUNCTION delete_master_tbl(mid integer) RETURNS void 
+REVOKE ALL ON FUNCTION create_master_tbl(char(36)) FROM PUBLIC;
+GRANT EXECUTE ON FUNCTION create_master_tbl(char(36))
+    TO GROUP :cm_group;
+
+CREATE OR REPLACE FUNCTION delete_master_tbl(mid integer) RETURNS void
     LANGUAGE 'plpgsql' VOLATILE EXTERNAL SECURITY DEFINER
     AS $$$$
 DECLARE
@@ -268,6 +277,10 @@
     DELETE FROM master_tbl WHERE id = mid;
 END;
 $$$$;
+
+REVOKE ALL ON FUNCTION delete_master_tbl(integer) FROM PUBLIC;
+GRANT EXECUTE ON FUNCTION delete_master_tbl(integer)
+    TO GROUP :admin_group;
 ''')
 
 class RGNode(object):
@@ -366,12 +379,12 @@
                 "SUBSELECT_INSERT": SUBSELECT_TMPL.safe_substitute({
                     "RELATION"   : self.name,
                     "INNER_JOINS": inner_joins,
-                    "NEW_OLD"    : "NEW" 
+                    "NEW_OLD"    : "NEW"
                 }),
                 "SUBSELECT_DELETE": SUBSELECT_TMPL.safe_substitute({
                     "RELATION"   : self.name,
                     "INNER_JOINS": inner_joins,
-                    "NEW_OLD"    : "OLD" 
+                    "NEW_OLD"    : "OLD"
                 })
             }))
         for child in self.children:



More information about the Formed-commits mailing list