mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Fixed SQL for Row Level Security which is incorrectly generated. Fixes #5764
This commit is contained in:
committed by
Akshay Joshi
parent
8c2e965f6e
commit
9e5487d5ad
@@ -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 #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 #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 #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 #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 #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.
|
| `Issue #5773 <https://redmine.postgresql.org/issues/5773>`_ - Fixed an issue where the application ignores the fixed port configuration value.
|
||||||
|
|||||||
@@ -315,7 +315,8 @@ class RowSecurityView(PGChildNodeView):
|
|||||||
"""
|
"""
|
||||||
sql = render_template("/".join(
|
sql = render_template("/".join(
|
||||||
[self.template_path, self._PROPERTIES_SQL]
|
[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)
|
status, res = self.conn.execute_dict(sql)
|
||||||
|
|
||||||
if not status:
|
if not status:
|
||||||
@@ -415,6 +416,7 @@ class RowSecurityView(PGChildNodeView):
|
|||||||
try:
|
try:
|
||||||
sql, name = row_security_policies_utils.get_sql(
|
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)
|
schema=self.schema, table=self.table)
|
||||||
|
|
||||||
# Most probably this is due to error
|
# Most probably this is due to error
|
||||||
@@ -475,7 +477,7 @@ class RowSecurityView(PGChildNodeView):
|
|||||||
|
|
||||||
for plid in data['ids']:
|
for plid in data['ids']:
|
||||||
try:
|
try:
|
||||||
# Get name for policy from plid
|
# Get name of policy using plid
|
||||||
sql = render_template("/".join([self.template_path,
|
sql = render_template("/".join([self.template_path,
|
||||||
'get_policy_name.sql']),
|
'get_policy_name.sql']),
|
||||||
plid=plid)
|
plid=plid)
|
||||||
@@ -525,7 +527,7 @@ class RowSecurityView(PGChildNodeView):
|
|||||||
data = dict(request.args)
|
data = dict(request.args)
|
||||||
|
|
||||||
sql, name = row_security_policies_utils.get_sql(
|
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)
|
schema=self.schema, table=self.table)
|
||||||
if not isinstance(sql, str):
|
if not isinstance(sql, str):
|
||||||
return sql
|
return sql
|
||||||
@@ -554,7 +556,7 @@ class RowSecurityView(PGChildNodeView):
|
|||||||
|
|
||||||
SQL = row_security_policies_utils.get_reverse_engineered_sql(
|
SQL = row_security_policies_utils.get_reverse_engineered_sql(
|
||||||
self.conn, schema=self.schema, table=self.table, scid=scid,
|
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)
|
return ajax_response(response=SQL)
|
||||||
|
|
||||||
|
|||||||
@@ -68,13 +68,15 @@ def get_sql(conn, **kwargs):
|
|||||||
data = kwargs.get('data')
|
data = kwargs.get('data')
|
||||||
scid = kwargs.get('scid')
|
scid = kwargs.get('scid')
|
||||||
plid = kwargs.get('plid')
|
plid = kwargs.get('plid')
|
||||||
|
policy_table_id = kwargs.get('policy_table_id')
|
||||||
schema = kwargs.get('schema')
|
schema = kwargs.get('schema')
|
||||||
table = kwargs.get('table')
|
table = kwargs.get('table')
|
||||||
template_path = kwargs.get('template_path', None)
|
template_path = kwargs.get('template_path', None)
|
||||||
|
|
||||||
if plid is not None:
|
if plid is not None:
|
||||||
sql = render_template("/".join([template_path, 'properties.sql']),
|
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)
|
status, res = conn.execute_dict(sql)
|
||||||
if not status:
|
if not status:
|
||||||
return internal_server_error(errormsg=res)
|
return internal_server_error(errormsg=res)
|
||||||
@@ -110,12 +112,14 @@ def get_reverse_engineered_sql(conn, **kwargs):
|
|||||||
table = kwargs.get('table')
|
table = kwargs.get('table')
|
||||||
scid = kwargs.get('scid')
|
scid = kwargs.get('scid')
|
||||||
plid = kwargs.get('plid')
|
plid = kwargs.get('plid')
|
||||||
|
policy_table_id = kwargs.get('policy_table_id')
|
||||||
datlastsysoid = kwargs.get('datlastsysoid')
|
datlastsysoid = kwargs.get('datlastsysoid')
|
||||||
template_path = kwargs.get('template_path', None)
|
template_path = kwargs.get('template_path', None)
|
||||||
with_header = kwargs.get('with_header', True)
|
with_header = kwargs.get('with_header', True)
|
||||||
|
|
||||||
SQL = render_template("/".join(
|
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)
|
status, res = conn.execute_dict(SQL)
|
||||||
if not status:
|
if not status:
|
||||||
@@ -130,6 +134,7 @@ def get_reverse_engineered_sql(conn, **kwargs):
|
|||||||
data['table'] = table
|
data['table'] = table
|
||||||
|
|
||||||
SQL, name = get_sql(conn, data=data, scid=scid, plid=None,
|
SQL, name = get_sql(conn, data=data, scid=scid, plid=None,
|
||||||
|
policy_table_id=policy_table_id,
|
||||||
datlastsysoid=datlastsysoid, schema=schema,
|
datlastsysoid=datlastsysoid, schema=schema,
|
||||||
table=table)
|
table=table)
|
||||||
if with_header:
|
if with_header:
|
||||||
|
|||||||
@@ -13,9 +13,10 @@ FROM
|
|||||||
pg_policy pl
|
pg_policy pl
|
||||||
JOIN pg_policies rw ON pl.polname=rw.policyname
|
JOIN pg_policies rw ON pl.polname=rw.policyname
|
||||||
JOIN pg_namespace n ON n.nspname=rw.schemaname
|
JOIN pg_namespace n ON n.nspname=rw.schemaname
|
||||||
|
JOIN pg_class rel on rel.relname=rw.tablename
|
||||||
WHERE
|
WHERE
|
||||||
{% if plid %}
|
{% if plid %}
|
||||||
pl.oid = {{ plid }} and n.oid = {{ scid }};
|
pl.oid = {{ plid }} and n.oid = {{ scid }} and rel.relfilenode = {{ policy_table_id }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if tid %}
|
{% if tid %}
|
||||||
pl.polrelid = {{ tid }};
|
pl.polrelid = {{ tid }};
|
||||||
|
|||||||
@@ -12,9 +12,10 @@ FROM
|
|||||||
pg_policy pl
|
pg_policy pl
|
||||||
JOIN pg_policies rw ON pl.polname=rw.policyname
|
JOIN pg_policies rw ON pl.polname=rw.policyname
|
||||||
JOIN pg_namespace n ON n.nspname=rw.schemaname
|
JOIN pg_namespace n ON n.nspname=rw.schemaname
|
||||||
|
JOIN pg_class rel on rel.relname=rw.tablename
|
||||||
WHERE
|
WHERE
|
||||||
{% if plid %}
|
{% if plid %}
|
||||||
pl.oid = {{ plid }} and n.oid = {{ scid }};
|
pl.oid = {{ plid }} and n.oid = {{ scid }} and rel.relfilenode = {{ policy_table_id }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if tid %}
|
{% if tid %}
|
||||||
pl.polrelid = {{ tid }};
|
pl.polrelid = {{ tid }};
|
||||||
|
|||||||
@@ -12,9 +12,10 @@ FROM
|
|||||||
pg_policy pl
|
pg_policy pl
|
||||||
JOIN pg_policies rw ON pl.polname=rw.policyname
|
JOIN pg_policies rw ON pl.polname=rw.policyname
|
||||||
JOIN pg_namespace n ON n.nspname=rw.schemaname
|
JOIN pg_namespace n ON n.nspname=rw.schemaname
|
||||||
|
JOIN pg_class rel on rel.relname=rw.tablename
|
||||||
WHERE
|
WHERE
|
||||||
{% if plid %}
|
{% if plid %}
|
||||||
pl.oid = {{ plid }} and n.oid = {{ scid }};
|
pl.oid = {{ plid }} and n.oid = {{ scid }} and rel.relfilenode = {{ policy_table_id }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if tid %}
|
{% if tid %}
|
||||||
pl.polrelid = {{ tid }};
|
pl.polrelid = {{ tid }};
|
||||||
|
|||||||
@@ -547,7 +547,8 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
|
|||||||
policy_sql = row_security_policies_utils. \
|
policy_sql = row_security_policies_utils. \
|
||||||
get_reverse_engineered_sql(
|
get_reverse_engineered_sql(
|
||||||
self.conn, schema=schema, table=table, scid=scid,
|
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)
|
template_path=None, with_header=json_resp)
|
||||||
policy_sql = "\n" + policy_sql
|
policy_sql = "\n" + policy_sql
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user