Also grant 'ADMIN' role any priv when it's added.
authorBen Thompson <ben@xtuple.com>
Wed, 11 Jun 2014 18:00:50 +0000 (14:00 -0400)
committerBen Thompson <ben@xtuple.com>
Wed, 11 Jun 2014 18:00:50 +0000 (14:00 -0400)
enyo-client/database/source/xt/functions/add_priv.sql

index f1ef70b..76aeae2 100644 (file)
@@ -5,10 +5,14 @@ create or replace function xt.add_priv(name text, descrip text, module text, gro
   var sqlCount = "select count(*) as count from public.priv where priv_name = $1;",
     sqlId = "select nextval('public.priv_priv_id_seq') as sequence;",
     sqlInsert = "insert into public.priv (priv_id, priv_name, priv_module, priv_descrip) values ($1, $2, $3, $4)",
+    sqlGrantToAdmin = "select xt.grant_role_priv('ADMIN', $1, $2)",
     count = plv8.execute(sqlCount, [ name ])[0].count,
     nextId;
 
   if(count > 0) {
+    /* Grant this priv to the 'ADMIN' role by default. */
+    plv8.execute(sqlGrantToAdmin, [module, name]);
+
     return false;
   }
 
@@ -18,6 +22,10 @@ create or replace function xt.add_priv(name text, descrip text, module text, gro
   /* groop is used to segment the assignment box */
   /* module is the name of the extension. was used to filter the assignment box, but doesn't do that any more */
   plv8.execute(sqlInsert, [nextId, name, module, descrip]);
+
+  /* Grant this priv to the 'ADMIN' role by default. */
+  plv8.execute(sqlGrantToAdmin, [module, name]);
+
   return true;
 
 $$ language plv8;