mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Fixed cognitive complexity issues reported by SonarQube.
This commit is contained in:
committed by
Akshay Joshi
parent
e6bd085c15
commit
7f947f146c
@@ -542,27 +542,11 @@ def _get_logout_url():
|
|||||||
url_for('security.logout'), url_for(BROWSER_INDEX))
|
url_for('security.logout'), url_for(BROWSER_INDEX))
|
||||||
|
|
||||||
|
|
||||||
@blueprint.route("/")
|
def _get_supported_browser():
|
||||||
@pgCSRFProtect.exempt
|
"""
|
||||||
@login_required
|
This function return supported browser.
|
||||||
def index():
|
:return: browser name, browser known, browser version
|
||||||
"""Render and process the main browser window."""
|
"""
|
||||||
# Register Gravatar module with the app only if required
|
|
||||||
if config.SHOW_GRAVATAR_IMAGE:
|
|
||||||
Gravatar(
|
|
||||||
current_app,
|
|
||||||
size=100,
|
|
||||||
rating='g',
|
|
||||||
default='retro',
|
|
||||||
force_default=False,
|
|
||||||
use_ssl=True,
|
|
||||||
base_url=None
|
|
||||||
)
|
|
||||||
|
|
||||||
# Check the browser is a support version
|
|
||||||
# NOTE: If the checks here are updated, make sure the supported versions
|
|
||||||
# at https://www.pgadmin.org/faq/#11 are updated to match!
|
|
||||||
if config.CHECK_SUPPORTED_BROWSER:
|
|
||||||
browser = request.user_agent.browser
|
browser = request.user_agent.browser
|
||||||
version = request.user_agent.version and int(
|
version = request.user_agent.version and int(
|
||||||
request.user_agent.version.split('.')[0])
|
request.user_agent.version.split('.')[0])
|
||||||
@@ -594,19 +578,14 @@ def index():
|
|||||||
browser_name = browser
|
browser_name = browser
|
||||||
browser_known = False
|
browser_known = False
|
||||||
|
|
||||||
if browser_name is not None:
|
return browser_name, browser_known, version
|
||||||
msg = render_template(
|
|
||||||
MODULE_NAME + "/browser.html",
|
|
||||||
version=version,
|
|
||||||
browser=browser_name,
|
|
||||||
known=browser_known
|
|
||||||
)
|
|
||||||
|
|
||||||
flash(msg, 'warning')
|
|
||||||
|
|
||||||
# Get the current version info from the website, and flash a message if
|
def check_browser_upgrade():
|
||||||
# the user is out of date, and the check is enabled.
|
"""
|
||||||
if config.UPGRADE_CHECK_ENABLED:
|
This function is used to check the browser version.
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
data = None
|
data = None
|
||||||
url = '%s?version=%s' % (config.UPGRADE_CHECK_URL, config.APP_VERSION)
|
url = '%s?version=%s' % (config.UPGRADE_CHECK_URL, config.APP_VERSION)
|
||||||
current_app.logger.debug('Checking version data at: %s' % url)
|
current_app.logger.debug('Checking version data at: %s' % url)
|
||||||
@@ -642,6 +621,45 @@ def index():
|
|||||||
|
|
||||||
flash(msg, 'warning')
|
flash(msg, 'warning')
|
||||||
|
|
||||||
|
|
||||||
|
@blueprint.route("/")
|
||||||
|
@pgCSRFProtect.exempt
|
||||||
|
@login_required
|
||||||
|
def index():
|
||||||
|
"""Render and process the main browser window."""
|
||||||
|
# Register Gravatar module with the app only if required
|
||||||
|
if config.SHOW_GRAVATAR_IMAGE:
|
||||||
|
Gravatar(
|
||||||
|
current_app,
|
||||||
|
size=100,
|
||||||
|
rating='g',
|
||||||
|
default='retro',
|
||||||
|
force_default=False,
|
||||||
|
use_ssl=True,
|
||||||
|
base_url=None
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check the browser is a support version
|
||||||
|
# NOTE: If the checks here are updated, make sure the supported versions
|
||||||
|
# at https://www.pgadmin.org/faq/#11 are updated to match!
|
||||||
|
if config.CHECK_SUPPORTED_BROWSER:
|
||||||
|
browser_name, browser_known, version = _get_supported_browser()
|
||||||
|
|
||||||
|
if browser_name is not None:
|
||||||
|
msg = render_template(
|
||||||
|
MODULE_NAME + "/browser.html",
|
||||||
|
version=version,
|
||||||
|
browser=browser_name,
|
||||||
|
known=browser_known
|
||||||
|
)
|
||||||
|
|
||||||
|
flash(msg, 'warning')
|
||||||
|
|
||||||
|
# Get the current version info from the website, and flash a message if
|
||||||
|
# the user is out of date, and the check is enabled.
|
||||||
|
if config.UPGRADE_CHECK_ENABLED:
|
||||||
|
check_browser_upgrade()
|
||||||
|
|
||||||
auth_only_internal = False
|
auth_only_internal = False
|
||||||
auth_source = []
|
auth_source = []
|
||||||
|
|
||||||
|
|||||||
@@ -342,7 +342,7 @@ class ExtensionView(PGChildNodeView, SchemaDiffObjectCompare):
|
|||||||
else:
|
else:
|
||||||
data = {'ids': [eid]}
|
data = {'ids': [eid]}
|
||||||
|
|
||||||
cascade = True if self.cmd == 'delete' else False
|
cascade = self._check_cascade_operation()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for eid in data['ids']:
|
for eid in data['ids']:
|
||||||
|
|||||||
@@ -530,6 +530,32 @@ class UserMappingView(PGChildNodeView, SchemaDiffObjectCompare):
|
|||||||
|
|
||||||
return cascade, data
|
return cascade, data
|
||||||
|
|
||||||
|
def _fetch_specified_user_mapping_properties(self, umid):
|
||||||
|
"""
|
||||||
|
This function is used to fetch the specified user mapping.
|
||||||
|
:param umid:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
sql = render_template("/".join([self.template_path,
|
||||||
|
'properties.sql']),
|
||||||
|
umid=umid, conn=self.conn)
|
||||||
|
status, res = self.conn.execute_dict(sql)
|
||||||
|
if not status:
|
||||||
|
return internal_server_error(errormsg=res)
|
||||||
|
|
||||||
|
if not res['rows']:
|
||||||
|
return make_json_response(
|
||||||
|
status=410,
|
||||||
|
success=0,
|
||||||
|
errormsg=gettext(
|
||||||
|
'The specified user mapping could not be found.\n'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return res
|
||||||
|
except Exception as e:
|
||||||
|
return internal_server_error(errormsg=str(e))
|
||||||
|
|
||||||
@check_precondition
|
@check_precondition
|
||||||
def delete(self, gid, sid, did, fid, fsid, **kwargs):
|
def delete(self, gid, sid, did, fid, fsid, **kwargs):
|
||||||
"""
|
"""
|
||||||
@@ -573,22 +599,7 @@ class UserMappingView(PGChildNodeView, SchemaDiffObjectCompare):
|
|||||||
'could not be found.\n'
|
'could not be found.\n'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
res = self._fetch_specified_user_mapping_properties(umid)
|
||||||
sql = render_template("/".join([self.template_path,
|
|
||||||
self._PROPERTIES_SQL]),
|
|
||||||
umid=umid, conn=self.conn)
|
|
||||||
status, res = self.conn.execute_dict(sql)
|
|
||||||
if not status:
|
|
||||||
return internal_server_error(errormsg=res)
|
|
||||||
|
|
||||||
if not res['rows']:
|
|
||||||
return make_json_response(
|
|
||||||
status=410,
|
|
||||||
success=0,
|
|
||||||
errormsg=gettext(
|
|
||||||
'The specified user mapping could not be found.\n'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
data = res['rows'][0]
|
data = res['rows'][0]
|
||||||
|
|
||||||
|
|||||||
@@ -531,11 +531,7 @@ class LanguageView(PGChildNodeView, SchemaDiffObjectCompare):
|
|||||||
else:
|
else:
|
||||||
data = {'ids': [lid]}
|
data = {'ids': [lid]}
|
||||||
|
|
||||||
if self.cmd == 'delete':
|
cascade = self._check_cascade_operation()
|
||||||
# This is a cascade operation
|
|
||||||
cascade = True
|
|
||||||
else:
|
|
||||||
cascade = False
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for lid in data['ids']:
|
for lid in data['ids']:
|
||||||
|
|||||||
@@ -731,7 +731,7 @@ It may have been removed by another user.
|
|||||||
"/".join([self.template_path,
|
"/".join([self.template_path,
|
||||||
self._SQL_PREFIX + self._DELETE_SQL]),
|
self._SQL_PREFIX + self._DELETE_SQL]),
|
||||||
_=gettext, name=name, conn=self.conn,
|
_=gettext, name=name, conn=self.conn,
|
||||||
cascade=True if self.cmd == 'delete' else False
|
cascade=self._check_cascade_operation()
|
||||||
)
|
)
|
||||||
status, res = self.conn.execute_scalar(SQL)
|
status, res = self.conn.execute_scalar(SQL)
|
||||||
if not status:
|
if not status:
|
||||||
|
|||||||
@@ -524,7 +524,8 @@ class CollationView(PGChildNodeView, SchemaDiffObjectCompare):
|
|||||||
else {'ids': [coid]}
|
else {'ids': [coid]}
|
||||||
|
|
||||||
# Below will decide if it's simple drop or drop with cascade call
|
# Below will decide if it's simple drop or drop with cascade call
|
||||||
cascade = True if self.cmd == 'delete' else False
|
|
||||||
|
cascade = self._check_cascade_operation()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for coid in data['ids']:
|
for coid in data['ids']:
|
||||||
|
|||||||
@@ -627,11 +627,7 @@ AND relkind != 'c'))"""
|
|||||||
else:
|
else:
|
||||||
data = {'ids': [doid]}
|
data = {'ids': [doid]}
|
||||||
|
|
||||||
if self.cmd == 'delete' or only_sql:
|
cascade = self._check_cascade_operation(only_sql)
|
||||||
# This is a cascade operation
|
|
||||||
cascade = True
|
|
||||||
else:
|
|
||||||
cascade = False
|
|
||||||
|
|
||||||
for doid in data['ids']:
|
for doid in data['ids']:
|
||||||
SQL = render_template("/".join([self.template_path,
|
SQL = render_template("/".join([self.template_path,
|
||||||
@@ -807,6 +803,26 @@ AND relkind != 'c'))"""
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return internal_server_error(errormsg=str(e))
|
return internal_server_error(errormsg=str(e))
|
||||||
|
|
||||||
|
def check_domain_type(self, data, old_data, is_schema_diff):
|
||||||
|
"""
|
||||||
|
Check domain type
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
# If fulltype or basetype or collname is changed while comparing
|
||||||
|
# two schemas then we need to drop domain and recreate it
|
||||||
|
if 'fulltype' in data or 'basetype' in data or 'collname' in data:
|
||||||
|
SQL = render_template(
|
||||||
|
"/".join([self.template_path, 'domain_schema_diff.sql']),
|
||||||
|
data=data, o_data=old_data)
|
||||||
|
else:
|
||||||
|
if is_schema_diff:
|
||||||
|
data['is_schema_diff'] = True
|
||||||
|
|
||||||
|
SQL = render_template(
|
||||||
|
"/".join([self.template_path, 'update.sql']),
|
||||||
|
data=data, o_data=old_data)
|
||||||
|
return SQL, data
|
||||||
|
|
||||||
def get_sql(self, gid, sid, data, scid, doid=None, is_schema_diff=False):
|
def get_sql(self, gid, sid, data, scid, doid=None, is_schema_diff=False):
|
||||||
"""
|
"""
|
||||||
Generates the SQL statements to create/update the Domain.
|
Generates the SQL statements to create/update the Domain.
|
||||||
@@ -847,19 +863,7 @@ AND relkind != 'c'))"""
|
|||||||
|
|
||||||
old_data['constraints'] = con_data
|
old_data['constraints'] = con_data
|
||||||
|
|
||||||
# If fulltype or basetype or collname is changed while comparing
|
SQL, data = self.check_domain_type(data, old_data, is_schema_diff)
|
||||||
# two schemas then we need to drop domain and recreate it
|
|
||||||
if 'fulltype' in data or 'basetype' in data or 'collname' in data:
|
|
||||||
SQL = render_template(
|
|
||||||
"/".join([self.template_path, 'domain_schema_diff.sql']),
|
|
||||||
data=data, o_data=old_data)
|
|
||||||
else:
|
|
||||||
if is_schema_diff:
|
|
||||||
data['is_schema_diff'] = True
|
|
||||||
|
|
||||||
SQL = render_template(
|
|
||||||
"/".join([self.template_path, self._UPDATE_SQL]),
|
|
||||||
data=data, o_data=old_data)
|
|
||||||
return SQL.strip('\n'), data['name'] if 'name' in data else \
|
return SQL.strip('\n'), data['name'] if 'name' in data else \
|
||||||
old_data['name']
|
old_data['name']
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -722,11 +722,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader,
|
|||||||
else:
|
else:
|
||||||
data = {'ids': [foid]}
|
data = {'ids': [foid]}
|
||||||
|
|
||||||
if self.cmd == 'delete':
|
cascade = self._check_cascade_operation()
|
||||||
# This is a cascade operation
|
|
||||||
cascade = True
|
|
||||||
else:
|
|
||||||
cascade = False
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for foid in data['ids']:
|
for foid in data['ids']:
|
||||||
|
|||||||
@@ -554,11 +554,7 @@ class FtsConfigurationView(PGChildNodeView, SchemaDiffObjectCompare):
|
|||||||
data = {'ids': [cfgid]}
|
data = {'ids': [cfgid]}
|
||||||
|
|
||||||
# Below will decide if it's simple drop or drop with cascade call
|
# Below will decide if it's simple drop or drop with cascade call
|
||||||
if self.cmd == 'delete':
|
cascade = self._check_cascade_operation()
|
||||||
# This is a cascade operation
|
|
||||||
cascade = True
|
|
||||||
else:
|
|
||||||
cascade = False
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for cfgid in data['ids']:
|
for cfgid in data['ids']:
|
||||||
|
|||||||
@@ -551,11 +551,8 @@ class FtsDictionaryView(PGChildNodeView, SchemaDiffObjectCompare):
|
|||||||
data = {'ids': [dcid]}
|
data = {'ids': [dcid]}
|
||||||
|
|
||||||
# Below will decide if it's simple drop or drop with cascade call
|
# Below will decide if it's simple drop or drop with cascade call
|
||||||
if self.cmd == 'delete':
|
|
||||||
# This is a cascade operation
|
cascade = self._check_cascade_operation()
|
||||||
cascade = True
|
|
||||||
else:
|
|
||||||
cascade = False
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for dcid in data['ids']:
|
for dcid in data['ids']:
|
||||||
|
|||||||
@@ -497,11 +497,7 @@ class FtsParserView(PGChildNodeView, SchemaDiffObjectCompare):
|
|||||||
data = {'ids': [pid]}
|
data = {'ids': [pid]}
|
||||||
|
|
||||||
# Below will decide if it's simple drop or drop with cascade call
|
# Below will decide if it's simple drop or drop with cascade call
|
||||||
if self.cmd == 'delete':
|
cascade = self._check_cascade_operation()
|
||||||
# This is a cascade operation
|
|
||||||
cascade = True
|
|
||||||
else:
|
|
||||||
cascade = False
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for pid in data['ids']:
|
for pid in data['ids']:
|
||||||
|
|||||||
@@ -462,11 +462,7 @@ class FtsTemplateView(PGChildNodeView, SchemaDiffObjectCompare):
|
|||||||
data = {'ids': [tid]}
|
data = {'ids': [tid]}
|
||||||
|
|
||||||
# Below will decide if it's simple drop or drop with cascade call
|
# Below will decide if it's simple drop or drop with cascade call
|
||||||
if self.cmd == 'delete':
|
cascade = self._check_cascade_operation()
|
||||||
# This is a cascade operation
|
|
||||||
cascade = True
|
|
||||||
else:
|
|
||||||
cascade = False
|
|
||||||
|
|
||||||
for tid in data['ids']:
|
for tid in data['ids']:
|
||||||
# Get name for template from tid
|
# Get name for template from tid
|
||||||
|
|||||||
@@ -895,11 +895,7 @@ class FunctionView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare):
|
|||||||
else:
|
else:
|
||||||
data = {'ids': [fnid]}
|
data = {'ids': [fnid]}
|
||||||
|
|
||||||
if self.cmd == 'delete':
|
cascade = self._check_cascade_operation()
|
||||||
# This is a cascade operation
|
|
||||||
cascade = True
|
|
||||||
else:
|
|
||||||
cascade = False
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for fnid in data['ids']:
|
for fnid in data['ids']:
|
||||||
|
|||||||
@@ -438,11 +438,8 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare):
|
|||||||
data = {'ids': [pkgid]}
|
data = {'ids': [pkgid]}
|
||||||
|
|
||||||
# Below will decide if it's simple drop or drop with cascade call
|
# Below will decide if it's simple drop or drop with cascade call
|
||||||
if self.cmd == 'delete':
|
|
||||||
# This is a cascade operation
|
cascade = self._check_cascade_operation()
|
||||||
cascade = True
|
|
||||||
else:
|
|
||||||
cascade = False
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for pkgid in data['ids']:
|
for pkgid in data['ids']:
|
||||||
|
|||||||
@@ -465,11 +465,8 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare):
|
|||||||
data = {'ids': [seid]}
|
data = {'ids': [seid]}
|
||||||
|
|
||||||
# Below will decide if it's simple drop or drop with cascade call
|
# Below will decide if it's simple drop or drop with cascade call
|
||||||
if self.cmd == 'delete':
|
|
||||||
# This is a cascade operation
|
cascade = self._check_cascade_operation()
|
||||||
cascade = True
|
|
||||||
else:
|
|
||||||
cascade = False
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for seid in data['ids']:
|
for seid in data['ids']:
|
||||||
|
|||||||
@@ -562,11 +562,7 @@ class CompoundTriggerView(PGChildNodeView, SchemaDiffObjectCompare):
|
|||||||
data = {'ids': [trid]}
|
data = {'ids': [trid]}
|
||||||
|
|
||||||
# Below will decide if it's simple drop or drop with cascade call
|
# Below will decide if it's simple drop or drop with cascade call
|
||||||
if self.cmd == 'delete':
|
cascade = self._check_cascade_operation()
|
||||||
# This is a cascade operation
|
|
||||||
cascade = True
|
|
||||||
else:
|
|
||||||
cascade = False
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for trid in data['ids']:
|
for trid in data['ids']:
|
||||||
|
|||||||
@@ -669,11 +669,7 @@ class ExclusionConstraintView(PGChildNodeView):
|
|||||||
data = {'ids': [exid]}
|
data = {'ids': [exid]}
|
||||||
|
|
||||||
# Below code will decide if it's simple drop or drop with cascade call
|
# Below code will decide if it's simple drop or drop with cascade call
|
||||||
if self.cmd == 'delete':
|
cascade = self._check_cascade_operation()
|
||||||
# This is a cascade operation
|
|
||||||
cascade = True
|
|
||||||
else:
|
|
||||||
cascade = False
|
|
||||||
try:
|
try:
|
||||||
for exid in data['ids']:
|
for exid in data['ids']:
|
||||||
sql = render_template(
|
sql = render_template(
|
||||||
|
|||||||
@@ -731,11 +731,8 @@ class ForeignKeyConstraintView(PGChildNodeView):
|
|||||||
data = {'ids': [fkid]}
|
data = {'ids': [fkid]}
|
||||||
|
|
||||||
# Below code will decide if it's simple drop or drop with cascade call
|
# Below code will decide if it's simple drop or drop with cascade call
|
||||||
if self.cmd == 'delete':
|
|
||||||
# This is a cascade operation
|
cascade = self._check_cascade_operation()
|
||||||
cascade = True
|
|
||||||
else:
|
|
||||||
cascade = False
|
|
||||||
try:
|
try:
|
||||||
for fkid in data['ids']:
|
for fkid in data['ids']:
|
||||||
sql = render_template(
|
sql = render_template(
|
||||||
|
|||||||
@@ -718,11 +718,7 @@ class IndexConstraintView(PGChildNodeView):
|
|||||||
data = {'ids': [cid]}
|
data = {'ids': [cid]}
|
||||||
|
|
||||||
# Below code will decide if it's simple drop or drop with cascade call
|
# Below code will decide if it's simple drop or drop with cascade call
|
||||||
if self.cmd == 'delete':
|
cascade = self._check_cascade_operation()
|
||||||
# This is a cascade operation
|
|
||||||
cascade = True
|
|
||||||
else:
|
|
||||||
cascade = False
|
|
||||||
try:
|
try:
|
||||||
for cid in data['ids']:
|
for cid in data['ids']:
|
||||||
sql = render_template(
|
sql = render_template(
|
||||||
|
|||||||
@@ -681,11 +681,8 @@ class IndexesView(PGChildNodeView, SchemaDiffObjectCompare):
|
|||||||
data = {'ids': [idx]}
|
data = {'ids': [idx]}
|
||||||
|
|
||||||
# Below will decide if it's simple drop or drop with cascade call
|
# Below will decide if it's simple drop or drop with cascade call
|
||||||
if self.cmd == 'delete':
|
|
||||||
# This is a cascade operation
|
cascade = self._check_cascade_operation()
|
||||||
cascade = True
|
|
||||||
else:
|
|
||||||
cascade = False
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for idx in data['ids']:
|
for idx in data['ids']:
|
||||||
|
|||||||
@@ -436,6 +436,22 @@ class RowSecurityView(PGChildNodeView):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return internal_server_error(errormsg=str(e))
|
return internal_server_error(errormsg=str(e))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_policy_data(plid):
|
||||||
|
"""
|
||||||
|
return policy data
|
||||||
|
:param plid:
|
||||||
|
:return: policy id
|
||||||
|
"""
|
||||||
|
if plid is None:
|
||||||
|
data = request.form if request.form else json.loads(
|
||||||
|
request.data, encoding='utf-8'
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
data = {'ids': [plid]}
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
@check_precondition
|
@check_precondition
|
||||||
def delete(self, gid, sid, did, scid, tid, **kwargs):
|
def delete(self, gid, sid, did, scid, tid, **kwargs):
|
||||||
"""
|
"""
|
||||||
@@ -453,18 +469,9 @@ class RowSecurityView(PGChildNodeView):
|
|||||||
only_sql = kwargs.get('only_sql', False)
|
only_sql = kwargs.get('only_sql', False)
|
||||||
|
|
||||||
# Below will deplide if it's simple drop or drop with cascade call
|
# Below will deplide if it's simple drop or drop with cascade call
|
||||||
if self.cmd == 'delete':
|
cascade = self._check_cascade_operation()
|
||||||
# This is a cascade operation
|
|
||||||
cascade = True
|
|
||||||
else:
|
|
||||||
cascade = False
|
|
||||||
|
|
||||||
if plid is None:
|
data = self.get_policy_data(plid)
|
||||||
data = request.form if request.form else json.loads(
|
|
||||||
request.data, encoding='utf-8'
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
data = {'ids': [plid]}
|
|
||||||
|
|
||||||
for plid in data['ids']:
|
for plid in data['ids']:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -407,7 +407,8 @@ class RuleView(PGChildNodeView, SchemaDiffObjectCompare):
|
|||||||
data = {'ids': [rid]}
|
data = {'ids': [rid]}
|
||||||
|
|
||||||
# Below will decide if it's simple drop or drop with cascade call
|
# Below will decide if it's simple drop or drop with cascade call
|
||||||
cascade = True if self.cmd == 'delete' else False
|
|
||||||
|
cascade = self._check_cascade_operation()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for rid in data['ids']:
|
for rid in data['ids']:
|
||||||
|
|||||||
@@ -596,11 +596,8 @@ class TriggerView(PGChildNodeView, SchemaDiffObjectCompare):
|
|||||||
data = {'ids': [trid]}
|
data = {'ids': [trid]}
|
||||||
|
|
||||||
# Below will decide if it's simple drop or drop with cascade call
|
# Below will decide if it's simple drop or drop with cascade call
|
||||||
if self.cmd == 'delete':
|
|
||||||
# This is a cascade operation
|
cascade = self._check_cascade_operation()
|
||||||
cascade = True
|
|
||||||
else:
|
|
||||||
cascade = False
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for trid in data['ids']:
|
for trid in data['ids']:
|
||||||
|
|||||||
@@ -1684,11 +1684,7 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
|
|||||||
|
|
||||||
def get_delete_sql(self, res):
|
def get_delete_sql(self, res):
|
||||||
# Below will decide if it's simple drop or drop with cascade call
|
# Below will decide if it's simple drop or drop with cascade call
|
||||||
if self.cmd == 'delete':
|
cascade = self._check_cascade_operation()
|
||||||
# This is a cascade operation
|
|
||||||
cascade = True
|
|
||||||
else:
|
|
||||||
cascade = False
|
|
||||||
|
|
||||||
data = res['rows'][0]
|
data = res['rows'][0]
|
||||||
|
|
||||||
|
|||||||
@@ -1106,12 +1106,7 @@ class TypeView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare):
|
|||||||
else:
|
else:
|
||||||
data = {'ids': [tid]}
|
data = {'ids': [tid]}
|
||||||
|
|
||||||
# Below will decide if it's simple drop or drop with cascade call
|
cascade = self._check_cascade_operation()
|
||||||
if self.cmd == 'delete' or only_sql:
|
|
||||||
# This is a cascade operation
|
|
||||||
cascade = True
|
|
||||||
else:
|
|
||||||
cascade = False
|
|
||||||
|
|
||||||
return data, cascade
|
return data, cascade
|
||||||
|
|
||||||
|
|||||||
@@ -647,7 +647,8 @@ class ViewNode(PGChildNodeView, VacuumSettings, SchemaDiffObjectCompare):
|
|||||||
data = {'ids': [vid]}
|
data = {'ids': [vid]}
|
||||||
|
|
||||||
# Below will decide if it's simple drop or drop with cascade call
|
# Below will decide if it's simple drop or drop with cascade call
|
||||||
cascade = True if self.cmd == 'delete' else False
|
|
||||||
|
cascade = self._check_cascade_operation()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for vid in data['ids']:
|
for vid in data['ids']:
|
||||||
|
|||||||
@@ -711,6 +711,19 @@ class PGChildNodeView(NodeView):
|
|||||||
|
|
||||||
return dependency
|
return dependency
|
||||||
|
|
||||||
|
def _check_cascade_operation(self, only_sql=None):
|
||||||
|
"""
|
||||||
|
Check cascade operation.
|
||||||
|
:param only_sql:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
if self.cmd == 'delete' or only_sql:
|
||||||
|
# This is a cascade operation
|
||||||
|
cascade = True
|
||||||
|
else:
|
||||||
|
cascade = False
|
||||||
|
return cascade
|
||||||
|
|
||||||
def not_found_error_msg(self, custom_label=None):
|
def not_found_error_msg(self, custom_label=None):
|
||||||
return gettext("Could not find the specified {}.".format(
|
return gettext("Could not find the specified {}.".format(
|
||||||
custom_label if custom_label else self.node_label).lower())
|
custom_label if custom_label else self.node_label).lower())
|
||||||
|
|||||||
@@ -2132,10 +2132,31 @@ def poll_result(trans_id):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def release_connection(manager, dbg_obj):
|
||||||
|
"""This function is used to release connection."""
|
||||||
|
conn = manager.connection(
|
||||||
|
did=dbg_obj['database_id'],
|
||||||
|
conn_id=dbg_obj['conn_id'])
|
||||||
|
if conn.connected():
|
||||||
|
conn.cancel_transaction(
|
||||||
|
dbg_obj['conn_id'],
|
||||||
|
dbg_obj['database_id'])
|
||||||
|
manager.release(conn_id=dbg_obj['conn_id'])
|
||||||
|
|
||||||
|
if 'exe_conn_id' in dbg_obj:
|
||||||
|
conn = manager.connection(
|
||||||
|
did=dbg_obj['database_id'],
|
||||||
|
conn_id=dbg_obj['exe_conn_id'])
|
||||||
|
if conn.connected():
|
||||||
|
conn.cancel_transaction(
|
||||||
|
dbg_obj['exe_conn_id'],
|
||||||
|
dbg_obj['database_id'])
|
||||||
|
manager.release(conn_id=dbg_obj['exe_conn_id'])
|
||||||
|
|
||||||
|
|
||||||
def close_debugger_session(_trans_id, close_all=False):
|
def close_debugger_session(_trans_id, close_all=False):
|
||||||
"""
|
"""
|
||||||
This function is used to cancel the debugger transaction and
|
This function is used to cancel the debugger transaction.
|
||||||
release the connection.
|
|
||||||
|
|
||||||
:param trans_id: Transaction id
|
:param trans_id: Transaction id
|
||||||
:return:
|
:return:
|
||||||
@@ -2156,24 +2177,7 @@ def close_debugger_session(_trans_id, close_all=False):
|
|||||||
connection_manager(dbg_obj['server_id'])
|
connection_manager(dbg_obj['server_id'])
|
||||||
|
|
||||||
if manager is not None:
|
if manager is not None:
|
||||||
conn = manager.connection(
|
release_connection(manager, dbg_obj)
|
||||||
did=dbg_obj['database_id'],
|
|
||||||
conn_id=dbg_obj['conn_id'])
|
|
||||||
if conn.connected():
|
|
||||||
conn.cancel_transaction(
|
|
||||||
dbg_obj['conn_id'],
|
|
||||||
dbg_obj['database_id'])
|
|
||||||
manager.release(conn_id=dbg_obj['conn_id'])
|
|
||||||
|
|
||||||
if 'exe_conn_id' in dbg_obj:
|
|
||||||
conn = manager.connection(
|
|
||||||
did=dbg_obj['database_id'],
|
|
||||||
conn_id=dbg_obj['exe_conn_id'])
|
|
||||||
if conn.connected():
|
|
||||||
conn.cancel_transaction(
|
|
||||||
dbg_obj['exe_conn_id'],
|
|
||||||
dbg_obj['database_id'])
|
|
||||||
manager.release(conn_id=dbg_obj['exe_conn_id'])
|
|
||||||
|
|
||||||
de_inst.clear()
|
de_inst.clear()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
Reference in New Issue
Block a user