From b9ad279ad2d8d93dd501115a028783cf8fe7fcbd Mon Sep 17 00:00:00 2001 From: Adam Young Date: Wed, 19 Jan 2011 12:26:14 -0500 Subject: rename static to ui Directory rename --- install/ui/sudorule.js | 1127 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1127 insertions(+) create mode 100644 install/ui/sudorule.js (limited to 'install/ui/sudorule.js') diff --git a/install/ui/sudorule.js b/install/ui/sudorule.js new file mode 100644 index 00000000..94f3247b --- /dev/null +++ b/install/ui/sudorule.js @@ -0,0 +1,1127 @@ +/*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.sudorule = function () { + + var that = IPA.entity({ + 'name': 'sudorule' + }); + + that.init = function() { + + var dialog = IPA.sudorule_add_dialog({ + 'name': 'add', + 'title': 'Add New Rule' + }); + that.add_dialog(dialog); + dialog.init(); + + var facet = IPA.sudorule_search_facet({ + 'name': 'search', + 'label': 'Search' + }); + that.add_facet(facet); + + facet = IPA.sudorule_details_facet({ + 'name': 'details' + }); + that.add_facet(facet); + + that.entity_init(); + }; + + return that; +}; + + +IPA.add_entity(IPA.sudorule()); + + +IPA.sudorule_add_dialog = function (spec) { + + spec = spec || {}; + + var that = IPA.add_dialog(spec); + + that.init = function() { + + that.add_field(IPA.text_widget({name: 'cn', undo: false})); + + that.add_dialog_init(); + }; + + return that; +}; + + +IPA.sudorule_search_facet = function (spec) { + + spec = spec || {}; + + var that = IPA.search_facet(spec); + + that.init = function() { + + that.create_column({name:'cn'}); + that.create_column({name:'description'}); + that.create_column({name:'cmdcategory'}); + + that.search_facet_init(); + }; + + return that; +}; + + +IPA.sudorule_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': 'General', + 'template': 'sudorule-details-general.html #contents' + }); + + } else { + section = IPA.sudorule_details_general_section({ + 'name': 'general', + 'label': 'General' + }); + that.add_section(section); + } + + section.create_text({ 'name': 'cn', 'read_only': true }); + section.create_textarea({ 'name': 'description' }); + section.create_radio({ 'name': 'ipaenabledflag' }); + + section = IPA.rule_details_section({ + 'name': 'user', + 'label': 'Who', + 'field_name': 'usercategory', + 'options': [ + { 'value': 'all', 'label': 'Anyone' }, + { 'value': '', 'label': 'Specified Users and Groups' } + ], + 'tables': [ + { 'field_name': 'memberuser_user' }, + { 'field_name': 'memberuser_group' } + ] + }); + that.add_section(section); + + var category = section.create_radio({ name: 'usercategory', label: 'User category' }); + section.add_field(IPA.sudorule_association_table_widget({ + 'id': that.entity_name+'-memberuser_user', + 'name': 'memberuser_user', 'label': 'Users', 'category': category, + 'other_entity': 'user', 'add_method': 'add_user', 'remove_method': 'remove_user', + 'external': 'externaluser' + })); + section.add_field(IPA.sudorule_association_table_widget({ + 'id': that.entity_name+'-memberuser_group', + 'name': 'memberuser_group', 'label': 'Groups', 'category': category, + 'other_entity': 'group', 'add_method': 'add_user', 'remove_method': 'remove_user' + })); + + section = IPA.rule_details_section({ + 'name': 'host', + 'label': 'Access this host', + 'field_name': 'hostcategory', + 'options': [ + { 'value': 'all', 'label': 'Any Host' }, + { 'value': '', 'label': 'Specified Hosts and Groups' } + ], + 'tables': [ + { 'field_name': 'memberhost_host' }, + { 'field_name': 'memberhost_hostgroup' } + ] + }); + that.add_section(section); + + category = section.create_radio({ 'name': 'hostcategory', 'label': 'Host category' }); + section.add_field(IPA.sudorule_association_table_widget({ + 'id': that.entity_name+'-memberhost_host', + 'name': 'memberhost_host', 'label': 'Host', 'category': category, + 'other_entity': 'host', 'add_method': 'add_host', 'remove_method': 'remove_host', + 'external': 'externalhost' + })); + section.add_field(IPA.sudorule_association_table_widget({ + 'id': that.entity_name+'-memberhost_hostgroup', + 'name': 'memberhost_hostgroup', 'label': 'Groups', 'category': category, + 'other_entity': 'hostgroup', 'add_method': 'add_host', 'remove_method': 'remove_host' + })); + + section = IPA.sudorule_details_command_section({ + 'name': 'command', + 'label': 'Run Commands' + }); + that.add_section(section); + + section = IPA.sudorule_details_runas_section({ + 'name': 'runas', + 'label': 'As Whom' + }); + that.add_section(section); + + 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 categories = { + 'usercategory': { + 'remove_values': false + }, + 'hostcategory': { + 'remove_values': false + }, + 'cmdcategory': { + 'remove_values': false + }, + 'ipasudorunasusercategory': { + 'remove_values': false + }, + 'ipasudorunasgroupcategory': { + '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} + }) + }, + 'memberallowcmd': { + 'category': 'cmdcategory', + 'has_values': false, + 'command': IPA.command({ + 'method': that.entity_name+'_remove_allow_command', + 'args': [pkey], + 'options': {'all': true, 'rights': true} + }) + }, + 'ipasudorunas': { + 'category': 'ipasudorunasusercategory', + 'has_values': false, + 'command': IPA.command({ + 'method': that.entity_name+'_remove_runasuser', + 'args': [pkey], + 'options': {'all': true, 'rights': true} + }) + }, + 'ipasudorunasgroup': { + 'category': 'ipasudorunasgroupcategory', + 'has_values': false, + 'command': IPA.command({ + 'method': that.entity_name+'_remove_runasgroup', + '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 (member_operations[attribute] && 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 (categories[field.name] && values[0] == 'all') { + categories[field.name].remove_values = true; + } + + // use setattr/addattr if param_info not available + if (!param_info) { + for (var k=0; k', { + 'style': 'width: 100%;' + }).appendTo(container); + + var param_info = IPA.get_param_info(that.entity_name, 'cn'); + + var tr = $('').appendTo(table); + + var td = $('', { + style: 'width: 100px; text-align: right;', + html: param_info.label+':', + title: param_info ? param_info.doc : 'cn' + }).appendTo(tr); + + td = $('').appendTo(tr); + + var span = $('', { + name: 'cn', + title: param_info ? param_info.doc : 'cn' + }).appendTo(td); + + $('', { + 'type': 'text', + 'name': 'cn', + 'size': 30 + }).appendTo(span); + + span.append(' '); + + $('', { + 'name': 'undo', + 'class': 'ui-state-highlight ui-corner-all', + 'style': 'display: none;', + 'html': 'undo' + }).appendTo(span); + + param_info = IPA.get_param_info(that.entity_name, 'description'); + + tr = $('').appendTo(table); + + td = $('', { + style: 'text-align: right; vertical-align: top;', + html: param_info.label+':', + title: param_info ? param_info.doc : 'description' + }).appendTo(tr); + + td = $('').appendTo(tr); + + span = $('', { + name: 'description', + title: param_info ? param_info.doc : 'description' + }).appendTo(td); + + $('