public inbox for [email protected]
help / color / mirror / Atom feedFrom: Akshay Joshi <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin4][Patch]: RM 4389 "string indices must be integers" error displayed if select Privileges for Columns
Date: Thu, 11 Jul 2019 18:56:24 +0530
Message-ID: <CANxoLDfzBv8o84VyBWOjTEjZKGJ+TvYVG1u9-P4Prr99-nbGAA@mail.gmail.com> (raw)
Hi Hackers,
Attached is the patch to fix RM 4389 "string indices must be integers"
error displayed if select Privileges for Columns. Added API test case for
the scenario.
Please review it.
--
*Thanks & Regards*
*Akshay Joshi*
*Sr. Software Architect*
*EnterpriseDB Software India Private Limited*
*Mobile: +91 976-788-8246*
Attachments:
[application/octet-stream] RM_4389.patch (14.3K, 3-RM_4389.patch)
download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
index d2354f37..f694396b 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
@@ -905,10 +905,18 @@ class TableView(BaseTableView, DataTypeReader, VacuumSettings):
for c in final_columns:
if 'attacl' in c:
- c['attacl'] = parse_priv_to_db(
- c['attacl'], self.column_acl
- )
-
+ if 'added' in c['attacl']:
+ c['attacl']['added'] = parse_priv_to_db(
+ c['attacl']['added'], self.column_acl
+ )
+ elif 'changed' in c['attacl']:
+ c['attacl']['changed'] = parse_priv_to_db(
+ c['attacl']['changed'], self.column_acl
+ )
+ elif 'deleted' in c['attacl']:
+ c['attacl']['deleted'] = parse_priv_to_db(
+ c['attacl']['deleted'], self.column_acl
+ )
if 'cltype' in c:
# check type for '[]' in it
c['cltype'], c['hasSqrBracket'] = \
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/10_plus/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/10_plus/update.sql
index eea328db..7cd40fc9 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/10_plus/update.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/10_plus/update.sql
@@ -131,29 +131,29 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
{% if 'deleted' in data.attacl %}
{% for priv in data.attacl.deleted %}
{% if data.name %}
- {{ PRIVILEGE.RESETALL(conn, data.schema, data.table, data.name, priv.grantee) }}
+{{ PRIVILEGE.RESETALL(conn, data.schema, data.table, data.name, priv.grantee) }}
{% else %}
- {{ PRIVILEGE.RESETALL(conn, data.schema, data.table, o_data.name, priv.grantee) }}
+{{ PRIVILEGE.RESETALL(conn, data.schema, data.table, o_data.name, priv.grantee) }}
{% endif %}
{% endfor %}
{% endif %}
{% if 'changed' in data.attacl %}
{% for priv in data.attacl.changed %}
{% if data.name %}
- {{ PRIVILEGE.RESETALL(conn, data.schema, data.table, data.name, priv.grantee) }}
- {{ PRIVILEGE.APPLY(conn, data.schema, data.table, data.name, priv.grantee, priv.without_grant, priv.with_grant) }}
+{{ PRIVILEGE.RESETALL(conn, data.schema, data.table, data.name, priv.grantee) }}
+{{ PRIVILEGE.APPLY(conn, data.schema, data.table, data.name, priv.grantee, priv.without_grant, priv.with_grant) }}
{% else %}
- {{ PRIVILEGE.RESETALL(conn, data.schema, data.table, o_data.name, priv.grantee) }}
- {{ PRIVILEGE.APPLY(conn, data.schema, data.table, o_data.name, priv.grantee, priv.without_grant, priv.with_grant) }}
+{{ PRIVILEGE.RESETALL(conn, data.schema, data.table, o_data.name, priv.grantee) }}
+{{ PRIVILEGE.APPLY(conn, data.schema, data.table, o_data.name, priv.grantee, priv.without_grant, priv.with_grant) }}
{% endif %}
{% endfor %}
{% endif %}
{% if 'added' in data.attacl %}
{% for priv in data.attacl.added %}
{% if data.name %}
- {{ PRIVILEGE.APPLY(conn, data.schema, data.table, data.name, priv.grantee, priv.without_grant, priv.with_grant) }}
+{{ PRIVILEGE.APPLY(conn, data.schema, data.table, data.name, priv.grantee, priv.without_grant, priv.with_grant) }}
{% else %}
- {{ PRIVILEGE.APPLY(conn, data.schema, data.table, o_data.name, priv.grantee, priv.without_grant, priv.with_grant) }}
+{{ PRIVILEGE.APPLY(conn, data.schema, data.table, o_data.name, priv.grantee, priv.without_grant, priv.with_grant) }}
{% endif %}
{% endfor %}
{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/9.2_plus/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/9.2_plus/update.sql
index 806fb37e..d92d0112 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/9.2_plus/update.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/9.2_plus/update.sql
@@ -89,29 +89,29 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}}
{% if 'deleted' in data.attacl %}
{% for priv in data.attacl.deleted %}
{% if data.name %}
- {{ PRIVILEGE.RESETALL(conn, data.schema, data.table, data.name, priv.grantee) }}
+{{ PRIVILEGE.RESETALL(conn, data.schema, data.table, data.name, priv.grantee) }}
{% else %}
- {{ PRIVILEGE.RESETALL(conn, data.schema, data.table, o_data.name, priv.grantee) }}
+{{ PRIVILEGE.RESETALL(conn, data.schema, data.table, o_data.name, priv.grantee) }}
{% endif %}
{% endfor %}
{% endif %}
{% if 'changed' in data.attacl %}
{% for priv in data.attacl.changed %}
{% if data.name %}
- {{ PRIVILEGE.RESETALL(conn, data.schema, data.table, data.name, priv.grantee) }}
- {{ PRIVILEGE.APPLY(conn, data.schema, data.table, data.name, priv.grantee, priv.without_grant, priv.with_grant) }}
+{{ PRIVILEGE.RESETALL(conn, data.schema, data.table, data.name, priv.grantee) }}
+{{ PRIVILEGE.APPLY(conn, data.schema, data.table, data.name, priv.grantee, priv.without_grant, priv.with_grant) }}
{% else %}
- {{ PRIVILEGE.RESETALL(conn, data.schema, data.table, o_data.name, priv.grantee) }}
- {{ PRIVILEGE.APPLY(conn, data.schema, data.table, o_data.name, priv.grantee, priv.without_grant, priv.with_grant) }}
+{{ PRIVILEGE.RESETALL(conn, data.schema, data.table, o_data.name, priv.grantee) }}
+{{ PRIVILEGE.APPLY(conn, data.schema, data.table, o_data.name, priv.grantee, priv.without_grant, priv.with_grant) }}
{% endif %}
{% endfor %}
{% endif %}
{% if 'added' in data.attacl %}
{% for priv in data.attacl.added %}
{% if data.name %}
- {{ PRIVILEGE.APPLY(conn, data.schema, data.table, data.name, priv.grantee, priv.without_grant, priv.with_grant) }}
+{{ PRIVILEGE.APPLY(conn, data.schema, data.table, data.name, priv.grantee, priv.without_grant, priv.with_grant) }}
{% else %}
- {{ PRIVILEGE.APPLY(conn, data.schema, data.table, o_data.name, priv.grantee, priv.without_grant, priv.with_grant) }}
+{{ PRIVILEGE.APPLY(conn, data.schema, data.table, o_data.name, priv.grantee, priv.without_grant, priv.with_grant) }}
{% endif %}
{% endfor %}
{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/10_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/10_plus/create.sql
index ab79d2e6..1f4c8387 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/10_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/10_plus/create.sql
@@ -145,7 +145,7 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}}
{% if c.attacl and c.attacl|length > 0 %}
{% for priv in c.attacl %}
- {{ COLUMN_PRIVILEGE.APPLY(conn, data.schema, data.name, c.name, priv.grantee, priv.without_grant, priv.with_grant) }}
+{{ COLUMN_PRIVILEGE.APPLY(conn, data.schema, data.name, c.name, priv.grantee, priv.without_grant, priv.with_grant) }}
{% endfor %}
{% endif %}
{### Security Lables ###}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/12_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/12_plus/create.sql
index f4daa2cc..7acbd008 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/12_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/12_plus/create.sql
@@ -157,7 +157,7 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.name)}}
{% if c.attacl and c.attacl|length > 0 %}
{% for priv in c.attacl %}
- {{ COLUMN_PRIVILEGE.APPLY(conn, data.schema, data.name, c.name, priv.grantee, priv.without_grant, priv.with_grant) }}
+{{ COLUMN_PRIVILEGE.APPLY(conn, data.schema, data.name, c.name, priv.grantee, priv.without_grant, priv.with_grant) }}
{% endfor %}
{% endif %}
{### Security Lables ###}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_column_privileges_put.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_column_privileges_put.py
new file mode 100644
index 00000000..1c587786
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_column_privileges_put.py
@@ -0,0 +1,96 @@
+##########################################################################
+#
+# pgAdmin 4 - PostgreSQL Tools
+#
+# Copyright (C) 2013 - 2019, The pgAdmin Development Team
+# This software is released under the PostgreSQL Licence
+#
+##########################################################################
+
+import json
+import uuid
+
+from pgadmin.browser.server_groups.servers.databases.schemas.tests import \
+ utils as schema_utils
+from pgadmin.browser.server_groups.servers.databases.tests import utils as \
+ database_utils
+from pgadmin.utils.route import BaseTestGenerator
+from regression import parent_node_dict
+from regression.python_test_utils import test_utils as utils
+from . import utils as tables_utils
+
+
+class TableUpdateColumnTestCase(BaseTestGenerator):
+ """This class will update the column node from table"""
+ scenarios = [
+ # Fetching default URL for table node.
+ ('Add privileges for existing column',
+ dict(url='/browser/table/obj/')
+ )
+ ]
+
+ def setUp(self):
+ self.db_name = parent_node_dict["database"][-1]["db_name"]
+ schema_info = parent_node_dict["schema"][-1]
+ self.server_id = schema_info["server_id"]
+ self.db_id = schema_info["db_id"]
+ db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
+ self.server_id, self.db_id)
+ if not db_con['data']["connected"]:
+ raise Exception("Could not connect to database to add a table.")
+ self.schema_id = schema_info["schema_id"]
+ self.schema_name = schema_info["schema_name"]
+ schema_response = schema_utils.verify_schemas(self.server,
+ self.db_name,
+ self.schema_name)
+ if not schema_response:
+ raise Exception("Could not find the schema to add a table.")
+ self.table_name = "test_table_column_put_%s" % (str(uuid.uuid4())[1:8])
+
+ self.table_id = tables_utils.create_table(
+ self.server, self.db_name,
+ self.schema_name,
+ self.table_name)
+
+ def runTest(self):
+ """This function will fetch added table under schema node."""
+ table_response = tables_utils.verify_table(self.server, self.db_name,
+ self.table_id)
+ if not table_response:
+ raise Exception("Could not find the table to update.")
+
+ data = {
+ "columns": {
+ "changed": [{
+ "attnum": 1,
+ "attacl": {
+ "added": [{
+ "grantee": self.server["username"],
+ "grantor": self.server["username"],
+ "privileges": [
+ {"privilege_type": "a", "privilege": True,
+ "with_grant": True},
+ {"privilege_type": "r", "privilege": True,
+ "with_grant": True},
+ {"privilege_type": "w", "privilege": True,
+ "with_grant": True},
+ {"privilege_type": "x", "privilege": True,
+ "with_grant": True
+ }
+ ]
+ }]
+ }
+ }]
+ }
+ }
+
+ response = self.tester.put(
+ self.url + str(utils.SERVER_GROUP) + '/' +
+ str(self.server_id) + '/' + str(self.db_id) + '/' +
+ str(self.schema_id) + '/' + str(self.table_id),
+ data=json.dumps(data), follow_redirects=True)
+ self.assertEquals(response.status_code, 200)
+
+ def tearDown(self):
+ # Disconnect the database
+ database_utils.disconnect_database(self, self.server_id, self.db_id)
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py
index bd3ba21e..078ba281 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py
@@ -1750,9 +1750,6 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
for c in columns['changed']:
c['schema'] = data['schema']
c['table'] = data['name']
- if 'attacl' in c:
- c['attacl'] = parse_priv_to_db(c['attacl'],
- self.column_acl)
properties_sql = render_template(
"/".join([self.column_template_path,
@@ -1856,10 +1853,6 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
for c in columns['added']:
c['schema'] = data['schema']
c['table'] = data['name']
- # Sql for create column
- if 'attacl' in c:
- c['attacl'] = parse_priv_to_db(c['attacl'],
- self.column_acl)
c = BaseTableView.convert_length_precision_to_string(c)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: [pgAdmin4][Patch]: RM 4389 "string indices must be integers" error displayed if select Privileges for Columns
In-Reply-To: <CANxoLDfzBv8o84VyBWOjTEjZKGJ+TvYVG1u9-P4Prr99-nbGAA@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox