From 4270e26adb56b6d1b7a9e80433581b82519d9eec Mon Sep 17 00:00:00 2001 From: Adam Young Date: Fri, 18 Mar 2011 16:43:54 -0400 Subject: define entities using builder and more declarative syntax merged hbac and sudo in to single files associaton facet and table supports linking --- install/ui/hbac.js | 997 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 997 insertions(+) create mode 100644 install/ui/hbac.js (limited to 'install/ui/hbac.js') diff --git a/install/ui/hbac.js b/install/ui/hbac.js new file mode 100644 index 000000000..4b9fe1ed3 --- /dev/null +++ b/install/ui/hbac.js @@ -0,0 +1,997 @@ +/*jsl:import ipa.js */ + +/* Authors: + * Endi Sukma Dewata + * + * Copyright (C) 2010 Red Hat + * see file 'COPYING' for use and warranty information + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* REQUIRES: ipa.js, details.js, search.js, add.js, entity.js */ + +IPA.entity_factories.hbacrule = function () { + return IPA.entity_builder(). + entity('hbacrule'). + search_facet({ + columns:['cn','usercategory','hostcategory','ipaenabledflag', + 'servicecategory','sourcehostcategory'], + add_fields:[ + 'cn', + { + factory: IPA.radio_widget, + 'name': 'accessruletype', + 'options': [ + { 'value': 'allow', + 'label': IPA.messages.objects.hbacrule.allow + }, + { 'value': 'deny', + 'label': IPA.messages.objects.hbacrule.deny + }], + 'undo': false + }]}). + facet(IPA.hbacrule_details_facet({ + 'name': 'details' + })). + build(); +}; + +IPA.entity_factories.hbacsvc = function () { + return IPA.entity_builder(). + entity('hbacsvc'). + search_facet({ + columns:['cn','description'], + add_fields:['cn','description']}). + details_facet([{ + section : 'general', + label: IPA.messages.details.general, + fields:[ 'cn', 'description']}]). + build(); +}; + + +IPA.entity_factories.hbacsvcgroup = function () { + return IPA.entity_builder(). + entity('hbacsvcgroup'). + search_facet({ + columns:['cn', 'description'], + add_fields:['cn', 'description']}). + details_facet([ + { + section: 'general', + label: IPA.messages.details.general, + fields:['cn','description'] + }, + { + section: 'services', + label: IPA.messages.objects.hbacsvcgroup.services, + fields:[{ + factory: IPA.hbacsvcgroup_member_hbacsvc_table_widget, + name: 'member_hbacsvc', + label: IPA.messages.objects.hbacsvcgroup.services, + other_entity: 'hbacsvc', + save_values: false + }] + }]). + build(); +}; + +IPA.hbacsvcgroup_member_hbacsvc_table_widget = function (spec) { + + spec = spec || {}; + + var that = IPA.association_table_widget(spec); + + that.init = function() { + + var column = that.create_column({ + name: 'cn', + primary_key: true, + width: '150px' + }); + + column.setup = function(container, record) { + container.empty(); + + var value = record[column.name]; + value = value ? value.toString() : ''; + + $('', { + 'href': '#'+value, + 'html': value, + 'click': function (value) { + return function() { + var state = IPA.tab_state(that.other_entity); + state[that.other_entity + '-facet'] = 'details'; + state[that.other_entity + '-pkey'] = value; + $.bbq.pushState(state); + return false; + }; + }(value) + }).appendTo(container); + }; + + that.create_column({ + name: 'description', + width: '350px' + }); + + that.create_adder_column({ + name: 'cn', + primary_key: true, + width: '100px' + }); + + that.create_adder_column({ + name: 'description', + width: '100px' + }); + + that.association_table_widget_init(); + }; + + return that; +}; + + + +IPA.hbacrule_details_facet = function (spec) { + + spec = spec || {}; + + var that = IPA.details_facet(spec); + + that.init = function() { + + var section; + + if (IPA.layout) { + section = that.create_section({ + 'name': 'general', + 'label': IPA.messages.details.general, + 'template': 'hbacrule-details-general.html #contents' + }); + + } else { + section = IPA.hbacrule_details_general_section({ + 'name': 'general', + 'label': IPA.messages.details.general + }); + that.add_section(section); + } + + section.text({name: 'cn', read_only: true}); + section.radio({name: 'accessruletype'}); + section.textarea({name: 'description'}); + section.radio({name: 'ipaenabledflag'}); + + var param_info = IPA.get_entity_param('hbacrule', 'usercategory'); + + if (IPA.layout) { + section = that.create_section({ + 'name': 'user', + 'label': IPA.messages.objects.hbacrule.user, + 'template': 'hbacrule-details-user.html #contents' + }); + + } else { + section = IPA.rule_details_section({ + 'name': 'user', + 'label': IPA.messages.objects.hbacrule.user, + 'text': param_info.doc+':', + 'field_name': 'usercategory', + 'options': [ + { 'value': 'all', 'label': IPA.messages.objects.hbacrule.anyone }, + { 'value': '', 'label': IPA.messages.objects.hbacrule.specified_users } + ], + 'tables': [ + { 'field_name': 'memberuser_user' }, + { 'field_name': 'memberuser_group' } + ] + }); + that.add_section(section); + } + + var category = section.radio({ name: 'usercategory' }); + section.add_field(IPA.rule_association_table_widget({ + 'id': that.entity_name+'-memberuser_user', + 'name': 'memberuser_user', 'category': category, + 'other_entity': 'user', 'add_method': 'add_user', 'remove_method': 'remove_user' + })); + section.add_field(IPA.rule_association_table_widget({ + 'id': that.entity_name+'-memberuser_group', + 'name': 'memberuser_group', 'category': category, + 'other_entity': 'group', 'add_method': 'add_user', 'remove_method': 'remove_user' + })); + + param_info = IPA.get_entity_param('hbacrule', 'hostcategory'); + + if (IPA.layout) { + section = that.create_section({ + 'name': 'host', + 'label': IPA.messages.objects.hbacrule.host, + 'template': 'hbacrule-details-host.html #contents' + }); + + } else { + section = IPA.rule_details_section({ + 'name': 'host', + 'label': IPA.messages.objects.hbacrule.host, + 'text': param_info.doc+':', + 'field_name': 'hostcategory', + 'options': [ + { 'value': 'all', 'label': IPA.messages.objects.hbacrule.any_host }, + { 'value': '', 'label': IPA.messages.objects.hbacrule.specified_hosts } + ], + 'tables': [ + { 'field_name': 'memberhost_host' }, + { 'field_name': 'memberhost_hostgroup' } + ] + }); + that.add_section(section); + } + + category = section.radio({ 'name': 'hostcategory' }); + section.add_field(IPA.rule_association_table_widget({ + 'id': that.entity_name+'-memberhost_host', + 'name': 'memberhost_host', 'category': category, + 'other_entity': 'host', 'add_method': 'add_host', 'remove_method': 'remove_host' + })); + section.add_field(IPA.rule_association_table_widget({ + 'id': that.entity_name+'-memberhost_hostgroup', + 'name': 'memberhost_hostgroup', 'category': category, + 'other_entity': 'hostgroup', 'add_method': 'add_host', 'remove_method': 'remove_host' + })); + + param_info = IPA.get_entity_param('hbacrule', 'servicecategory'); + + if (IPA.layout) { + section = that.create_section({ + 'name': 'service', + 'label': IPA.messages.objects.hbacrule.service, + 'template': 'hbacrule-details-service.html #contents' + }); + + } else { + section = IPA.rule_details_section({ + 'name': 'service', + 'label': IPA.messages.objects.hbacrule.service, + 'text': param_info.doc+':', + 'field_name': 'servicecategory', + 'options': [ + { 'value': 'all', 'label': IPA.messages.objects.hbacrule.any_service }, + { 'value': '', 'label': IPA.messages.objects.hbacrule.specified_services } + ], + 'tables': [ + { 'field_name': 'memberservice_hbacsvc' }, + { 'field_name': 'memberservice_hbacsvcgroup' } + ] + }); + that.add_section(section); + } + + category = section.radio({ 'name': 'servicecategory' }); + section.add_field(IPA.rule_association_table_widget({ + 'id': that.entity_name+'-memberservice_hbacsvc', + 'name': 'memberservice_hbacsvc', 'category': category, + 'other_entity': 'hbacsvc', 'add_method': 'add_service', 'remove_method': 'remove_service' + })); + section.add_field(IPA.rule_association_table_widget({ + 'id': that.entity_name+'-memberservice_hbacsvcgroup', + 'name': 'memberservice_hbacsvcgroup', 'category': category, + 'other_entity': 'hbacsvcgroup', 'add_method': 'add_service', 'remove_method': 'remove_service' + })); + + param_info = IPA.get_entity_param('hbacrule', 'sourcehostcategory'); + + if (IPA.layout) { + section = that.create_section({ + 'name': 'sourcehost', + 'label': IPA.messages.objects.hbacrule.sourcehost, + 'template': 'hbacrule-details-sourcehost.html #contents' + }); + + } else { + section = IPA.rule_details_section({ + 'name': 'sourcehost', + 'label': IPA.messages.objects.hbacrule.sourcehost, + 'text': param_info.doc+':', + 'field_name': 'sourcehostcategory', + 'options': [ + { 'value': 'all', 'label': IPA.messages.objects.hbacrule.any_host }, + { 'value': '', 'label': IPA.messages.objects.hbacrule.specified_hosts } + ], + 'tables': [ + { 'field_name': 'sourcehost_host' }, + { 'field_name': 'sourcehost_hostgroup' } + ] + }); + that.add_section(section); + } + + category = section.radio({ 'name': 'sourcehostcategory' }); + section.add_field(IPA.rule_association_table_widget({ + 'id': that.entity_name+'-sourcehost_host', + 'name': 'sourcehost_host', 'category': category, + 'other_entity': 'host', 'add_method': 'add_sourcehost', 'remove_method': 'remove_sourcehost' + })); + section.add_field(IPA.rule_association_table_widget({ + 'id': that.entity_name+'-sourcehost_hostgroup', + 'name': 'sourcehost_hostgroup', 'category': category, + 'other_entity': 'hostgroup', 'add_method': 'add_sourcehost', 'remove_method': 'remove_sourcehost' + })); + that.details_facet_init(); + }; + + that.update = function() { + + var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; + + var modify_operation = { + 'execute': false, + 'command': IPA.command({ + 'method': that.entity_name+'_mod', + 'args': [pkey], + 'options': {'all': true, 'rights': true} + }) + }; + + var remove_accesstime = { + 'template': IPA.command({ + 'method': that.entity_name+'_remove_accesstime', + 'args': [pkey], + 'options': {'all': true, 'rights': true} + }), + 'commands': [] + }; + + var categories = { + 'usercategory': { + 'remove_values': false + }, + 'hostcategory': { + 'remove_values': false + }, + 'servicecategory': { + 'remove_values': false + }, + 'sourcehostcategory': { + 'remove_values': false + } + }; + + var member_operations = { + 'memberuser': { + 'category': 'usercategory', + 'has_values': false, + 'command': IPA.command({ + 'method': that.entity_name+'_remove_user', + 'args': [pkey], + 'options': {'all': true, 'rights': true} + }) + }, + 'memberhost': { + 'category': 'hostcategory', + 'has_values': false, + 'command': IPA.command({ + 'method': that.entity_name+'_remove_host', + 'args': [pkey], + 'options': {'all': true, 'rights': true} + }) + }, + 'memberservice': { + 'category': 'servicecategory', + 'has_values': false, + 'command': IPA.command({ + 'method': that.entity_name+'_remove_service', + 'args': [pkey], + 'options': {'all': true, 'rights': true} + }) + }, + 'sourcehost': { + 'category': 'sourcehostcategory', + 'has_values': false, + 'command': IPA.command({ + 'method': that.entity_name+'_remove_sourcehost', + 'args': [pkey], + 'options': {'all': true, 'rights': true} + }) + } + }; + + var enable_operation = { + 'execute': false, + 'command': IPA.command({ + 'method': that.entity_name+'_enable', + 'args': [pkey], + 'options': {'all': true, 'rights': true} + }) + }; + + for (var i=0; i= 0) { + // prepare command to remove members if needed + var attribute = field.name.substring(0, p); + var other_entity = field.name.substring(p+1); + + if (values.length) { + member_operations[attribute].command.set_option(other_entity, values.join(',')); + member_operations[attribute].has_values = true; + } + continue; + } + + // skip unchanged field + if (!field.is_dirty(span)) continue; + + // check enable/disable + if (field.name == 'ipaenabledflag') { + if (values[0] == 'FALSE') enable_operation.command.method = that.entity_name+'_disable'; + enable_operation.execute = true; + continue; + } + + if (field.name == 'accesstime') { + // if accesstime is dirty, it means 'Any Time' is selected, + // so existing values have to be removed + for (var k=0; k', { + 'style': 'width: 100%;' + }).appendTo(container); + + var tr = $('').appendTo(table); + + var td = $('', { + 'style': 'width: 100px; text-align: right;' + }).appendTo(tr); + + var param_info = IPA.get_entity_param('hbacrule', 'cn'); + td.append(param_info.label+':'); + + td = $('').appendTo(tr); + + var field = that.get_field('cn'); + var span = $('', { 'name': 'cn' }).appendTo(td); + + $('