Revert "Handle comments on databases with datallowconn=False correctly. Fixes #2024"
This reverts commit e431eb9d8e
.
pull/3/head
parent
ff199f4582
commit
ac4178233b
|
@ -134,17 +134,9 @@ class DatabaseView(PGChildNodeView):
|
||||||
self.conn = self.manager.connection()
|
self.conn = self.manager.connection()
|
||||||
elif 'did' in kwargs:
|
elif 'did' in kwargs:
|
||||||
self.conn = self.manager.connection(did=kwargs['did'])
|
self.conn = self.manager.connection(did=kwargs['did'])
|
||||||
|
|
||||||
# If connection to database is not allowed then
|
|
||||||
# provide generic connection
|
|
||||||
if kwargs['did'] in self.conn.manager.db_info:
|
|
||||||
self._db = self.conn.manager.db_info[kwargs['did']]
|
|
||||||
if self._db['datallowconn'] is False:
|
|
||||||
self.conn = self.manager.connection()
|
|
||||||
else:
|
else:
|
||||||
self.conn = self.manager.connection()
|
self.conn = self.manager.connection()
|
||||||
|
|
||||||
|
|
||||||
ver = self.manager.version
|
ver = self.manager.version
|
||||||
# we will set template path for sql scripts
|
# we will set template path for sql scripts
|
||||||
if ver >= 90300:
|
if ver >= 90300:
|
||||||
|
@ -567,8 +559,8 @@ class DatabaseView(PGChildNodeView):
|
||||||
if 'name' not in data:
|
if 'name' not in data:
|
||||||
data['name'] = data['old_name']
|
data['name'] = data['old_name']
|
||||||
|
|
||||||
|
status = self.manager.release(did=did)
|
||||||
for action in ["rename_database", "tablespace"]:
|
for action in ["rename_database", "tablespace"]:
|
||||||
status = self.manager.release(did=did)
|
|
||||||
SQL = self.get_offline_sql(gid, sid, data, did, action)
|
SQL = self.get_offline_sql(gid, sid, data, did, action)
|
||||||
SQL = SQL.strip('\n').strip(' ')
|
SQL = SQL.strip('\n').strip(' ')
|
||||||
if SQL and SQL != "":
|
if SQL and SQL != "":
|
||||||
|
@ -576,6 +568,21 @@ class DatabaseView(PGChildNodeView):
|
||||||
if not status:
|
if not status:
|
||||||
return internal_server_error(errormsg=msg)
|
return internal_server_error(errormsg=msg)
|
||||||
|
|
||||||
|
if not self.manager.db_info[did]['datallowconn']:
|
||||||
|
return jsonify(
|
||||||
|
node=self.blueprint.generate_browser_node(
|
||||||
|
did,
|
||||||
|
sid,
|
||||||
|
data['name'],
|
||||||
|
"icon-database-not-connected",
|
||||||
|
connected=False,
|
||||||
|
allowConn=False
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.conn = self.manager.connection(database=data['name'], auto_reconnect=True)
|
||||||
|
status, errmsg = self.conn.connect()
|
||||||
|
|
||||||
SQL = self.get_online_sql(gid, sid, data, did)
|
SQL = self.get_online_sql(gid, sid, data, did)
|
||||||
SQL = SQL.strip('\n').strip(' ')
|
SQL = SQL.strip('\n').strip(' ')
|
||||||
if SQL and SQL != "":
|
if SQL and SQL != "":
|
||||||
|
@ -588,11 +595,7 @@ class DatabaseView(PGChildNodeView):
|
||||||
did,
|
did,
|
||||||
sid,
|
sid,
|
||||||
data['name'],
|
data['name'],
|
||||||
"pg-icon-{0}".format(self.node_type) if
|
"pg-icon-{0}".format(self.node_type)
|
||||||
self._db['datallowconn'] else
|
|
||||||
"icon-database-not-connected",
|
|
||||||
connected=False,
|
|
||||||
allowConn=False
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -636,6 +639,7 @@ class DatabaseView(PGChildNodeView):
|
||||||
|
|
||||||
return internal_server_error(errormsg=msg)
|
return internal_server_error(errormsg=msg)
|
||||||
|
|
||||||
|
|
||||||
return make_json_response(success=1)
|
return make_json_response(success=1)
|
||||||
|
|
||||||
@check_precondition(action="msql")
|
@check_precondition(action="msql")
|
||||||
|
@ -689,7 +693,8 @@ class DatabaseView(PGChildNodeView):
|
||||||
for action in ["rename_database", "tablespace"]:
|
for action in ["rename_database", "tablespace"]:
|
||||||
SQL += self.get_offline_sql(gid, sid, data, did, action)
|
SQL += self.get_offline_sql(gid, sid, data, did, action)
|
||||||
|
|
||||||
SQL += self.get_online_sql(gid, sid, data, did)
|
if rset['rows'][0]['datallowconn']:
|
||||||
|
SQL += self.get_online_sql(gid, sid, data, did)
|
||||||
else:
|
else:
|
||||||
SQL += self.get_new_sql(gid, sid, data, did)
|
SQL += self.get_new_sql(gid, sid, data, did)
|
||||||
|
|
||||||
|
@ -710,30 +715,33 @@ class DatabaseView(PGChildNodeView):
|
||||||
acls = []
|
acls = []
|
||||||
SQL_acl = ''
|
SQL_acl = ''
|
||||||
|
|
||||||
try:
|
if ('datallowconn' in data and data['datallowconn']) or \
|
||||||
acls = render_template(
|
'datallowconn' not in data:
|
||||||
"/".join([self.template_path, 'allowed_privs.json'])
|
try:
|
||||||
)
|
acls = render_template(
|
||||||
acls = json.loads(acls, encoding='utf-8')
|
"/".join([self.template_path, 'allowed_privs.json'])
|
||||||
except Exception as e:
|
|
||||||
current_app.logger.exception(e)
|
|
||||||
|
|
||||||
# Privileges
|
|
||||||
for aclcol in acls:
|
|
||||||
if aclcol in data:
|
|
||||||
allowedacl = acls[aclcol]
|
|
||||||
data[aclcol] = parse_priv_to_db(
|
|
||||||
data[aclcol], allowedacl['acl']
|
|
||||||
)
|
)
|
||||||
|
acls = json.loads(acls, encoding='utf-8')
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.exception(e)
|
||||||
|
|
||||||
SQL_acl = render_template(
|
# Privileges
|
||||||
"/".join([self.template_path, 'grant.sql']),
|
for aclcol in acls:
|
||||||
data=data, conn=self.conn
|
if aclcol in data:
|
||||||
)
|
allowedacl = acls[aclcol]
|
||||||
|
data[aclcol] = parse_priv_to_db(
|
||||||
|
data[aclcol], allowedacl['acl']
|
||||||
|
)
|
||||||
|
|
||||||
|
SQL_acl = render_template(
|
||||||
|
"/".join([self.template_path, 'grant.sql']),
|
||||||
|
data=data, conn=self.conn
|
||||||
|
)
|
||||||
|
|
||||||
|
conn = self.manager.connection()
|
||||||
SQL = render_template(
|
SQL = render_template(
|
||||||
"/".join([self.template_path, 'create.sql']),
|
"/".join([self.template_path, 'create.sql']),
|
||||||
data=data, conn=self.conn
|
data=data, conn=conn
|
||||||
)
|
)
|
||||||
SQL += "\n"
|
SQL += "\n"
|
||||||
SQL += SQL_acl
|
SQL += SQL_acl
|
||||||
|
@ -839,44 +847,46 @@ class DatabaseView(PGChildNodeView):
|
||||||
if not status:
|
if not status:
|
||||||
return internal_server_error(errormsg=res)
|
return internal_server_error(errormsg=res)
|
||||||
|
|
||||||
SQL = render_template(
|
if res['rows'][0]['datallowconn']:
|
||||||
"/".join([self.template_path, 'acl.sql']),
|
SQL = render_template(
|
||||||
did=did, conn=self.conn
|
"/".join([self.template_path, 'acl.sql']),
|
||||||
)
|
did=did, conn=self.conn
|
||||||
status, dataclres = self.conn.execute_dict(SQL)
|
)
|
||||||
if not status:
|
status, dataclres = self.conn.execute_dict(SQL)
|
||||||
return internal_server_error(errormsg=dataclres)
|
if not status:
|
||||||
res = self.formatdbacl(res, dataclres['rows'])
|
return internal_server_error(errormsg=dataclres)
|
||||||
|
res = self.formatdbacl(res, dataclres['rows'])
|
||||||
|
|
||||||
SQL = render_template(
|
SQL = render_template(
|
||||||
"/".join([self.template_path, 'defacl.sql']),
|
"/".join([self.template_path, 'defacl.sql']),
|
||||||
did=did, conn=self.conn
|
did=did, conn=self.conn
|
||||||
)
|
)
|
||||||
status, defaclres = self.conn.execute_dict(SQL)
|
status, defaclres = self.conn.execute_dict(SQL)
|
||||||
if not status:
|
if not status:
|
||||||
return internal_server_error(errormsg=defaclres)
|
return internal_server_error(errormsg=defaclres)
|
||||||
|
|
||||||
res = self.formatdbacl(res, defaclres['rows'])
|
res = self.formatdbacl(res, defaclres['rows'])
|
||||||
|
|
||||||
result = res['rows'][0]
|
result = res['rows'][0]
|
||||||
|
|
||||||
SQL = render_template(
|
if result['datallowconn']:
|
||||||
"/".join([self.template_path, 'get_variables.sql']),
|
SQL = render_template(
|
||||||
did=did, conn=self.conn
|
"/".join([self.template_path, 'get_variables.sql']),
|
||||||
)
|
did=did, conn=self.conn
|
||||||
status, res1 = self.conn.execute_dict(SQL)
|
)
|
||||||
if not status:
|
status, res1 = self.conn.execute_dict(SQL)
|
||||||
return internal_server_error(errormsg=res1)
|
if not status:
|
||||||
|
return internal_server_error(errormsg=res1)
|
||||||
|
|
||||||
# Get Formatted Security Labels
|
# Get Formatted Security Labels
|
||||||
if 'seclabels' in result:
|
if 'seclabels' in result:
|
||||||
# Security Labels is not available for PostgreSQL <= 9.1
|
# Security Labels is not available for PostgreSQL <= 9.1
|
||||||
frmtd_sec_labels = parse_sec_labels_from_db(result['seclabels'])
|
frmtd_sec_labels = parse_sec_labels_from_db(result['seclabels'])
|
||||||
result.update(frmtd_sec_labels)
|
result.update(frmtd_sec_labels)
|
||||||
|
|
||||||
# Get Formatted Variables
|
# Get Formatted Variables
|
||||||
frmtd_variables = parse_variables_from_db(res1['rows'])
|
frmtd_variables = parse_variables_from_db(res1['rows'])
|
||||||
result.update(frmtd_variables)
|
result.update(frmtd_variables)
|
||||||
|
|
||||||
sql_header = "-- Database: {0}\n\n-- ".format(result['name'])
|
sql_header = "-- Database: {0}\n\n-- ".format(result['name'])
|
||||||
if hasattr(str, 'decode'):
|
if hasattr(str, 'decode'):
|
||||||
|
|
Loading…
Reference in New Issue