mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2024-11-22 08:46:39 -06:00
Hide menu options for creating objects, if the object type is set to hidden. Includes Jasmine tests. Fixes #2225
This commit is contained in:
parent
dd318e679d
commit
aea0d93390
@ -1,6 +1,7 @@
|
||||
define('pgadmin.browser',
|
||||
['require', 'jquery', 'underscore', 'underscore.string', 'bootstrap',
|
||||
'pgadmin', 'alertify', 'codemirror', 'codemirror/mode/sql/sql', 'wcdocker',
|
||||
'pgadmin', 'alertify', 'codemirror', 'sources/check_node_visibility',
|
||||
'codemirror/mode/sql/sql', 'wcdocker',
|
||||
'jquery.contextmenu', 'jquery.aciplugin', 'jquery.acitree',
|
||||
'pgadmin.alertifyjs', 'pgadmin.browser.messages',
|
||||
'pgadmin.browser.menu', 'pgadmin.browser.panel',
|
||||
@ -8,7 +9,10 @@ define('pgadmin.browser',
|
||||
'pgadmin.browser.node', 'pgadmin.browser.collection'
|
||||
|
||||
],
|
||||
function(require, $, _, S, Bootstrap, pgAdmin, Alertify, CodeMirror) {
|
||||
function(
|
||||
require, $, _, S, Bootstrap, pgAdmin, Alertify,
|
||||
CodeMirror, checkNodeVisibility
|
||||
) {
|
||||
|
||||
// Some scripts do export their object in the window only.
|
||||
// Generally the one, which do no have AMD support.
|
||||
@ -593,10 +597,16 @@ function(require, $, _, S, Bootstrap, pgAdmin, Alertify, CodeMirror) {
|
||||
single: single
|
||||
}
|
||||
},
|
||||
|
||||
// This will hold preference data (Works as a cache object)
|
||||
// Here node will be a key and it's preference data will be value
|
||||
node_preference_data: {},
|
||||
|
||||
// Add menus of module/extension at appropriate menu
|
||||
add_menus: function(menus) {
|
||||
var pgMenu = this.menus;
|
||||
var MenuItem = pgAdmin.Browser.MenuItem;
|
||||
var self = this,
|
||||
pgMenu = this.menus,
|
||||
MenuItem = pgAdmin.Browser.MenuItem;
|
||||
_.each(menus, function(m) {
|
||||
_.each(m.applies, function(a) {
|
||||
/* We do support menu type only from this list */
|
||||
@ -604,6 +614,19 @@ function(require, $, _, S, Bootstrap, pgAdmin, Alertify, CodeMirror) {
|
||||
'context', 'file', 'edit', 'object',
|
||||
'management', 'tools', 'help']) >= 0) {
|
||||
var menus;
|
||||
|
||||
// If current node is not visible in browser tree
|
||||
// then return from here
|
||||
if(!checkNodeVisibility(self, m.node)) {
|
||||
return;
|
||||
} else if(_.has(m, 'module') && !_.isUndefined(m.module)) {
|
||||
// If module to which this menu applies is not visible in
|
||||
// browser tree then also we do not display menu
|
||||
if(!checkNodeVisibility(self, m.module.type)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
pgMenu[a] = pgMenu[a] || {};
|
||||
if (_.isString(m.node)) {
|
||||
menus = pgMenu[a][m.node] = pgMenu[a][m.node] || {};
|
||||
|
53
web/pgadmin/static/js/check_node_visibility.js
Normal file
53
web/pgadmin/static/js/check_node_visibility.js
Normal file
@ -0,0 +1,53 @@
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2017, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
define(['jquery', 'underscore', 'underscore.string'],
|
||||
function ($, _, S) {
|
||||
|
||||
var check_node_visibility = function (pgBrowser, node_type) {
|
||||
if(_.isUndefined(node_type) || _.isNull(node_type)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Target actual node instead of collection.
|
||||
// If node is disabled then there is no meaning of
|
||||
// adding collection node menu
|
||||
if(S.startsWith(node_type, "coll-")) {
|
||||
node_type = node_type.replace("coll-", "")
|
||||
}
|
||||
|
||||
// Exclude non-applicable nodes
|
||||
var nodes_not_supported = [
|
||||
"server-group", "server", "catalog_object_column"
|
||||
];
|
||||
if(_.indexOf(nodes_not_supported, node_type) >= 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we have already fetched preference earlier then pick
|
||||
// it from our cache object
|
||||
if (_.has(pgBrowser.node_preference_data, node_type)) {
|
||||
return pgBrowser.node_preference_data[node_type].value
|
||||
}
|
||||
|
||||
var preference = pgBrowser.get_preference(
|
||||
'browser', 'show_node_' + node_type
|
||||
);
|
||||
|
||||
// Save it for future use, kind of caching
|
||||
if(!_.isUndefined(preference) && !_.isNull(preference)) {
|
||||
pgBrowser.node_preference_data[node_type] = preference;
|
||||
return preference.value;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return check_node_visibility;
|
||||
});
|
32
web/regression/javascript/check_node_visiblity_spec.js
Normal file
32
web/regression/javascript/check_node_visiblity_spec.js
Normal file
@ -0,0 +1,32 @@
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2017, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
define(["sources/check_node_visibility"],
|
||||
function (checkNodeVisibility, pgBrowser) {
|
||||
describe("checkNodeVisibility", function () {
|
||||
|
||||
var browser;
|
||||
|
||||
browser = jasmine.createSpyObj('browser', [
|
||||
'node_preference_data', 'get_preference']
|
||||
);
|
||||
|
||||
describe("when node is server collection", function () {
|
||||
it("returns true", function () {
|
||||
expect(checkNodeVisibility(browser, 'coll-server')).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when node is server", function () {
|
||||
it("returns true", function () {
|
||||
expect(checkNodeVisibility(browser, 'server')).toEqual(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -32,6 +32,7 @@ require.config({
|
||||
'jquery.ui': sourcesDir + 'vendor/jquery-ui/jquery-ui-1.11.3',
|
||||
'jquery.event.drag': sourcesDir + 'vendor/jquery-ui/jquery.event.drag-2.2',
|
||||
'underscore': sourcesDir + 'vendor/underscore/underscore',
|
||||
'underscore.string': sourcesDir + 'vendor/underscore/underscore.string',
|
||||
'slickgrid': sourcesDir + 'vendor/slickgrid/slick.core',
|
||||
'slickgrid/slick.grid': sourcesDir + 'vendor/slickgrid/slick.grid',
|
||||
'slickgrid/slick.rowselectionmodel': sourcesDir + 'vendor/slickgrid/plugins/slick.rowselectionmodel',
|
||||
|
Loading…
Reference in New Issue
Block a user