From 67f481ab11bd1f34ac5f57c60a59b257a6a5fd7c Mon Sep 17 00:00:00 2001 From: Surinder Kumar Date: Tue, 16 Aug 2016 12:49:19 +0100 Subject: [PATCH] Prevent creation of FTS objects in catalogs. Fixes #1122 --- .../fts_configuration/js/fts_configuration.js | 37 ++++++++++++++++-- .../fts_dictionary/js/fts_dictionary.js | 38 ++++++++++++++++-- .../templates/fts_parser/js/fts_parser.js | 38 ++++++++++++++++-- .../fts_template/js/fts_templates.js | 39 +++++++++++++++++-- 4 files changed, 136 insertions(+), 16 deletions(-) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_configurations/templates/fts_configuration/js/fts_configuration.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_configurations/templates/fts_configuration/js/fts_configuration.js index 18b4250b1..96f823e60 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_configurations/templates/fts_configuration/js/fts_configuration.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_configurations/templates/fts_configuration/js/fts_configuration.js @@ -436,19 +436,20 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { module: this, category: 'create', priority: 4, applies: ['object', 'context'], callback: 'show_obj_properties', label: '{{_('FTS Configuration...')}}', - icon: 'wcTabIcon icon-fts_configuration', data: {action: 'create'} + icon: 'wcTabIcon icon-fts_configuration', data: {action: 'create'}, + enable: 'canCreate' },{ name: 'create_fts_configuration_on_coll', module: this, priority: 4, node: 'coll-fts_configuration', applies: ['object', 'context'], callback: 'show_obj_properties', category: 'create', label: '{{ _('FTS Configuration...') }}', data: {action: 'create'}, - icon: 'wcTabIcon icon-fts_configuration' + icon: 'wcTabIcon icon-fts_configuration', enable: 'canCreate' },{ name: 'create_fts_configuration', node: 'fts_configuration', module: this, applies: ['object', 'context'], callback: 'show_obj_properties', category: 'create', priority: 4, label: '{{_('FTS Configuration...')}}', data: {action: 'create'}, - icon: 'wcTabIcon icon-fts_configuration' + icon: 'wcTabIcon icon-fts_configuration', enable: 'canCreate' }]); }, @@ -575,7 +576,35 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { return null; } - }) + }), + canCreate: function(itemData, item, data) { + //If check is false then , we will allow create menu + if (data && data.check == false) + return true; + + var t = pgBrowser.tree, i = item, d = itemData; + // To iterate over tree to check parent node + while (i) { + // If it is schema then allow user to create fts configuration + if (_.indexOf(['schema'], d._type) > -1) + return true; + + if ('coll-fts_configuration' == d._type) { + //Check if we are not child of catalog + prev_i = t.hasParent(i) ? t.parent(i) : null; + prev_d = prev_i ? t.itemData(prev_i) : null; + if( prev_d._type == 'catalog') { + return false; + } else { + return true; + } + } + i = t.hasParent(i) ? t.parent(i) : null; + d = i ? t.itemData(i) : null; + } + // by default we do not want to allow create menu + return true; + } }); } diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/templates/fts_dictionary/js/fts_dictionary.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/templates/fts_dictionary/js/fts_dictionary.js index 734da5ff4..030394316 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/templates/fts_dictionary/js/fts_dictionary.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_dictionaries/templates/fts_dictionary/js/fts_dictionary.js @@ -76,18 +76,20 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { name: 'create_fts_dictionary_on_schema', node: 'schema', module: this, applies: ['object', 'context'], callback: 'show_obj_properties', category: 'create', priority: 4, label: '{{_('FTS Dictionary...')}}', - icon: 'wcTabIcon icon-fts_dictionary', data: {action: 'create'} + icon: 'wcTabIcon icon-fts_dictionary', data: {action: 'create'}, + enable: 'canCreate' },{ name: 'create_fts_dictionary_on_coll', node: 'coll-fts_dictionary', module: this, applies: ['object', 'context'], priority: 4, callback: 'show_obj_properties', category: 'create', label: '{{ _('FTS Dictionary...') }}', data: {action: 'create'}, - icon: 'wcTabIcon icon-fts_dictionary' + icon: 'wcTabIcon icon-fts_dictionary', enable: 'canCreate' },{ name: 'create_fts_dictionary', node: 'fts_dictionary', module: this, applies: ['object', 'context'], callback: 'show_obj_properties', category: 'create', priority: 4, label: '{{_('FTS Dictionary...')}}', - icon: 'wcTabIcon icon-fts_dictionary', data: {action: 'create'} + icon: 'wcTabIcon icon-fts_dictionary', data: {action: 'create'}, + enable: 'canCreate' }]); }, @@ -179,7 +181,35 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { this.trigger('on-status-clear'); return null; } - }) + }), + canCreate: function(itemData, item, data) { + //If check is false then , we will allow create menu + if (data && data.check == false) + return true; + + var t = pgBrowser.tree, i = item, d = itemData; + // To iterate over tree to check parent node + while (i) { + // If it is schema then allow user to create fts dictionary + if (_.indexOf(['schema'], d._type) > -1) + return true; + + if ('coll-fts_dictionary' == d._type) { + //Check if we are not child of catalog + prev_i = t.hasParent(i) ? t.parent(i) : null; + prev_d = prev_i ? t.itemData(prev_i) : null; + if( prev_d._type == 'catalog') { + return false; + } else { + return true; + } + } + i = t.hasParent(i) ? t.parent(i) : null; + d = i ? t.itemData(i) : null; + } + // by default we do not want to allow create menu + return true; + } }); } diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parser/templates/fts_parser/js/fts_parser.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parser/templates/fts_parser/js/fts_parser.js index 2389a8046..949be8269 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parser/templates/fts_parser/js/fts_parser.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_parser/templates/fts_parser/js/fts_parser.js @@ -40,18 +40,20 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { name: 'create_fts_parser_on_schema', node: 'schema', module: this, applies: ['object', 'context'], callback: 'show_obj_properties', category: 'create', priority: 4, label: '{{ _('FTS Parser...') }}', - icon: 'wcTabIcon icon-fts_parser', data: {action: 'create'} + icon: 'wcTabIcon icon-fts_parser', data: {action: 'create'}, + enable: 'canCreate' },{ name: 'create_fts_parser_on_coll', node: 'coll-fts_parser', applies: ['object', 'context'], callback: 'show_obj_properties', category: 'create', priority: 4, label: '{{ _('FTS Parser...') }}', icon: 'wcTabIcon icon-fts_parser', data: {action: 'create'}, - module: this + module: this, enable: 'canCreate' },{ name: 'create_fts_parser', node: 'fts_parser', module: this, applies: ['object', 'context'], callback: 'show_obj_properties', category: 'create', priority: 4, label: '{{ _('FTS Parser...') }}', - icon: 'wcTabIcon icon-fts_parser', data: {action: 'create'} + icon: 'wcTabIcon icon-fts_parser', data: {action: 'create'}, + enable: 'canCreate' }]); }, @@ -195,7 +197,35 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { this.trigger('on-status-clear'); return null; } - }) + }), + canCreate: function(itemData, item, data) { + //If check is false then , we will allow create menu + if (data && data.check == false) + return true; + + var t = pgBrowser.tree, i = item, d = itemData; + // To iterate over tree to check parent node + while (i) { + // If it is schema then allow user to create fts parser + if (_.indexOf(['schema'], d._type) > -1) + return true; + + if ('coll-fts_parser' == d._type) { + //Check if we are not child of catalog + prev_i = t.hasParent(i) ? t.parent(i) : null; + prev_d = prev_i ? t.itemData(prev_i) : null; + if( prev_d._type == 'catalog') { + return false; + } else { + return true; + } + } + i = t.hasParent(i) ? t.parent(i) : null; + d = i ? t.itemData(i) : null; + } + // by default we do not want to allow create menu + return true; + } }); } diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/templates/fts_template/js/fts_templates.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/templates/fts_template/js/fts_templates.js index 9d2d0d4b9..41adf270b 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/templates/fts_template/js/fts_templates.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/fts_templates/templates/fts_template/js/fts_templates.js @@ -39,17 +39,20 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { name: 'create_fts_template_on_schema', node: 'schema', module: this, applies: ['object', 'context'], callback: 'show_obj_properties', category: 'create', priority: 4, label: '{{ _('FTS Template...') }}', - icon: 'wcTabIcon icon-fts_template', data: {action: 'create'} + icon: 'wcTabIcon icon-fts_template', data: {action: 'create'}, + enable: 'canCreate' },{ name: 'create_fts_template_on_coll', node: 'coll-fts_template', module: this, applies: ['object', 'context'], callback: 'show_obj_properties', category: 'create', priority: 4, label: '{{ _('FTS Template...') }}', - icon: 'wcTabIcon icon-fts_template', data: {action: 'create'} + icon: 'wcTabIcon icon-fts_template', data: {action: 'create'}, + enable: 'canCreate' },{ name: 'create_fts_template', node: 'fts_template', module: this, applies: ['object', 'context'], callback: 'show_obj_properties', category: 'create', priority: 4, label: '{{ _('FTS Template...') }}', - icon: 'wcTabIcon icon-fts_template', data: {action: 'create'} + icon: 'wcTabIcon icon-fts_template', data: {action: 'create'}, + enable: 'canCreate' }]); }, @@ -132,7 +135,35 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { this.trigger('on-status-clear'); return null; } - }) + }), + canCreate: function(itemData, item, data) { + //If check is false then , we will allow create menu + if (data && data.check == false) + return true; + + var t = pgBrowser.tree, i = item, d = itemData; + // To iterate over tree to check parent node + while (i) { + // If it is schema then allow user to create fts fts_template + if (_.indexOf(['schema'], d._type) > -1) + return true; + + if ('coll-fts_template' == d._type) { + //Check if we are not child of catalog + prev_i = t.hasParent(i) ? t.parent(i) : null; + prev_d = prev_i ? t.itemData(prev_i) : null; + if( prev_d._type == 'catalog') { + return false; + } else { + return true; + } + } + i = t.hasParent(i) ? t.parent(i) : null; + d = i ? t.itemData(i) : null; + } + // by default we do not want to allow create menu + return true; + } }); }