Fixed SQL for Row Level Security which is incorrectly generated. Fixes #5764

This commit is contained in:
Pradip Parkale 2020-09-07 18:40:49 +05:30 committed by Akshay Joshi
parent 8c2e965f6e
commit 9e5487d5ad
7 changed files with 22 additions and 10 deletions

View File

@ -32,6 +32,7 @@ Bug fixes
| `Issue #5748 <https://redmine.postgresql.org/issues/5748>`_ - Fixed incorrect reverse engineering SQL for Foreign key when creating a table.
| `Issue #5751 <https://redmine.postgresql.org/issues/5751>`_ - Enable the 'Configure' and 'View log' menu option when the server taking longer than usual time to start.
| `Issue #5754 <https://redmine.postgresql.org/issues/5754>`_ - Fixed an issue where schema diff is not working when providing the options to Foreign Data Wrapper, Foreign Server, and User Mapping.
| `Issue #5764 <https://redmine.postgresql.org/issues/5764>`_ - Fixed SQL for Row Level Security which is incorrectly generated.
| `Issue #5765 <https://redmine.postgresql.org/issues/5765>`_ - Fixed an issue in the query tool when columns are having the same name as javascript object internal functions.
| `Issue #5766 <https://redmine.postgresql.org/issues/5766>`_ - Fixed string indices must be integers issue for PostgreSQL < 9.3.
| `Issue #5773 <https://redmine.postgresql.org/issues/5773>`_ - Fixed an issue where the application ignores the fixed port configuration value.

View File

@ -315,7 +315,8 @@ class RowSecurityView(PGChildNodeView):
"""
sql = render_template("/".join(
[self.template_path, self._PROPERTIES_SQL]
), plid=plid, scid=scid, datlastsysoid=self.datlastsysoid)
), plid=plid, scid=scid, policy_table_id=tid,
datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(sql)
if not status:
@ -415,6 +416,7 @@ class RowSecurityView(PGChildNodeView):
try:
sql, name = row_security_policies_utils.get_sql(
self.conn, data=data, scid=scid, plid=plid,
policy_table_id=tid,
schema=self.schema, table=self.table)
# Most probably this is due to error
@ -475,7 +477,7 @@ class RowSecurityView(PGChildNodeView):
for plid in data['ids']:
try:
# Get name for policy from plid
# Get name of policy using plid
sql = render_template("/".join([self.template_path,
'get_policy_name.sql']),
plid=plid)
@ -525,7 +527,7 @@ class RowSecurityView(PGChildNodeView):
data = dict(request.args)
sql, name = row_security_policies_utils.get_sql(
self.conn, data=data, scid=scid, plid=plid,
self.conn, data=data, scid=scid, plid=plid, policy_table_id=tid,
schema=self.schema, table=self.table)
if not isinstance(sql, str):
return sql
@ -554,7 +556,7 @@ class RowSecurityView(PGChildNodeView):
SQL = row_security_policies_utils.get_reverse_engineered_sql(
self.conn, schema=self.schema, table=self.table, scid=scid,
plid=plid, datlastsysoid=self.datlastsysoid)
plid=plid, policy_table_id=tid, datlastsysoid=self.datlastsysoid)
return ajax_response(response=SQL)

View File

@ -68,13 +68,15 @@ def get_sql(conn, **kwargs):
data = kwargs.get('data')
scid = kwargs.get('scid')
plid = kwargs.get('plid')
policy_table_id = kwargs.get('policy_table_id')
schema = kwargs.get('schema')
table = kwargs.get('table')
template_path = kwargs.get('template_path', None)
if plid is not None:
sql = render_template("/".join([template_path, 'properties.sql']),
schema=schema, plid=plid, scid=scid)
schema=schema, plid=plid, scid=scid,
policy_table_id=policy_table_id)
status, res = conn.execute_dict(sql)
if not status:
return internal_server_error(errormsg=res)
@ -110,12 +112,14 @@ def get_reverse_engineered_sql(conn, **kwargs):
table = kwargs.get('table')
scid = kwargs.get('scid')
plid = kwargs.get('plid')
policy_table_id = kwargs.get('policy_table_id')
datlastsysoid = kwargs.get('datlastsysoid')
template_path = kwargs.get('template_path', None)
with_header = kwargs.get('with_header', True)
SQL = render_template("/".join(
[template_path, 'properties.sql']), plid=plid, scid=scid)
[template_path, 'properties.sql']), plid=plid, scid=scid,
policy_table_id=policy_table_id)
status, res = conn.execute_dict(SQL)
if not status:
@ -130,6 +134,7 @@ def get_reverse_engineered_sql(conn, **kwargs):
data['table'] = table
SQL, name = get_sql(conn, data=data, scid=scid, plid=None,
policy_table_id=policy_table_id,
datlastsysoid=datlastsysoid, schema=schema,
table=table)
if with_header:

View File

@ -13,9 +13,10 @@ FROM
pg_policy pl
JOIN pg_policies rw ON pl.polname=rw.policyname
JOIN pg_namespace n ON n.nspname=rw.schemaname
JOIN pg_class rel on rel.relname=rw.tablename
WHERE
{% if plid %}
pl.oid = {{ plid }} and n.oid = {{ scid }};
pl.oid = {{ plid }} and n.oid = {{ scid }} and rel.relfilenode = {{ policy_table_id }};
{% endif %}
{% if tid %}
pl.polrelid = {{ tid }};

View File

@ -12,9 +12,10 @@ FROM
pg_policy pl
JOIN pg_policies rw ON pl.polname=rw.policyname
JOIN pg_namespace n ON n.nspname=rw.schemaname
JOIN pg_class rel on rel.relname=rw.tablename
WHERE
{% if plid %}
pl.oid = {{ plid }} and n.oid = {{ scid }};
pl.oid = {{ plid }} and n.oid = {{ scid }} and rel.relfilenode = {{ policy_table_id }};
{% endif %}
{% if tid %}
pl.polrelid = {{ tid }};

View File

@ -12,9 +12,10 @@ FROM
pg_policy pl
JOIN pg_policies rw ON pl.polname=rw.policyname
JOIN pg_namespace n ON n.nspname=rw.schemaname
JOIN pg_class rel on rel.relname=rw.tablename
WHERE
{% if plid %}
pl.oid = {{ plid }} and n.oid = {{ scid }};
pl.oid = {{ plid }} and n.oid = {{ scid }} and rel.relfilenode = {{ policy_table_id }};
{% endif %}
{% if tid %}
pl.polrelid = {{ tid }};

View File

@ -547,7 +547,8 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
policy_sql = row_security_policies_utils. \
get_reverse_engineered_sql(
self.conn, schema=schema, table=table, scid=scid,
plid=row['oid'], datlastsysoid=self.datlastsysoid,
plid=row['oid'], policy_table_id=tid,
datlastsysoid=self.datlastsysoid,
template_path=None, with_header=json_resp)
policy_sql = "\n" + policy_sql