mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Update "parse_priv_to_db" function to return list a instead of a string.
This will also allow us to operate on individual privileges & also we needed this functionality for column nodes. For example, *Earlier:* priv was string GRANT {{ priv }} ON {{ type }} TO {{ conn|qtIdent(role) }}; *Now:* priv will be List, which we need to handle in jinja templates. GRANT *{{ priv|join(', ') }}* ON {{ type }} TO {{ conn|qtIdent(role) }};
This commit is contained in:
parent
5d6c5bc74d
commit
8a7ec6b452
@ -1,11 +1,11 @@
|
|||||||
{% macro APPLY(conn, type, role, priv, with_grant) -%}
|
{% macro APPLY(conn, type, role, privs, with_grant_privs) -%}
|
||||||
{% if priv %}
|
{% if privs %}
|
||||||
ALTER DEFAULT PRIVILEGES
|
ALTER DEFAULT PRIVILEGES
|
||||||
GRANT {{ priv }} ON {{ type }} TO {{ conn|qtIdent(role) }};
|
GRANT {{ privs|join(', ') }} ON {{ type }} TO {{ conn|qtIdent(role) }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if with_grant %}
|
{% if with_grant_privs %}
|
||||||
ALTER DEFAULT PRIVILEGES
|
ALTER DEFAULT PRIVILEGES
|
||||||
GRANT {{ with_grant }} ON {{ type }} TO {{ conn|qtIdent(role) }} WITH GRANT OPTION;
|
GRANT {{ with_grant_privs|join(', ') }} ON {{ type }} TO {{ conn|qtIdent(role) }} WITH GRANT OPTION;
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
{% macro RESETALL(conn, type, role) -%}
|
{% macro RESETALL(conn, type, role) -%}
|
||||||
@ -13,14 +13,14 @@ ALTER DEFAULT PRIVILEGES
|
|||||||
REVOKE ALL ON {{ type }} FROM {{ conn|qtIdent(role) }};
|
REVOKE ALL ON {{ type }} FROM {{ conn|qtIdent(role) }};
|
||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
{### To allow create macro for specific database object ###}
|
{### To allow create macro for specific database object ###}
|
||||||
{% macro SET(conn, db_object_type, db_object_name, type, role, priv, with_grant) -%}
|
{% macro SET(conn, db_object_type, db_object_name, type, role, privs, with_grant_privs) -%}
|
||||||
{% if priv %}
|
{% if privs %}
|
||||||
ALTER DEFAULT PRIVILEGES IN {{ db_object_type }} {{ conn|qtIdent(db_object_name) }}
|
ALTER DEFAULT PRIVILEGES IN {{ db_object_type }} {{ conn|qtIdent(db_object_name) }}
|
||||||
GRANT {{ priv }} ON {{ type }} TO {{ conn|qtIdent(role) }};
|
GRANT {{ privs|join(', ') }} ON {{ type }} TO {{ conn|qtIdent(role) }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if with_grant %}
|
{% if with_grant_privs %}
|
||||||
ALTER DEFAULT PRIVILEGES IN {{ db_object_type }} {{ conn|qtIdent(db_object_name) }}
|
ALTER DEFAULT PRIVILEGES IN {{ db_object_type }} {{ conn|qtIdent(db_object_name) }}
|
||||||
GRANT {{ with_grant }} ON {{ type }} TO {{ conn|qtIdent(role) }} WITH GRANT OPTION;
|
GRANT {{ with_grant_privs|join(', ') }} ON {{ type }} TO {{ conn|qtIdent(role) }} WITH GRANT OPTION;
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
{% macro UNSET(conn, db_object_type, db_object_name, type, role) -%}
|
{% macro UNSET(conn, db_object_type, db_object_name, type, role) -%}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
{% macro APPLY(conn, type, role, param, priv, with_grant) -%}
|
{% macro APPLY(conn, type, role, param, privs, with_grant_privs) -%}
|
||||||
{% if priv %}
|
{% if privs %}
|
||||||
GRANT {{ priv }} ON {{ type }} {{ conn|qtIdent(param) }} TO {{ conn|qtIdent(role) }};
|
GRANT {{ privs|join(', ') }} ON {{ type }} {{ conn|qtIdent(param) }} TO {{ conn|qtIdent(role) }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if with_grant %}
|
{% if with_grant_privs %}
|
||||||
GRANT {{ with_grant }} ON {{ type }} {{ conn|qtIdent(param) }} TO {{ conn|qtIdent(role) }} WITH GRANT OPTION;
|
GRANT {{ with_grant_privs|join(', ') }} ON {{ type }} {{ conn|qtIdent(param) }} TO {{ conn|qtIdent(role) }} WITH GRANT OPTION;
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
{% macro RESETALL(conn, type, role, param) -%}
|
{% macro RESETALL(conn, type, role, param) -%}
|
||||||
|
@ -75,12 +75,12 @@ def parse_priv_to_db(str_privileges, allowed_acls = []):
|
|||||||
priv_without_grant.append(
|
priv_without_grant.append(
|
||||||
db_privileges[privilege['privilege_type']]
|
db_privileges[privilege['privilege_type']]
|
||||||
)
|
)
|
||||||
|
# If we have all acl then just return all
|
||||||
priv_with_grant = ", ".join(priv_with_grant) \
|
if len(priv_with_grant) == allowed_acls_len:
|
||||||
if len(priv_with_grant) < allowed_acls_len else 'ALL'
|
priv_with_grant = ['ALL']
|
||||||
priv_without_grant = ", ".join(priv_without_grant) \
|
if len(priv_without_grant) == allowed_acls_len:
|
||||||
if len(priv_without_grant) < allowed_acls_len else 'ALL'
|
priv_without_grant = ['ALL']
|
||||||
|
# Appending and returning all ACL
|
||||||
privileges.append({
|
privileges.append({
|
||||||
'grantee': priv['grantee'],
|
'grantee': priv['grantee'],
|
||||||
'with_grant': priv_with_grant,
|
'with_grant': priv_with_grant,
|
||||||
|
Loading…
Reference in New Issue
Block a user