Allow default ACLs to be specified when creating schemas. Fixes #1108.

This commit is contained in:
Murtuza Zabuawala
2016-06-23 13:03:18 +01:00
committed by Dave Page
parent 5928f70a1d
commit 8b0e65dc57
6 changed files with 29 additions and 45 deletions

View File

@@ -508,7 +508,7 @@ It may have been removed by another user.
) )
) )
try: try:
self.format_request_acls(data, specific=['nspacl']) self.format_request_acls(data)
SQL = render_template( SQL = render_template(
"/".join([self.template_path, 'sql/create.sql']), "/".join([self.template_path, 'sql/create.sql']),
data=data, conn=self.conn, _=gettext data=data, conn=self.conn, _=gettext
@@ -665,7 +665,7 @@ It may have been removed by another user.
SQL = self.get_sql(gid, sid, data, scid) SQL = self.get_sql(gid, sid, data, scid)
if SQL and SQL.strip('\n') and SQL.strip(' '): if SQL and SQL.strip('\n') and SQL.strip(' '):
return make_json_response( return make_json_response(
data=SQL, data=SQL.strip('\n'),
status=200 status=200
) )
except Exception as e: except Exception as e:
@@ -708,7 +708,7 @@ It may have been removed by another user.
return " -- " + gettext("Definition incomplete.") return " -- " + gettext("Definition incomplete.")
# Privileges # Privileges
self.format_request_acls(data, specific=['nspacl']) self.format_request_acls(data)
SQL = render_template( SQL = render_template(
"/".join([self.template_path, 'sql/create.sql']), "/".join([self.template_path, 'sql/create.sql']),

View File

@@ -377,7 +377,7 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
canEdit: false, canDelete: true, control: 'unique-col-collection' canEdit: false, canDelete: true, control: 'unique-col-collection'
},{ },{
type: 'nested', control: 'tab', group: '{{ _('Default Privileges') }}', type: 'nested', control: 'tab', group: '{{ _('Default Privileges') }}',
mode: ['edit'], mode: ['create','edit'],
schema:[{ schema:[{
id: 'deftblacl', model: pgBrowser.Node.PrivilegeRoleModel.extend( id: 'deftblacl', model: pgBrowser.Node.PrivilegeRoleModel.extend(
{privileges: ['a', 'r', 'w', 'd', 'D', 'x', 't']}), {privileges: ['a', 'r', 'w', 'd', 'D', 'x', 't']}),

View File

@@ -4,41 +4,37 @@
{% if data.name %} {% if data.name %}
CREATE SCHEMA {{ conn|qtIdent(data.name) }}{% if data.namespaceowner %} CREATE SCHEMA {{ conn|qtIdent(data.name) }}{% if data.namespaceowner %}
AUTHORIZATION {{ conn|qtIdent(data.namespaceowner) }}{% endif %}; AUTHORIZATION {{ conn|qtIdent(data.namespaceowner) }}{% endif %}{% endif %};
{# Alter the comment/description #} {# Alter the comment/description #}
{% if data.description %} {% if data.description %}
COMMENT ON SCHEMA {{ conn|qtIdent(data.name) }} COMMENT ON SCHEMA {{ conn|qtIdent(data.name) }}
IS {{ data.description|qtLiteral }}; IS {{ data.description|qtLiteral }};
{% endif %} {% endif %}
{# ACL for the schema #} {# ACL for the schema #}
{% if data.nspacl %} {% if data.nspacl %}
{% for priv in data.nspacl %} {% for priv in data.nspacl %}
{{ PRIVILEGE.APPLY(conn, 'SCHEMA', priv.grantee, data.name, priv.without_grant, priv.with_grant) }}{% endfor %} {{ PRIVILEGE.APPLY(conn, 'SCHEMA', priv.grantee, data.name, priv.without_grant, priv.with_grant) }}{% endfor %}
{% endif %} {% endif %}
{# Default privileges on tables #} {# Default privileges on tables #}
{% for defacl, type in [ {% for defacl, type in [
('deftblacl', 'TABLES'), ('defseqacl', 'SEQUENCES'), ('deftblacl', 'TABLES'), ('defseqacl', 'SEQUENCES'),
('deffuncacl', 'FUNCTIONS')] ('deffuncacl', 'FUNCTIONS')]
%} %}
{% if data[defacl] %}{% set acl = data[defacl] %} {% if data[defacl] %}{% set acl = data[defacl] %}
{% for priv in data.deftblacl %} {% for priv in acl %}
{{ DEFAULT_PRIVILEGE.SET( {{ DEFAULT_PRIVILEGE.SET(
conn, 'SCHEMA', data.name, type, priv.grantee, conn, 'SCHEMA', data.name, type, priv.grantee,
priv.without_grant, priv.with_grant priv.without_grant, priv.with_grant
) }}{% endfor %} ) }}{% endfor %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{# Security Labels on schema #} {# Security Labels on schema #}
{% if data.seclabels and data.seclabels|length > 0 %} {% if data.seclabels and data.seclabels|length > 0 %}
{% for r in data.seclabels %} {% for r in data.seclabels %}
{{ SECLABLE.APPLY(conn, 'SCHEMA', data.name, r.provider, r.label) }}
{% endfor %}
{% endif %}
{% else %} {{ SECLABEL.APPLY(conn, 'SCHEMA', data.name, r.provider, r.label) }}
{{ -- _('Incomplete definition') }} {% endfor %}
{% endif %} {% endif %}

View File

@@ -4,41 +4,37 @@
{% if data.name %} {% if data.name %}
CREATE SCHEMA {{ conn|qtIdent(data.name) }}{% if data.namespaceowner %} CREATE SCHEMA {{ conn|qtIdent(data.name) }}{% if data.namespaceowner %}
AUTHORIZATION {{ conn|qtIdent(data.namespaceowner) }}{% endif %}; AUTHORIZATION {{ conn|qtIdent(data.namespaceowner) }}{% endif %}{% endif %};
{# Alter the comment/description #} {# Alter the comment/description #}
{% if data.description %} {% if data.description %}
COMMENT ON SCHEMA {{ conn|qtIdent(data.name) }} COMMENT ON SCHEMA {{ conn|qtIdent(data.name) }}
IS {{ data.description|qtLiteral }}; IS {{ data.description|qtLiteral }};
{% endif %} {% endif %}
{# ACL for the schema #} {# ACL for the schema #}
{% if data.nspacl %} {% if data.nspacl %}
{% for priv in data.nspacl %} {% for priv in data.nspacl %}
{{ PRIVILEGE.APPLY(conn, 'SCHEMA', priv.grantee, data.name, priv.without_grant, priv.with_grant) }}{% endfor %} {{ PRIVILEGE.APPLY(conn, 'SCHEMA', priv.grantee, data.name, priv.without_grant, priv.with_grant) }}{% endfor %}
{% endif %} {% endif %}
{# Default privileges on tables #} {# Default privileges on tables #}
{% for defacl, type in [ {% for defacl, type in [
('deftblacl', 'TABLES'), ('defseqacl', 'SEQUENCES'), ('deftblacl', 'TABLES'), ('defseqacl', 'SEQUENCES'),
('deffuncacl', 'FUNCTIONS'), ('deftypeacl', 'TYPES')] ('deffuncacl', 'FUNCTIONS'), ('deftypeacl', 'TYPES')]
%} %}
{% if data[defacl] %}{% set acl = data[defacl] %} {% if data[defacl] %}{% set acl = data[defacl] %}
{% for priv in data.deftblacl %} {% for priv in acl %}
{{ DEFAULT_PRIVILEGE.SET( {{ DEFAULT_PRIVILEGE.SET(
conn, 'SCHEMA', data.name, type, priv.grantee, conn, 'SCHEMA', data.name, type, priv.grantee,
priv.without_grant, priv.with_grant priv.without_grant, priv.with_grant
) }}{% endfor %} ) }}{% endfor %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{# Security Labels on schema #} {# Security Labels on schema #}
{% if data.seclabels and data.seclabels|length > 0 %} {% if data.seclabels and data.seclabels|length > 0 %}
{% for r in data.seclabels %} {% for r in data.seclabels %}
{{ SECLABEL.APPLY(conn, 'SCHEMA', data.name, r.provider, r.label) }} {{ SECLABEL.APPLY(conn, 'SCHEMA', data.name, r.provider, r.label) }}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% else %}
{{ -- _('Incomplete definition') }}
{% endif %}

View File

@@ -4,41 +4,37 @@
{% if data.name %} {% if data.name %}
CREATE SCHEMA {{ conn|qtIdent(data.name) }}{% if data.namespaceowner %} CREATE SCHEMA {{ conn|qtIdent(data.name) }}{% if data.namespaceowner %}
AUTHORIZATION {{ conn|qtIdent(data.namespaceowner) }}{% endif %}; AUTHORIZATION {{ conn|qtIdent(data.namespaceowner) }}{% endif %}{% endif %};
{# Alter the comment/description #} {# Alter the comment/description #}
{% if data.description %} {% if data.description %}
COMMENT ON SCHEMA {{ conn|qtIdent(data.name) }} COMMENT ON SCHEMA {{ conn|qtIdent(data.name) }}
IS {{ data.description|qtLiteral }}; IS {{ data.description|qtLiteral }};
{% endif %} {% endif %}
{# ACL for the schema #} {# ACL for the schema #}
{% if data.nspacl %} {% if data.nspacl %}
{% for priv in data.nspacl %} {% for priv in data.nspacl %}
{{ PRIVILEGE.APPLY(conn, 'SCHEMA', priv.grantee, data.name, priv.without_grant, priv.with_grant) }}{% endfor %} {{ PRIVILEGE.APPLY(conn, 'SCHEMA', priv.grantee, data.name, priv.without_grant, priv.with_grant) }}{% endfor %}
{% endif %} {% endif %}
{# Default privileges on tables #} {# Default privileges on tables #}
{% for defacl, type in [ {% for defacl, type in [
('deftblacl', 'TABLES'), ('defseqacl', 'SEQUENCES'), ('deftblacl', 'TABLES'), ('defseqacl', 'SEQUENCES'),
('deffuncacl', 'FUNCTIONS')] ('deffuncacl', 'FUNCTIONS')]
%} %}
{% if data[defacl] %}{% set acl = data[defacl] %} {% if data[defacl] %}{% set acl = data[defacl] %}
{% for priv in data.deftblacl %} {% for priv in acl %}
{{ DEFAULT_PRIVILEGE.SET( {{ DEFAULT_PRIVILEGE.SET(
conn, 'SCHEMA', data.name, type, priv.grantee, conn, 'SCHEMA', data.name, type, priv.grantee,
priv.without_grant, priv.with_grant priv.without_grant, priv.with_grant
) }}{% endfor %} ) }}{% endfor %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{# Security Labels on schema #} {# Security Labels on schema #}
{% if data.seclabels and data.seclabels|length > 0 %} {% if data.seclabels and data.seclabels|length > 0 %}
{% for r in data.seclabels %} {% for r in data.seclabels %}
{{ SECLABEL.APPLY(conn, 'SCHEMA', data.name, r.provider, r.label) }} {{ SECLABEL.APPLY(conn, 'SCHEMA', data.name, r.provider, r.label) }}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% else %}
{{ -- _('Incomplete definition') }}
{% endif %}

View File

@@ -4,41 +4,37 @@
{% if data.name %} {% if data.name %}
CREATE SCHEMA {{ conn|qtIdent(data.name) }}{% if data.namespaceowner %} CREATE SCHEMA {{ conn|qtIdent(data.name) }}{% if data.namespaceowner %}
AUTHORIZATION {{ conn|qtIdent(data.namespaceowner) }}{% endif %}; AUTHORIZATION {{ conn|qtIdent(data.namespaceowner) }}{% endif %}{% endif %};
{# Alter the comment/description #} {# Alter the comment/description #}
{% if data.description %} {% if data.description %}
COMMENT ON SCHEMA {{ conn|qtIdent(data.name) }} COMMENT ON SCHEMA {{ conn|qtIdent(data.name) }}
IS {{ data.description|qtLiteral }}; IS {{ data.description|qtLiteral }};
{% endif %} {% endif %}
{# ACL for the schema #} {# ACL for the schema #}
{% if data.nspacl %} {% if data.nspacl %}
{% for priv in data.nspacl %} {% for priv in data.nspacl %}
{{ PRIVILEGE.APPLY(conn, 'SCHEMA', priv.grantee, data.name, priv.without_grant, priv.with_grant) }}{% endfor %} {{ PRIVILEGE.APPLY(conn, 'SCHEMA', priv.grantee, data.name, priv.without_grant, priv.with_grant) }}{% endfor %}
{% endif %} {% endif %}
{# Default privileges on tables #} {# Default privileges on tables #}
{% for defacl, type in [ {% for defacl, type in [
('deftblacl', 'TABLES'), ('defseqacl', 'SEQUENCES'), ('deftblacl', 'TABLES'), ('defseqacl', 'SEQUENCES'),
('deffuncacl', 'FUNCTIONS'), ('deftypeacl', 'TYPES')] ('deffuncacl', 'FUNCTIONS'), ('deftypeacl', 'TYPES')]
%} %}
{% if data[defacl] %}{% set acl = data[defacl] %} {% if data[defacl] %}{% set acl = data[defacl] %}
{% for priv in data.deftblacl %} {% for priv in acl %}
{{ DEFAULT_PRIVILEGE.SET( {{ DEFAULT_PRIVILEGE.SET(
conn, 'SCHEMA', data.name, type, priv.grantee, conn, 'SCHEMA', data.name, type, priv.grantee,
priv.without_grant, priv.with_grant priv.without_grant, priv.with_grant
) }}{% endfor %} ) }}{% endfor %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{# Security Labels on schema #} {# Security Labels on schema #}
{% if data.seclabels and data.seclabels|length > 0 %} {% if data.seclabels and data.seclabels|length > 0 %}
{% for r in data.seclabels %} {% for r in data.seclabels %}
{{ SECLABEL.APPLY(conn, 'SCHEMA', data.name, r.provider, r.label) }} {{ SECLABEL.APPLY(conn, 'SCHEMA', data.name, r.provider, r.label) }}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% else %}
{{ -- _('Incomplete definition') }}
{% endif %}