From 0243d886c3cd01d8ca4d2941edf063c39affd1e6 Mon Sep 17 00:00:00 2001 From: Ashesh Vashi Date: Tue, 13 Jun 2017 11:47:55 +0530 Subject: [PATCH] Using client-side 'url_for' implementation in the Grant-Wizard module. --- web/pgadmin/tools/grant_wizard/__init__.py | 38 +++++++---- .../templates/grant_wizard/js/grant_wizard.js | 63 ++++++++++--------- 2 files changed, 57 insertions(+), 44 deletions(-) diff --git a/web/pgadmin/tools/grant_wizard/__init__.py b/web/pgadmin/tools/grant_wizard/__init__.py index 9c6f47e5e..488a7e22e 100644 --- a/web/pgadmin/tools/grant_wizard/__init__.py +++ b/web/pgadmin/tools/grant_wizard/__init__.py @@ -90,6 +90,16 @@ class GrantWizardModule(PgAdminModule): 'show_system_objects' ) + def get_exposed_url_endpoints(self): + """ + Returns: + list: URL endpoints for grant-wizard module + """ + return [ + 'grant_wizard.acl', 'grant_wizard.objects', 'grant_wizard.apply', + 'grant_wizard.modified_sql' + ] + # Create blueprint for GrantWizardModule class blueprint = GrantWizardModule( @@ -108,7 +118,7 @@ def check_precondition(f): @wraps(f) def wrap(*args, **kwargs): - # Here args[0] will hold self & kwargs will hold gid,sid,did + # Here args[0] will hold self & kwargs will hold sid,did server_info.clear() server_info['manager'] = get_driver(PG_DEFAULT_DRIVER)\ @@ -152,10 +162,11 @@ def script(): @blueprint.route( - '/acl////', methods=('GET', 'POST')) + '/acl///', methods=['GET'], endpoint='acl' +) @login_required @check_precondition -def acl_list(gid, sid, did): +def acl_list(sid, did): """render list of acls""" server_prop = server_info return Response(response=render_template( @@ -165,12 +176,12 @@ def acl_list(gid, sid, did): @blueprint.route( - '/properties///' - '///', - methods=('GET', 'POST')) + '/////', + methods=['GET'], endpoint='objects' +) @login_required @check_precondition -def properties(gid, sid, did, node_id, node_type): +def properties(sid, did, node_id, node_type): """It fetches the properties of object types and render into selection page of wizard """ @@ -308,11 +319,12 @@ def properties(gid, sid, did, node_id, node_type): @blueprint.route( - '/msql////', - methods=('GET', 'POST')) + '/sql///', + methods=['GET'], endpoint='modified_sql' +) @login_required @check_precondition -def msql(gid, sid, did): +def msql(sid, did): """ This function will return modified SQL """ @@ -400,11 +412,11 @@ def msql(gid, sid, did): @blueprint.route( - '/save////', - methods=('GET', 'POST')) + '///', methods=['POST'], endpoint='apply' +) @login_required @check_precondition -def save(gid, sid, did): +def save(sid, did): """ This function will apply the privileges to the selected Database Objects diff --git a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/js/grant_wizard.js b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/js/grant_wizard.js index 5cd26dc98..fd0a4e52c 100644 --- a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/js/grant_wizard.js +++ b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/js/grant_wizard.js @@ -1,10 +1,10 @@ // Grant Wizard define([ - 'sources/gettext', 'jquery', 'underscore', 'underscore.string', 'alertify', - 'pgadmin.browser', 'backbone', 'backgrid', 'pgadmin.browser.node', - 'backgrid.select.all', 'backgrid.filter', 'pgadmin.browser.server.privilege', - 'pgadmin.browser.wizard', -], function(gettext, $, _, S, alertify, pgBrowser, Backbone, Backgrid, pgNode) { + 'sources/gettext', 'sources/url_for', 'jquery', 'underscore', + 'underscore.string', 'alertify', 'pgadmin.browser', 'backbone', 'backgrid', + 'pgadmin.browser.node', 'backgrid.select.all', 'backgrid.filter', + 'pgadmin.browser.server.privilege', 'pgadmin.browser.wizard', +], function(gettext, url_for, $, _, S, alertify, pgBrowser, Backbone, Backgrid, pgNode) { // if module is already initialized, refer to that. if (pgBrowser.GrantWizard) { @@ -416,12 +416,12 @@ define([ //Returns list of Acls defined for nodes get_json_data: function(gid, sid, did) { - var url = "{{ url_for('grant_wizard.index') }}" + "acl/" + - S('%s/%s/%s/').sprintf( - encodeURI(gid), encodeURI(sid), encodeURI(did)).value(); return $.ajax({ async: false, - url: url, + url: url_for( + 'grant_wizard.acl', + {'sid': encodeURI(sid), 'did': encodeURI(did)} + ), dataType: 'jsonp' }); @@ -463,23 +463,22 @@ define([ var privDict = JSON.parse(json_data.responseText); // Collection url to fetch database object types for objects field - var baseUrl = "{{ url_for('grant_wizard.index') }}" + "properties/" + - S('%s/%s/%s/%s/%s/').sprintf( - encodeURI(gid), encodeURI(sid), encodeURI(did), - encodeURI(node_id), encodeURI(node_type)).value(); - + var baseUrl = url_for( + 'grant_wizard.objects', { + 'sid': encodeURI(sid), 'did': encodeURI(did), + 'node_id': encodeURI(node_id), + 'node_type': encodeURI(node_type) + }), // Model's save url - saveUrl = "{{ url_for('grant_wizard.index') }}" + "save/" + - S('%s/%s/%s/').sprintf( - encodeURI(gid), encodeURI(sid), - encodeURI(did)).value(), - + saveUrl = url_for( + 'grant_wizard.apply', { + 'sid': encodeURI(sid), 'did': encodeURI(did) + }), // generate encoded url based on wizard type - msql_url = this.msql_url = "/grant_wizard/msql/"+ - S('%s/%s/%s/').sprintf( - encodeURI(gid), encodeURI(sid), - encodeURI(did)).value(), - + msql_url = this.msql_url = url_for( + 'grant_wizard.modified_sql', { + 'sid': encodeURI(sid), 'did': encodeURI(did) + }), Coll = Backbone.Collection.extend({ model: DatabaseObjectModel, url: baseUrl @@ -487,19 +486,19 @@ define([ // Create instances of collection and filter coll = this.coll = new Coll(), + self = this; - coll.comparator = function(model) { - return model.get('object_type'); - } + coll.comparator = function(model) { + return model.get('object_type'); + } - coll.sort(); - dbObjectFilter = this.dbObjectFilter = this.DbObjectFilter(coll); + coll.sort(); + dbObjectFilter = this.dbObjectFilter = this.DbObjectFilter(coll); /** privArray holds objects selected which further helps in creating privileges Model */ - var self = this; self.privArray = []; /** @@ -1063,7 +1062,9 @@ define([ show_header_maximize_btn: true, disable_finish: true, dialog_api: that, - wizard_help: "{{ url_for('help.static', filename='grant_wizard.html') }}" + wizard_help: url_for( + 'help.static', {'filename': 'grant_wizard.html'} + ) }, // Callback for finish button