Using client-side 'url_for' implementation in the Grant-Wizard module.

This commit is contained in:
Ashesh Vashi
2017-06-13 11:47:55 +05:30
parent f9a3878220
commit 0243d886c3
2 changed files with 57 additions and 44 deletions

View File

@@ -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/<int:gid>/<int:sid>/<int:did>/', methods=('GET', 'POST'))
'/acl/<int:sid>/<int:did>/', 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/<int:gid>/<int:sid>/<int:did>'
'/<int:node_id>/<node_type>/',
methods=('GET', 'POST'))
'/<int:sid>/<int:did>/<int:node_id>/<node_type>/',
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/<int:gid>/<int:sid>/<int:did>/',
methods=('GET', 'POST'))
'/sql/<int:sid>/<int:did>/',
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/<int:gid>/<int:sid>/<int:did>/',
methods=('GET', 'POST'))
'/<int:sid>/<int:did>/', 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

View File

@@ -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