diff --git a/web/pgadmin/tools/grant_wizard/__init__.py b/web/pgadmin/tools/grant_wizard/__init__.py index 4002e4e..a60dc36 100644 --- a/web/pgadmin/tools/grant_wizard/__init__.py +++ b/web/pgadmin/tools/grant_wizard/__init__.py @@ -227,6 +227,21 @@ def properties(gid, sid, did, node_id, node_type): res_data.extend(res['rows']) + # Fetch procedures only if server type is ppas + if (len(server_prop) > 0 and + server_prop['server_type'] == 'ppas' and + ntype in ['schema', 'procedure']): + SQL = render_template("/".join( + [server_prop['template_path'], '/sql/function.sql']), + node_id=node_id, nspname=nspname, type='procedure') + + status, res = conn.execute_dict(SQL) + + if not status: + return internal_server_error(errormsg=res) + + res_data.extend(res['rows']) + # Fetch trigger functions if ntype in ['schema', 'trigger_function']: SQL = render_template("/".join( diff --git a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/js/grant_wizard.js b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/js/grant_wizard.js index 7340ec5..b167447 100644 --- a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/js/grant_wizard.js +++ b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/js/grant_wizard.js @@ -41,8 +41,11 @@ define([ res.object_id = res.name_with_args; // create name with args if its object is function - if(!_.isUndefined(res.object_type) && (res.object_type == 'Function' || - res.object_type == 'Trigger Function')) + if(!_.isUndefined(res.object_type) && + (res.object_type == 'Function' || + res.object_type == 'Trigger Function' || + res.object_type == 'Procedure' + )) res.name_with_args = res.name+'('+(typeof(res.proargs) != 'undefined' ? res.proargs : '')+')'; else res.name_with_args = res.name; @@ -138,7 +141,7 @@ define([ // Define list of nodes on which grant wizard context menu option appears var supported_nodes = [ 'schema', 'coll-function', 'coll-sequence', - 'coll-table', 'coll-view', + 'coll-table', 'coll-view', 'coll-procedure', 'coll-materialized_view', 'database' ], @@ -508,6 +511,9 @@ define([ case 'Trigger Function': object_type = 'function'; break; + case 'Procedure': + object_type = 'procedure'; + break; case 'Table': object_type = 'table'; break; diff --git a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/acl.json b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/acl.json index 2d21f14..78782b5 100644 --- a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/acl.json +++ b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/acl.json @@ -26,5 +26,9 @@ "function": { "type": "FUNCTION", "acl": ["X"] + }, + "procedure": { + "type": "PROCEDURE", + "acl": ["X"] } } diff --git a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/function.sql b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/function.sql index 7fad225..067606f 100644 --- a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/function.sql +++ b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/function.sql @@ -1,14 +1,14 @@ {# ===== Fetch list of Database object types(Functions) ====== #} {% if type and node_id and nspname %} {% set func_type = 'Trigger Function' if type == 'trigger_function' else 'Function' %} +{% set icon = 'icon-function' if type == 'function' else 'icon-trigger_function' %} SELECT pr.oid, pg_get_function_identity_arguments(pr.oid) AS proargs, - {# pr.proname || '(' || pg_get_function_identity_arguments(pr.oid) || ')' AS name,#} pr.proname AS name, - '{{ nspname }}' AS nspname, '{{ func_type }}' AS object_type, - '{{ "icon-function" if type != "trigger_function" else "icon-trigger_function" }}' AS icon + '{{ nspname }}' AS nspname, + '{{ icon }}' AS icon FROM pg_proc pr JOIN pg_type typ ON typ.oid=prorettype diff --git a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/grant_function.sql b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/grant_function.sql index aea68af..7e8e506 100644 --- a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/grant_function.sql +++ b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/grant_function.sql @@ -2,9 +2,8 @@ {% import 'macros/functions/privilege.macros' as PRIVILEGE_FUNCTION %} {% for obj in data.objects -%} {% for priv in data.priv -%} -{# ===== if object_type is Function then apply function marcros ===== #} -{% if (obj.object_type == 'Function' or obj.object_type == 'Trigger Function') %} -{{ PRIVILEGE_FUNCTION.SET(conn, 'FUNCTION', priv['grantee'], obj.name, priv['without_grant'], priv['with_grant'], obj.nspname, obj.proargs)}} +{% if (obj.object_type == 'Function' or obj.object_type == 'Trigger Function' or obj.object_type == 'Procedure') %}{% set func_type = 'PROCEDURE' if obj.object_type == 'Procedure' else 'FUNCTION' if obj.object_type == 'Function' or obj.object_type == 'Trigger Function' -%} +{{ PRIVILEGE_FUNCTION.SET(conn, func_type, priv['grantee'], obj.name, priv['without_grant'], priv['with_grant'], obj.nspname, obj.proargs)}} {% endif -%} {% endfor -%} {% endfor -%} diff --git a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/acl.json b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/acl.json index 2d21f14..78782b5 100644 --- a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/acl.json +++ b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/acl.json @@ -26,5 +26,9 @@ "function": { "type": "FUNCTION", "acl": ["X"] + }, + "procedure": { + "type": "PROCEDURE", + "acl": ["X"] } } diff --git a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/function.sql b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/function.sql index 7fad225..855a841 100644 --- a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/function.sql +++ b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/function.sql @@ -1,14 +1,14 @@ {# ===== Fetch list of Database object types(Functions) ====== #} {% if type and node_id and nspname %} -{% set func_type = 'Trigger Function' if type == 'trigger_function' else 'Function' %} +{% set func_type = 'Trigger Function' if type == 'trigger_function' else 'Procedure' if type == 'procedure' else 'Function' %} +{% set icon = 'icon-function' if type == 'function' else 'icon-procedure' if type == 'procedure' else 'icon-trigger_function' %} SELECT pr.oid, pg_get_function_identity_arguments(pr.oid) AS proargs, - {# pr.proname || '(' || pg_get_function_identity_arguments(pr.oid) || ')' AS name,#} pr.proname AS name, - '{{ nspname }}' AS nspname, '{{ func_type }}' AS object_type, - '{{ "icon-function" if type != "trigger_function" else "icon-trigger_function" }}' AS icon + '{{ nspname }}' AS nspname, + '{{ icon }}' AS icon FROM pg_proc pr JOIN pg_type typ ON typ.oid=prorettype @@ -18,6 +18,7 @@ LEFT OUTER JOIN pg_description des ON (des.objoid=pr.oid AND des.classoid='pg_pr WHERE proisagg = FALSE AND pronamespace = {{ node_id }}::oid AND typname {{ 'NOT' if type != 'trigger_function' else '' }} IN ('trigger', 'event_trigger') + AND pr.protype = {{ 0 if type != 'procedure' else 1 }} ORDER BY proname {% endif %} diff --git a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/get_schemas.sql b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/get_schemas.sql index 4f6fd5a..4d47fa1 100644 --- a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/get_schemas.sql +++ b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/get_schemas.sql @@ -1,11 +1,12 @@ {# ===== Fetch list of all schemas ===== #} -{% import 'catalog/pg/macros/catalogs.sql' as CATALOGS %} +{% import 'catalog/ppas/macros/catalogs.sql' as CATALOGS %} SELECT nsp.oid, nsp.nspname as name FROM pg_namespace nsp WHERE + nsp.nspparent = 0 AND {% if nspid %} nsp.oid={{nspid}}::int AND {% else %} diff --git a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/grant_function.sql b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/grant_function.sql index aea68af..7e8e506 100644 --- a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/grant_function.sql +++ b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/grant_function.sql @@ -2,9 +2,8 @@ {% import 'macros/functions/privilege.macros' as PRIVILEGE_FUNCTION %} {% for obj in data.objects -%} {% for priv in data.priv -%} -{# ===== if object_type is Function then apply function marcros ===== #} -{% if (obj.object_type == 'Function' or obj.object_type == 'Trigger Function') %} -{{ PRIVILEGE_FUNCTION.SET(conn, 'FUNCTION', priv['grantee'], obj.name, priv['without_grant'], priv['with_grant'], obj.nspname, obj.proargs)}} +{% if (obj.object_type == 'Function' or obj.object_type == 'Trigger Function' or obj.object_type == 'Procedure') %}{% set func_type = 'PROCEDURE' if obj.object_type == 'Procedure' else 'FUNCTION' if obj.object_type == 'Function' or obj.object_type == 'Trigger Function' -%} +{{ PRIVILEGE_FUNCTION.SET(conn, func_type, priv['grantee'], obj.name, priv['without_grant'], priv['with_grant'], obj.nspname, obj.proargs)}} {% endif -%} {% endfor -%} {% endfor -%}