Resolved few issues (with some improvements) with existing nodes.

This commit takes care of the following issues/improvements.
* Adding missing imports for unauthorised in database module
* Node under Servers Nodes (i.e. Databases, tablespaces, roles nodes)
  need to be inherited from PGChildNodeView (and, not from NodeView) for
  adding server version check for their children.
* Adding statistics for database, and tablespaces in its node (not, yet
  in UI)
* Renaming the camel case methods with proper name.
  (i.e. getSQL -> get_sql, getNewSQL -> get_new_sql, etc.)
* Fixed the functions going beyond the text limit (column: 80) in
  Databases, Roles & Tablespaces modules.
* Fixed the node method of Database module, which was not tested ever.
* We do not need separate SQL template for fetching the name (i.e.
  get_name.sql), using the 'nodes.sql' for the same.
* Optimise the query for fetching ACLs for the database node, we didn't
  require to join certain tables, while fetching only the ACLs.
* Introduced the list of the ACLs (regular and default ACLs for
  different type) supported by each version [Databases Module].
* Renamed the templates 'get_nodes.sql' to' nodes.sql' to make it
  consistent with other modules.
* Removed the checks for the authentication table use, as we don't need
  to expose the password to the users (even the encrypted MD5). Using
  the pg_roles view always for fetching roles/users information now.
* Resolved some typos in unreachable (specially the exceptions
  catchment area.)
* Logging the exception in the application.
* Using qtLiteral, qtIdent properly in the templates (do not assume
  about the types of data.)
* Using tsid as identifier instead of did for the tablespaces.
* Using nodes method of tablespace view for fetching individual node
  information.
* Removing the hardcoded node information from the 'parse_priv_to_db'
  function, and pass on allowed ACLs by the caller nodes.
* Using 'nodes.sql' to fetch name of the template instead of writing
  that in the delete.sql template, which is definitely wrong place to
  fetch the name of the object. [Tablespace Module]
This commit is contained in:
Ashesh Vashi
2016-02-22 11:44:24 +05:30
parent 9274d87c55
commit d5da26876b
50 changed files with 694 additions and 374 deletions

View File

@@ -33,7 +33,7 @@ def parse_priv_from_db(db_privileges):
return acl
def parse_priv_to_db(str_privileges, object_type = None):
def parse_priv_to_db(str_privileges, allowed_acls = []):
"""
Common utility function to parse privileges before sending to database.
"""
@@ -51,18 +51,22 @@ def parse_priv_to_db(str_privileges, object_type = None):
'U': 'USAGE',
'X': 'EXECUTE'
}
privileges_max_cnt = {
'DATABASE': 3,
'TABLESPACE': 2,
'SCHEMA': 2
}
privileges = []
allowed_acls_len = len(allowed_acls)
for priv in str_privileges:
priv_with_grant = []
priv_without_grant = []
for privilege in priv['privileges']:
if privilege['privilege_type'] not in db_privileges:
continue
if privilege['privilege_type'] not in allowed_acls:
continue
if privilege['with_grant']:
priv_with_grant.append(
db_privileges[privilege['privilege_type']]
@@ -72,19 +76,15 @@ def parse_priv_to_db(str_privileges, object_type = None):
db_privileges[privilege['privilege_type']]
)
if object_type in ("DATABASE", "SCHEMA", "TABLESPACE"):
priv_with_grant = ", ".join(priv_with_grant) if (
len(priv_with_grant) < privileges_max_cnt[object_type.upper()]
) else 'ALL'
priv_without_grant = ", ".join(priv_without_grant) if (
len(priv_without_grant) < privileges_max_cnt[object_type.upper()]
) else 'ALL'
else:
priv_with_grant = ", ".join(priv_with_grant)
priv_without_grant = ", ".join(priv_without_grant)
priv_with_grant = ", ".join(priv_with_grant) \
if len(priv_with_grant) < allowed_acls_len else 'ALL'
priv_without_grant = ", ".join(priv_without_grant) \
if len(priv_without_grant) < allowed_acls_len else 'ALL'
privileges.append({'grantee': priv['grantee'],
'with_grant': priv_with_grant,
'without_grant': priv_without_grant})
privileges.append({
'grantee': priv['grantee'],
'with_grant': priv_with_grant,
'without_grant': priv_without_grant
})
return privileges