diff --git a/docs/en_US/release_notes_4_24.rst b/docs/en_US/release_notes_4_24.rst index bd12cd5c1..a277124f5 100644 --- a/docs/en_US/release_notes_4_24.rst +++ b/docs/en_US/release_notes_4_24.rst @@ -19,4 +19,5 @@ Bug fixes ********* | `Issue #3851 `_ - Add proper indentation to the code while generating functions, procedures, and trigger functions. +| `Issue #5621 `_ - Remove extra brackets from reverse engineering SQL of RLS Policy. | `Issue #5630 `_ - Fixed an issue where installation of pgadmin4 not working on 32-bit Windows. \ No newline at end of file diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/utils.py index 306823229..d2a2d4339 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/utils.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/utils.py @@ -186,6 +186,16 @@ def get_sql(conn, data, did, tid, idx, datlastsysoid, raise ObjectGone(_('Could not find the index in the table.')) old_data = dict(res['rows'][0]) + # Remove opening and closing bracket as we already have in jinja + # template. + if 'using' in old_data and old_data['using'] is not None and \ + old_data['using'].startswith('(') and \ + old_data['using'].endswith(')'): + old_data['using'] = old_data['using'][1:-1] + if 'withcheck' in old_data and old_data['withcheck'] is not None and \ + old_data['withcheck'].startswith('(') and \ + old_data['withcheck'].endswith(')'): + old_data['withcheck'] = old_data['withcheck'][1:-1] # If name is not present in data then # we will fetch it from old data, we also need schema & table name diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/row_security_policies/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/row_security_policies/__init__.py index 65dc046d3..86a724170 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/row_security_policies/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/row_security_policies/__init__.py @@ -326,9 +326,17 @@ class RowSecurityView(PGChildNodeView): data = dict(res['rows'][0]) - res = data + # Remove opening and closing bracket as we already have in jinja + # template. + if 'using' in data and data['using'] is not None and \ + data['using'].startswith('(') and data['using'].endswith(')'): + data['using'] = data['using'][1:-1] + if 'withcheck' in data and data['withcheck'] is not None and \ + data['withcheck'].startswith('(') and \ + data['withcheck'].endswith(')'): + data['withcheck'] = data['withcheck'][1:-1] - return True, res + return True, data @check_precondition def create(self, gid, sid, did, scid, tid): @@ -527,15 +535,10 @@ class RowSecurityView(PGChildNodeView): """ This function will generate sql to render into the sql panel """ - sql = render_template("/".join( - [self.template_path, 'properties.sql']), plid=plid) - status, res = self.conn.execute_dict(sql) + status, res_data = self._fetch_properties(plid) if not status: - return internal_server_error(errormsg=res) - if len(res['rows']) == 0: - return gone(gettext("""Could not find the policy in the table.""")) - res = dict(res['rows'][0]) - res_data = res + return res_data + res_data['schema'] = self.schema res_data['table'] = self.table diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/row_security_policies/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/row_security_policies/utils.py index f61eadca1..11c509759 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/row_security_policies/utils.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/row_security_policies/utils.py @@ -70,16 +70,15 @@ def get_sql(conn, data, did, tid, plid, datlastsysoid, schema, table, if plid is not None: sql = render_template("/".join( [template_path, 'properties.sql']), plid=plid) + status, res = conn.execute_dict(sql) if not status: return internal_server_error(errormsg=res) + if len(res['rows']) == 0: raise ObjectGone(_('Could not find the index in the table.')) - res_data = dict(res['rows'][0]) - res = res_data - - old_data = res + old_data = dict(res['rows'][0]) old_data['schema'] = schema old_data['table'] = table sql = render_template( @@ -91,6 +90,7 @@ def get_sql(conn, data, did, tid, plid, datlastsysoid, schema, table, data['table'] = table sql = render_template("/".join( [template_path, 'create.sql']), data=data) + return sql, data['name'] if 'name' in data else old_data['name'] diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/row_security_policies/sql/9.5_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/row_security_policies/sql/9.5_plus/properties.sql index a83ca056c..2818640e7 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/row_security_policies/sql/9.5_plus/properties.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/row_security_policies/sql/9.5_plus/properties.sql @@ -15,5 +15,3 @@ WHERE {% if tid %} pl.polrelid = {{ tid }} {% endif %}; - -