public inbox for [email protected]  
help / color / mirror / Atom feed
From: Surinder Kumar <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin4][Patch]: RM#1293 - SQL pane is not displaying GRANT queries in Function, Procedure and Trigger node
Date: Thu, 2 Jun 2016 19:25:39 +0530
Message-ID: <CAM5-9D_P=5wEc5phxDcf41y09gnxgAU++ffxCQL9qMkkOb203w@mail.gmail.com> (raw)
List-Unsubscribe:  <mailto:[email protected]?body=unsub%20pgadmin-hackers>

Hi,

Please find attached patch for RM#1293.
Add support to display GRANT privilege query in SQL Pane.

Please review.

Thanks,
Surinder Kumar


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers


Attachments:

  [application/octet-stream] display_GRANT_queries_in_SQL_PANE.patch (12.3K, 3-display_GRANT_queries_in_SQL_PANE.patch)
  download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py
index 99cf94a..5119b80 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/__init__.py
@@ -886,6 +886,20 @@ class FunctionView(PGChildNodeView, DataTypeReader):
             scid: Schema Id
             fnid: Function Id
         """
+        data_prop = self._fetch_properties(gid, sid, did, scid, fnid)
+
+        # Get Schema Name from its OID.
+        if 'pronamespace' in data_prop:
+            data_prop['pronamespace'] = self._get_schema(data_prop[
+                'pronamespace'])
+
+        # Parse privilege data
+        if 'acl' in data_prop:
+            data_prop['acl'] = parse_priv_to_db(data_prop['acl'], ['X'])
+
+        # Fetch the function definition.
+        grant_SQL = render_template("/".join([self.sql_template_path,
+                                    'grant.sql']), data=data_prop)

         if self.node_type == 'procedure':
             object_type = 'procedure'
@@ -902,7 +916,8 @@ class FunctionView(PGChildNodeView, DataTypeReader):
             object_type = 'function'
             # Fetch the function definition.
             SQL = render_template("/".join([self.sql_template_path,
-                                  'get_definition.sql']), fnid=fnid, scid=scid)
+                                  'get_definition.sql']),
+                                  fnid=fnid, scid=scid)
             status, res = self.conn.execute_2darray(SQL)
             if not status:
                 return internal_server_error(errormsg=res)
@@ -915,7 +930,7 @@ class FunctionView(PGChildNodeView, DataTypeReader):

 """.format(object_type.upper(), name)

-        SQL = sql_header + func_def
+        SQL = sql_header + func_def + '\n' + grant_SQL
         SQL = re.sub('\n{2,}', '\n\n', SQL)

         return ajax_response(response=SQL)
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.1_plus/grant.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.1_plus/grant.sql
new file mode 100644
index 0000000..8523219
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.1_plus/grant.sql
@@ -0,0 +1,2 @@
+{% import 'macros/functions/privilege.macros' as PRIVILEGE %}
+{% if data.acl %}{% for p in data.acl %}{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.proargs)}}{% endfor %}{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.2_plus/grant.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.2_plus/grant.sql
new file mode 100644
index 0000000..8523219
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.2_plus/grant.sql
@@ -0,0 +1,2 @@
+{% import 'macros/functions/privilege.macros' as PRIVILEGE %}
+{% if data.acl %}{% for p in data.acl %}{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.proargs)}}{% endfor %}{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.5_plus/grant.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.5_plus/grant.sql
new file mode 100644
index 0000000..8523219
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/pg/sql/9.5_plus/grant.sql
@@ -0,0 +1,2 @@
+{% import 'macros/functions/privilege.macros' as PRIVILEGE %}
+{% if data.acl %}{% for p in data.acl %}{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.proargs)}}{% endfor %}{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.1_plus/grant.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.1_plus/grant.sql
new file mode 100644
index 0000000..8523219
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.1_plus/grant.sql
@@ -0,0 +1,2 @@
+{% import 'macros/functions/privilege.macros' as PRIVILEGE %}
+{% if data.acl %}{% for p in data.acl %}{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.proargs)}}{% endfor %}{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.2_plus/grant.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.2_plus/grant.sql
new file mode 100644
index 0000000..8523219
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.2_plus/grant.sql
@@ -0,0 +1,2 @@
+{% import 'macros/functions/privilege.macros' as PRIVILEGE %}
+{% if data.acl %}{% for p in data.acl %}{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.proargs)}}{% endfor %}{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.5_plus/grant.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.5_plus/grant.sql
new file mode 100644
index 0000000..8523219
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/function/ppas/sql/9.5_plus/grant.sql
@@ -0,0 +1,2 @@
+{% import 'macros/functions/privilege.macros' as PRIVILEGE %}
+{% if data.acl %}{% for p in data.acl %}{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.proargs)}}{% endfor %}{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.1_plus/grant.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.1_plus/grant.sql
new file mode 100644
index 0000000..eee5257
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.1_plus/grant.sql
@@ -0,0 +1,2 @@
+{% import 'macros/functions/privilege.macros' as PRIVILEGE %}
+{% if data.acl %}{% for p in data.acl %}{{ PRIVILEGE.SET(conn, "PROCEDURE", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.proargs)}}{% endfor %}{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.2_plus/grant.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.2_plus/grant.sql
new file mode 100644
index 0000000..eee5257
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.2_plus/grant.sql
@@ -0,0 +1,2 @@
+{% import 'macros/functions/privilege.macros' as PRIVILEGE %}
+{% if data.acl %}{% for p in data.acl %}{{ PRIVILEGE.SET(conn, "PROCEDURE", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.proargs)}}{% endfor %}{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.5_plus/grant.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.5_plus/grant.sql
new file mode 100644
index 0000000..eee5257
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/procedure/ppas/sql/9.5_plus/grant.sql
@@ -0,0 +1,2 @@
+{% import 'macros/functions/privilege.macros' as PRIVILEGE %}
+{% if data.acl %}{% for p in data.acl %}{{ PRIVILEGE.SET(conn, "PROCEDURE", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.proargs)}}{% endfor %}{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.1_plus/grant.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.1_plus/grant.sql
new file mode 100644
index 0000000..8523219
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.1_plus/grant.sql
@@ -0,0 +1,2 @@
+{% import 'macros/functions/privilege.macros' as PRIVILEGE %}
+{% if data.acl %}{% for p in data.acl %}{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.proargs)}}{% endfor %}{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.2_plus/grant.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.2_plus/grant.sql
new file mode 100644
index 0000000..8523219
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.2_plus/grant.sql
@@ -0,0 +1,2 @@
+{% import 'macros/functions/privilege.macros' as PRIVILEGE %}
+{% if data.acl %}{% for p in data.acl %}{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.proargs)}}{% endfor %}{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.5_plus/grant.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.5_plus/grant.sql
new file mode 100644
index 0000000..8523219
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/pg/sql/9.5_plus/grant.sql
@@ -0,0 +1,2 @@
+{% import 'macros/functions/privilege.macros' as PRIVILEGE %}
+{% if data.acl %}{% for p in data.acl %}{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.proargs)}}{% endfor %}{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.1_plus/grant.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.1_plus/grant.sql
new file mode 100644
index 0000000..8523219
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.1_plus/grant.sql
@@ -0,0 +1,2 @@
+{% import 'macros/functions/privilege.macros' as PRIVILEGE %}
+{% if data.acl %}{% for p in data.acl %}{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.proargs)}}{% endfor %}{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.2_plus/grant.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.2_plus/grant.sql
new file mode 100644
index 0000000..8523219
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.2_plus/grant.sql
@@ -0,0 +1,2 @@
+{% import 'macros/functions/privilege.macros' as PRIVILEGE %}
+{% if data.acl %}{% for p in data.acl %}{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.proargs)}}{% endfor %}{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.5_plus/grant.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.5_plus/grant.sql
new file mode 100644
index 0000000..8523219
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_function/ppas/sql/9.5_plus/grant.sql
@@ -0,0 +1,2 @@
+{% import 'macros/functions/privilege.macros' as PRIVILEGE %}
+{% if data.acl %}{% for p in data.acl %}{{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.proargs)}}{% endfor %}{% endif %}


view thread (6+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: [pgAdmin4][Patch]: RM#1293 - SQL pane is not displaying GRANT queries in Function, Procedure and Trigger node
  In-Reply-To: <CAM5-9D_P=5wEc5phxDcf41y09gnxgAU++ffxCQL9qMkkOb203w@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox