From 4b367b5bf7b7f8434ac31ff9c2e745382f08d0eb Mon Sep 17 00:00:00 2001 From: Endi S. Dewata Date: Fri, 19 Nov 2010 11:38:35 -0600 Subject: [PATCH] Fixed action panel queries Previously the queries for action panel were done globally. Since each entity container has its own action panel, the queries will return multiple results. This is fixed by qualifying the query to run within the entity container. The query has also been moved into ipa_facet.get_action_panel(). Entities that do not have their own entity container (e.g. HBAC services and service groups) will need to override this method to get the action panel from the right entity container (e.g. HBAC rules). The facet.setup_views() has been renamed to facet.create_action_panel(). New test data for SUDO rules have been added. --- install/static/associate.js | 26 +++++------- install/static/details.js | 3 +- install/static/entity.js | 55 ++++++++++++++----------- install/static/hbac.js | 42 ++++++++++++------- install/static/hbacsvc.js | 21 +++++----- install/static/hbacsvcgroup.js | 43 ++++++++++++------- install/static/search.js | 30 +++++++------ install/static/test/data/service_disable.json | 9 ++++ install/static/test/data/sudorule_add.json | 24 +++++++++++ install/static/test/data/sudorule_del.json | 9 ++++ install/static/test/data/sudorule_mod.json | 51 +++++++++++++++++++++++ install/static/test/entity_tests.js | 2 +- 12 files changed, 216 insertions(+), 99 deletions(-) create mode 100644 install/static/test/data/service_disable.json create mode 100644 install/static/test/data/sudorule_add.json create mode 100644 install/static/test/data/sudorule_del.json create mode 100644 install/static/test/data/sudorule_mod.json diff --git a/install/static/associate.js b/install/static/associate.js index f0239a44e12670f5399d9dd30c99a5e553a2aba0..01f7551a2fbf634b27b049220253f9a0d2cdb18b 100644 --- a/install/static/associate.js +++ b/install/static/associate.js @@ -241,6 +241,7 @@ function ipa_association_widget(spec) { var that = ipa_table_widget(spec); + that.facet = spec.facet; that.other_entity = spec.other_entity; that.superior_create = that.superior('create'); @@ -257,11 +258,10 @@ function ipa_association_widget(spec) { that.superior_create(container); - var entity_container = $('#' + that.entity_name); - var action_panel = $('.action-panel', entity_container); + var action_panel = that.facet.get_action_panel(); var ul = $('ul', action_panel); - var li = $('
  • ').appendTo(ul); + var li = $('
  • ').prependTo(ul); // creating generic buttons for layout $('', { @@ -282,7 +282,8 @@ function ipa_association_widget(spec) { that.table_setup(container); // replacing generic buttons with ipa_button and setting click handler - var action_panel = $('.action-panel'); + var action_panel = that.facet.get_action_panel(); + var button = $('input[name=remove]', action_panel); button.replaceWith(ipa_button({ 'label': button.val(), @@ -428,19 +429,10 @@ function ipa_association_facet(spec) { that.create = function(container) { that.pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; - that.other_entity = - $.bbq.getState(that.entity_name + '-enroll', true) || ''; + that.other_entity = $.bbq.getState(that.entity_name + '-enroll', true) || ''; var label = IPA.metadata[that.other_entity] ? IPA.metadata[that.other_entity].label : that.other_entity; - that.table = ipa_association_widget({ - 'id': that.entity_name+'-'+that.other_entity, - 'name': 'association', - 'label': label, - 'entity_name': that.entity_name, - 'other_entity': that.other_entity - }); - //TODO I18N var header_message = that.other_entity + '(s) enrolled in ' + that.entity_name + ' ' + that.pkey; @@ -449,12 +441,14 @@ function ipa_association_facet(spec) { 'id': that.entity_name+'-'+that.other_entity, html: $('

    ',{ html: header_message }) }).appendTo(container); + that.table = ipa_association_widget({ 'id': that.entity_name+'-'+that.other_entity, 'name': that.other_entity, - 'label': IPA.metadata[that.other_entity].label, + 'label': label, 'entity_name': that.entity_name, - 'other_entity': that.other_entity + 'other_entity': that.other_entity, + 'facet': that }); var span = $('', { 'name': 'association' }).appendTo(container); diff --git a/install/static/details.js b/install/static/details.js index 9bf54a8fb3744f733cfede2f1e191d44597d05ff..3b4edda6c5ac751cbaa4c897bf2ba34b2458a051 100644 --- a/install/static/details.js +++ b/install/static/details.js @@ -454,8 +454,7 @@ function ipa_details_create(container) 'class': 'content' }).appendTo(container); - var entity_container = $('#' + that.entity_name); - var action_panel = $('.action-panel', entity_container); + var action_panel = that.get_action_panel(); var ul = $('ul', action_panel); var buttons = $('
  • ', { diff --git a/install/static/entity.js b/install/static/entity.js index d117d881ced80d1d1c465910bb29370c8e5e08bc..25a9fd3106c29d28679f6fc365f803d8d2e9e9d0 100644 --- a/install/static/entity.js +++ b/install/static/entity.js @@ -44,7 +44,7 @@ function ipa_facet(spec) { that._entity_name = entity_name; }); - that.setup_views = ipa_facet_setup_views; + that.create_action_panel = ipa_facet_create_action_panel; that.superior = function(name) { var method = that[name]; @@ -66,6 +66,14 @@ function ipa_facet(spec) { function load() { } + that.get_client_area = function() { + return $('#' + that.entity_name+' .client'); + }; + + that.get_action_panel = function() { + return $('#' + that.entity_name+' .action-panel'); + }; + that.facet_init = that.init; that.facet_create = that.create; that.facet_setup = that.setup; @@ -325,7 +333,7 @@ function ipa_entity_setup(container) { container.empty(); - facet.setup_views(container); + facet.create_action_panel(container); facet.create(container); container.children().last().addClass('client'); facet.setup(container); @@ -333,7 +341,16 @@ function ipa_entity_setup(container) { } -function action_panel(entity_name){ + +function ipa_facet_create_action_panel(container) { + + var that = this; + var entity_name = that.entity_name; + + var action_panel = $('
    ', { + "class": "action-panel", + html: $('

    Actions

    ') + }).appendTo(container); function build_link(other_facet,label,other_entity){ var li = $('
  • ', { @@ -345,7 +362,7 @@ function action_panel(entity_name){ if($(this).hasClass('entity-facet-disabled')){ return false; } - var this_pkey = $('.action-panel input[id=pkey]').val(); + var this_pkey = $('input[id=pkey]', action_panel).val(); IPA.switch_and_show_page( entity_name, other_facet_name, this_pkey, other_entity); @@ -357,19 +374,15 @@ function action_panel(entity_name){ return li; } - var div = $('
    ', { - "class":"action-panel", - html: $('

    Actions

    ') - }); - /*Note, for debugging purposes, it is useful to set var pkey_type = 'text';*/ var pkey_type = 'hidden'; - $('', - {'type': pkey_type, - id:'pkey', - name:'pkey'}).appendTo(div); + $('', { + 'type': pkey_type, + id:'pkey', + name:'pkey' + }).appendTo(action_panel); - var ul = $('
      ', {'class': 'action'}).appendTo(div); + var ul = $('
        ', {'class': 'action'}).appendTo(action_panel); var entity = IPA.get_entity(entity_name); var facet_name = ipa_current_facet(entity); @@ -380,6 +393,7 @@ function action_panel(entity_name){ if (other_facet.label) { ul.append(build_link(other_facet,other_facet.label)); + } else { // For now empty label indicates an association facet var attribute_members = IPA.metadata[entity_name].attribute_members; for (var attribute_member in attribute_members) { @@ -392,19 +406,12 @@ function action_panel(entity_name){ } } } + /*When we land on the search page, disable all facets that require a pkey until one is selected*/ if (facet_name === 'search'){ - $('.entity-facet', div).addClass('entity-facet-disabled'); + $('.entity-facet', action_panel).addClass('entity-facet-disabled'); } - return div; -} - -function ipa_facet_setup_views(container) { - - var facet = this; - var entity_name = facet.entity_name; - action_panel(entity_name).appendTo(container); + return action_panel; } - diff --git a/install/static/hbac.js b/install/static/hbac.js index 894b2f4a01e0d00f162549a1d8a4def37d15b331..12883efa31122cd48398cae94688e41359ebd2e6 100755 --- a/install/static/hbac.js +++ b/install/static/hbac.js @@ -120,31 +120,18 @@ function ipa_hbac_search_facet(spec) { 'label': 'Cull Disabled Rules' })); */ - var entity_container = $('#' + that.entity_name); - var action_panel = $('.action-panel', entity_container); + var action_panel = that.get_action_panel(); var ul = $('ul', action_panel); $('
      • ', { title: 'hbacsvc', - text: 'HBAC Services', - 'click': function() { - var state = {}; - state['entity'] = 'hbacsvc'; - nav_push_state(state); - return false; - } + text: 'HBAC Services' }).appendTo(ul); $('
      • ', { title: 'hbacsvcgroup', - text: 'HBAC Service Groups', - 'click': function() { - var state = {}; - state['entity'] = 'hbacsvcgroup'; - nav_push_state(state); - return false; - } + text: 'HBAC Service Groups' }).appendTo(ul); that.search_facet_create(container); @@ -156,6 +143,29 @@ function ipa_hbac_search_facet(spec) { }; + that.setup = function(container) { + + that.search_facet_setup(container); + + var action_panel = that.get_action_panel(); + + var li = $('li[title=hbacsvc]', action_panel); + li.click(function() { + var state = {}; + state['entity'] = 'hbacsvc'; + nav_push_state(state); + return false; + }); + + li = $('li[title=hbacsvcgroup]', action_panel); + li.click(function() { + var state = {}; + state['entity'] = 'hbacsvcgroup'; + nav_push_state(state); + return false; + }); + }; + return that; } diff --git a/install/static/hbacsvc.js b/install/static/hbacsvc.js index 012c92a354a81ecc37a8d2eebaedb562d749ddea..13135da243080dfae38b1a472215ed7ede62e1c1 100755 --- a/install/static/hbacsvc.js +++ b/install/static/hbacsvc.js @@ -26,8 +26,6 @@ function ipa_hbacsvc() { 'name': 'hbacsvc' }); - that.superior_init = that.superior('init'); - that.init = function() { var dialog = ipa_hbacsvc_add_dialog({ @@ -49,7 +47,7 @@ function ipa_hbacsvc() { }); that.add_facet(facet); - that.superior_init(); + that.entity_init(); }; return that; @@ -82,22 +80,21 @@ function ipa_hbacsvc_search_facet(spec) { var that = ipa_search_facet(spec); - that.superior_init = that.superior('init'); - that.superior_create = that.superior('create'); - that.superior_setup = that.superior('setup'); + that.get_action_panel = function() { + return $('#hbac .action-panel'); + }; that.init = function() { that.create_column({name:'cn', label:'Service', primary_key: true}); that.create_column({name:'description', label:'Description'}); - that.superior_init(); + that.search_facet_init(); }; that.create = function(container) { - var entity_container = $('#' + that.entity_name); - var action_panel = $('.action-panel', entity_container); + var action_panel = that.get_action_panel(); var ul = $('ul', action_panel); @@ -123,7 +120,7 @@ function ipa_hbacsvc_search_facet(spec) { } }).appendTo(ul); - that.superior_create(container); + that.search_facet_create(container); // TODO: replace with IPA.metadata[that.entity_name].label container.children().last().prepend( @@ -149,6 +146,10 @@ function ipa_hbacsvc_details_facet(spec) { that.superior_create = that.superior('create'); that.superior_setup = that.superior('setup'); + that.get_action_panel = function() { + return $('#hbac .action-panel'); + }; + that.init = function() { var section = ipa_details_list_section({ diff --git a/install/static/hbacsvcgroup.js b/install/static/hbacsvcgroup.js index 30cb2c86e8c3b2bdfa441cde87d357a04d79a06d..212185ac6e6a7dc4fe768bf8e31c6a781a7299aa 100755 --- a/install/static/hbacsvcgroup.js +++ b/install/static/hbacsvcgroup.js @@ -26,8 +26,6 @@ function ipa_hbacsvcgroup() { 'name': 'hbacsvcgroup' }); - that.superior_init = that.superior('init'); - that.init = function() { that.create_association({ @@ -55,12 +53,12 @@ function ipa_hbacsvcgroup() { }); that.add_facet(facet); - facet = ipa_association_facet({ + facet = ipa_hbacsvcgroup_association_facet({ 'name': 'associate' }); that.add_facet(facet); - that.superior_init(); + that.entity_init(); }; return that; @@ -93,23 +91,22 @@ function ipa_hbacsvcgroup_search_facet(spec) { var that = ipa_search_facet(spec); - that.superior_init = that.superior('init'); - that.superior_create = that.superior('create'); - that.superior_setup = that.superior('setup'); + that.get_action_panel = function() { + return $('#hbac .action-panel'); + }; that.init = function() { that.create_column({name:'cn', label:'Group', primary_key: true}); that.create_column({name:'description', label:'Description'}); - that.superior_init(); + that.search_facet_init(); }; that.create = function(container) { - var entity_container = $('#' + that.entity_name); - var action_panel = $('.action-panel', entity_container); - + var action_panel = that.get_action_panel(); + var ul = $('ul', action_panel); $('
      • ', { @@ -134,7 +131,8 @@ function ipa_hbacsvcgroup_search_facet(spec) { } }).appendTo(ul); - that.superior_create(container); + that.search_facet_create(container); + // TODO: replace with IPA.metadata[that.entity_name].label container.children().last().prepend( $('

        ', { 'html': 'HBAC Service Groups' })); @@ -152,9 +150,9 @@ function ipa_hbacsvcgroup_details_facet(spec) { var that = ipa_details_facet(spec); - that.superior_init = that.superior('init'); - that.superior_create = that.superior('create'); - that.superior_setup = that.superior('setup'); + that.get_action_panel = function() { + return $('#hbac .action-panel'); + }; that.init = function() { @@ -167,7 +165,20 @@ function ipa_hbacsvcgroup_details_facet(spec) { section.create_field({ 'name': 'cn', 'label': 'Name' }); section.create_field({ 'name': 'description', 'label': 'Description' }); - that.superior_init(); + that.details_facet_init(); + }; + + return that; +} + +function ipa_hbacsvcgroup_association_facet(spec) { + + spec = spec || {}; + + var that = ipa_association_facet(spec); + + that.get_action_panel = function() { + return $('#hbac .action-panel'); }; return that; diff --git a/install/static/search.js b/install/static/search.js index 91c6641bbbf2bdbeaa5096497e75811f5f9d2783..03d4cac5a61c510943c79c545b95b93d24e9a1c1 100644 --- a/install/static/search.js +++ b/install/static/search.js @@ -28,7 +28,7 @@ function ipa_search_widget(spec) { var that = ipa_table_widget(spec); - that.superior_create = that.superior('create'); + that.facet = spec.facet; that.create = function(container) { @@ -52,8 +52,7 @@ function ipa_search_widget(spec) { 'value': 'Find' }).appendTo(search_filter); - var entity_container = $('#' + that.entity_name); - var action_panel = $('.action-panel', entity_container); + var action_panel = that.facet.get_action_panel(); var ul = $('ul', action_panel); var li = $('
      • ').prependTo(ul); @@ -78,7 +77,7 @@ function ipa_search_widget(spec) { 'class': 'search-results' }).appendTo(container); - that.superior_create(container); + that.table_create(container); }; that.setup = function(container) { @@ -95,8 +94,7 @@ function ipa_search_widget(spec) { }); button.replaceWith(that.find_button); - var entity_container = $('#' + that.entity_name); - var action_panel = $('.action-panel', entity_container); + var action_panel = that.facet.get_action_panel(); var search_buttons = $('.search-buttons', action_panel); button = $('input[name=remove]', search_buttons); @@ -143,19 +141,21 @@ function ipa_search_widget(spec) { count += 1; pkey = $(this).val(); }); + + var action_panel = that.facet.get_action_panel(); if(count == 1){ - $('.action-panel li.entity-facet'). + $('li.entity-facet', action_panel). removeClass('entity-facet-disabled'); var state = {}; - $('.action-panel input[id=pkey]').val(pkey); + $('input[id=pkey]', action_panel).val(pkey); }else{ - $('.action-panel li.entity-facet'). + $('li.entity-facet', action_panel). addClass('entity-facet-disabled'); - $('.action-panel input').val(null); + $('input', action_panel).val(null); } return false; - } + }; that.remove = function(container) { @@ -262,7 +262,7 @@ function ipa_search_facet(spec) { var that = ipa_facet(spec); that.init = spec.init || init; - that.create = spec.create || ipa_search_facet_create; + that.create = spec.create || create; that.setup = spec.setup || setup; that.refresh = spec.refresh || refresh; @@ -306,7 +306,8 @@ function ipa_search_facet(spec) { that.table = ipa_search_widget({ 'id': that.entity_name+'-search', 'name': 'search', 'label': IPA.metadata[that.entity_name].label, - 'entity_name': that.entity_name + 'entity_name': that.entity_name, + 'facet': that }); for (var i=0; i