URL: https://github.com/freeipa/freeipa/pull/400 Author: pvomacka Title: #400: WebUI: Certificate Mapping Action: synchronized
To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/400/head:pr400 git checkout pr400
From 740a6ed90575051107bae7c0987c62f981308fc9 Mon Sep 17 00:00:00 2001 From: Pavel Vomacka <pvoma...@redhat.com> Date: Mon, 16 Jan 2017 13:59:16 +0100 Subject: [PATCH 1/4] WebUI: Add possibility to set field always writable If field will have set attribute 'always_writable' to true, then 'no_update' flag will be ingored. Used in command user-{add,remove}-certmap which needs to be writable in WebUI and also needs to be omitted from user-mod command. Part of: https://fedorahosted.org/freeipa/ticket/6601 --- install/ui/src/freeipa/field.js | 43 +++++++++++++++++++++++++++++++++++++++- install/ui/src/freeipa/widget.js | 35 ++++++++++---------------------- 2 files changed, 52 insertions(+), 26 deletions(-) diff --git a/install/ui/src/freeipa/field.js b/install/ui/src/freeipa/field.js index d70a778..9f287dd 100644 --- a/install/ui/src/freeipa/field.js +++ b/install/ui/src/freeipa/field.js @@ -484,7 +484,16 @@ field.field = IPA.field = function(spec) { writable = false; } - if (that.metadata.flags && array.indexOf(that.metadata.flags, 'no_update') > -1) { + // In case that field has set always_writable attribute, then + // 'no_update' flag is ignored in WebUI. It is done because of + // commands like user-{add,remove}-certmap. They operate with user's + // attribute, which cannot be changed using user-mod, but only + // using command user-{add,remove}-certmap. Therefore it has set + // 'no_update' flag, but we need to show 'Add', 'Remove' buttons in + // WebUI. + if (that.metadata.flags && + array.indexOf(that.metadata.flags, 'no_update') > -1 && + !that.always_writable) { writable = false; } } @@ -1259,6 +1268,37 @@ field.certs_field = IPA.certs_field = function(spec) { return that; }; + +/** + * Used along with custom_command_multivalued widget + * + * - by default has `w_if_no_aci` to workaround missing object class + * - by default has always_writable=true to workaround aci rights + * + * @class + * @alternateClassName IPA.custom_command_multivalued_field + * @extends IPA.field + */ +field.certmap_command_multivalued_field = function(spec) { + + spec = spec || {}; + spec.flags = spec.flags || ['w_if_no_aci']; + + var that = IPA.field(spec); + + /** + * Set field always writable in case that it is set to true + * @param Boolean always_writable + */ + that.always_writable = spec.always_writable === undefined ? true : + spec.always_writable; + + return that; +}; + + +IPA.custom_command_multivalued_field = field.custom_command_multivalued_field; + /** * SSH Keys Adapter * @class @@ -1652,6 +1692,7 @@ field.register = function() { f.register('checkbox', field.checkbox_field); f.register('checkboxes', field.field); f.register('combobox', field.field); + f.register('certmap_multivalued', field.certmap_command_multivalued_field); f.register('datetime', field.datetime_field); f.register('enable', field.enable_field); f.register('entity_select', field.field); diff --git a/install/ui/src/freeipa/widget.js b/install/ui/src/freeipa/widget.js index 15f0126..b7028a9 100644 --- a/install/ui/src/freeipa/widget.js +++ b/install/ui/src/freeipa/widget.js @@ -1534,12 +1534,8 @@ IPA.custom_command_multivalued_widget = function(spec) { * Called on error of add command. Override point. */ that.on_error_add = function(xhr, text_status, error_thrown) { - that.adder_dialog.focus_first_element(); - - if (error_thrown.message) { - var msg = error_thrown.message; - IPA.notify(msg, 'error'); - } + that.adder_dialog.show(); + exp.focus_invalid(that.adder_dialog); }; /** @@ -1599,27 +1595,16 @@ IPA.custom_command_multivalued_widget = function(spec) { name: 'custom-add-dialog' }; - that.adder_dialog = IPA.dialog(spec); - that.adder_dialog.create_button({ - name: 'add', - label: '@i18n:buttons.add', - click: function() { - if (!that.adder_dialog.validate()) { - exp.focus_invalid(that.adder_dialog); - } - else { - that.add(that.adder_dialog); - } + spec.on_ok = function() { + if (!that.adder_dialog.validate()) { + exp.focus_invalid(that.adder_dialog); } - }); - - that.adder_dialog.create_button({ - name: 'cancel', - label: '@i18n:buttons.cancel', - click: function() { - that.adder_dialog.close(); + else { + that.add(that.adder_dialog); } - }); + }; + + that.adder_dialog = IPA.custom_command_multivalued_dialog(spec); }; /* on button 'Add' on adder dialog click */ From 653b2c5a9ee9700967cddc8e62a039cfe2418b15 Mon Sep 17 00:00:00 2001 From: Pavel Vomacka <pvoma...@redhat.com> Date: Mon, 16 Jan 2017 14:13:42 +0100 Subject: [PATCH 2/4] WebUI: Create non editable row widget for mutlivalued widget Old krb-principal widget is changed to general one. And used also for ipacertmapdata in user. This widget make every line non-editable. Part of: https://fedorahosted.org/freeipa/ticket/6601 --- install/ui/src/freeipa/host.js | 3 ++- install/ui/src/freeipa/service.js | 3 ++- install/ui/src/freeipa/user.js | 3 ++- install/ui/src/freeipa/widget.js | 29 +++++++++++++++++++---------- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/install/ui/src/freeipa/host.js b/install/ui/src/freeipa/host.js index 87cf264..023530a 100644 --- a/install/ui/src/freeipa/host.js +++ b/install/ui/src/freeipa/host.js @@ -93,7 +93,8 @@ return { name: 'krbprincipalname', item_name: 'principal', child_spec: { - $type: 'krb_principal' + $type: 'non_editable_row', + data_name: 'krb-principal' } }, { diff --git a/install/ui/src/freeipa/service.js b/install/ui/src/freeipa/service.js index a6607d2..adae347 100644 --- a/install/ui/src/freeipa/service.js +++ b/install/ui/src/freeipa/service.js @@ -81,7 +81,8 @@ return { name: 'krbprincipalname', item_name: 'principal', child_spec: { - $type: 'krb_principal' + $type: 'non_editable_row', + data_name: 'krb-principal' } }, { diff --git a/install/ui/src/freeipa/user.js b/install/ui/src/freeipa/user.js index 7a08151..a36b65a 100644 --- a/install/ui/src/freeipa/user.js +++ b/install/ui/src/freeipa/user.js @@ -192,7 +192,8 @@ return { name: 'krbprincipalname', item_name: 'principal', child_spec: { - $type: 'krb_principal' + $type: 'non_editable_row', + data_name: 'krb-principal' } }, { diff --git a/install/ui/src/freeipa/widget.js b/install/ui/src/freeipa/widget.js index b7028a9..9b9d58d 100644 --- a/install/ui/src/freeipa/widget.js +++ b/install/ui/src/freeipa/widget.js @@ -1792,6 +1792,8 @@ IPA.custom_command_multivalued_widget = function(spec) { IPA.krb_principal_multivalued_widget = function (spec) { spec = spec || {}; + spec.child_spec = spec.child_spec || {}; + spec.child_spec.data_name = spec.child_spec.data_name || 'krb-principal'; spec.adder_dialog_spec = spec.adder_dialog_spec || { title: '@i18n:krbaliases.adder_title', @@ -1812,7 +1814,7 @@ IPA.krb_principal_multivalued_widget = function (spec) { that.create_remove_dialog_message = function(row) { var message = text.get('@i18n:krbaliases.remove_message'); - message = message.replace('${alias}', row.widget.principal_name); + message = message.replace('${alias}', row.widget.new_value); return message; }; @@ -1820,7 +1822,7 @@ IPA.krb_principal_multivalued_widget = function (spec) { that.create_remove_args = function(row) { var pkey = that.facet.get_pkey(); - var krbprincipalname = row.widget.principal_name; + var krbprincipalname = row.widget.new_value; krbprincipalname = [ krbprincipalname ]; var args = [ @@ -1847,22 +1849,27 @@ IPA.krb_principal_multivalued_widget = function (spec) { }; /** - * Widget which is used as row in kerberos aliases multivalued widget. - * It contains only string where is the principal alias name and delete button. + * Widget which is used as row in multivalued widget. Each row is just + * non-editable text field. * * @class * @extends IPA.input_widget */ -IPA.krb_principal_widget = function(spec) { + IPA.non_editable_row_widget = function(spec) { spec = spec || {}; var that = IPA.input_widget(); + /** + * Prefix of CSS class of each row. + */ + that.data_name = spec.data_name || 'non-editable'; + that.create = function(container) { that.widget_create(container); - that.principal_text = $('<span />', { - 'class': 'krb-principal-name', + that.data_text = $('<span />', { + 'class': that.data_name + '-data', text: '' }).appendTo(container); @@ -1875,19 +1882,20 @@ IPA.krb_principal_widget = function(spec) { that.update = function(value) { - var principal_name = value[0] || ''; + var single_value = value[0] || ''; - that.principal_name = principal_name; + that.new_value = single_value; that.update_text(); }; that.update_text = function() { - that.principal_text.text(that.principal_name); + that.data_text.text(that.new_value); }; return that; }; + /** * Option widget base * @@ -7161,6 +7169,7 @@ exp.register = function() { w.register('html', IPA.html_widget); w.register('link', IPA.link_widget); w.register('multivalued', IPA.multivalued_widget); + w.register('non_editable_row', IPA.non_editable_row_widget); w.register('custom_command_multivalued', IPA.custom_command_multivalued_widget); w.register('krb_principal_multivalued', From 9990e57b11f0d25ee306a3726693196fdcc8d649 Mon Sep 17 00:00:00 2001 From: Pavel Vomacka <pvoma...@redhat.com> Date: Mon, 27 Feb 2017 18:12:29 +0100 Subject: [PATCH 3/4] WebUI: Add Custom command multivalued adder dialog Adder dialog which is used along with custom_command_multivalued_widget. It behaivor of confirm dialog and adds fields which are necessary. Part of: https://fedorahosted.org/freeipa/ticket/6601 --- install/ui/src/freeipa/dialog.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/install/ui/src/freeipa/dialog.js b/install/ui/src/freeipa/dialog.js index 8552e76..5150527 100644 --- a/install/ui/src/freeipa/dialog.js +++ b/install/ui/src/freeipa/dialog.js @@ -1451,6 +1451,40 @@ IPA.confirm_dialog = function(spec) { return that; }; +/** + * Custom command multivalued dialog + * + * Combines confirmation dialog which could be reopen after unsucessful command + * call. It also allows to define fields and widgets in the dialog. + * + * Acceptation is done by clicking on 'Add' button or hitting 'ENTER' key, + * refusal by clicking on 'Cancel' button or hitting 'ESCAPE' key. + * + * @class + * @extends IPA.form_dialog + */ +IPA.custom_command_multivalued_dialog = function(spec) { + spec = spec || {}; + + /** + * Name of confirmation button, by default set to 'Add'. + * @param {String} ok_label + */ + spec.ok_label = spec.ok_label || '@i18n:buttons.add'; + + var that = IPA.form_dialog(spec); + + that.close = function() { + that.dialog_close(); + }; + + that.on_confirm = function() { + if (that.on_ok) that.on_ok(); + }; + + return that; +}; + /** * From ad8d4fce58bf18883b0e4dd741cbbe320ee3c627 Mon Sep 17 00:00:00 2001 From: Pavel Vomacka <pvoma...@redhat.com> Date: Mon, 16 Jan 2017 14:16:47 +0100 Subject: [PATCH 4/4] WebUI: Add certmap module Add facets for certmaprule and certmapconfigure entities. https://fedorahosted.org/freeipa/ticket/6601 --- install/ui/src/freeipa/app.js | 1 + install/ui/src/freeipa/navigation/menu_spec.js | 16 +- install/ui/src/freeipa/plugins/certmap.js | 381 +++++++++++++++++++++++++ install/ui/src/freeipa/stageuser.js | 12 + install/ui/src/freeipa/user.js | 12 + ipaserver/plugins/internal.py | 12 + 6 files changed, 433 insertions(+), 1 deletion(-) create mode 100644 install/ui/src/freeipa/plugins/certmap.js diff --git a/install/ui/src/freeipa/app.js b/install/ui/src/freeipa/app.js index 4eb045d..d262a64 100644 --- a/install/ui/src/freeipa/app.js +++ b/install/ui/src/freeipa/app.js @@ -32,6 +32,7 @@ define([ './plugins/ca', './plugins/caacl', './plugins/certprofile', + './plugins/certmap', './dns', './group', './hbac', diff --git a/install/ui/src/freeipa/navigation/menu_spec.js b/install/ui/src/freeipa/navigation/menu_spec.js index 7d121d9..281bf22 100644 --- a/install/ui/src/freeipa/navigation/menu_spec.js +++ b/install/ui/src/freeipa/navigation/menu_spec.js @@ -151,7 +151,21 @@ var nav = {}; ] }, { entity: 'otptoken' }, - { entity: 'radiusproxy' } + { entity: 'radiusproxy' }, + { + entity: 'certmaprule', + facet: 'search', + children: [ + { + entity: 'certmaprule', + facet: 'search' + }, + { + entity: 'certmapconfig', + facet: 'details' + } + ] + } ] }, { diff --git a/install/ui/src/freeipa/plugins/certmap.js b/install/ui/src/freeipa/plugins/certmap.js new file mode 100644 index 0000000..ddbc5a7 --- /dev/null +++ b/install/ui/src/freeipa/plugins/certmap.js @@ -0,0 +1,381 @@ +// +// Copyright (C) 2017 FreeIPA Contributors see COPYING for license +// + + +define([ + 'dojo/_base/lang', + 'dojo/_base/declare', + 'dojo/Evented', + 'dojo/on', + '../navigation', + '../field', + '../ipa', + '../phases', + '../reg', + '../widget', + '../text', + '../util', + // plain imports + '../search', + '../entity'], + function(lang, declare, Evented, on, navigation, mod_field, IPA, + phases, reg, widget_mod, text, util) { +/** + * Certificate map module + * @class + */ +var certmap = IPA.certmap = { + + search_facet_group: { + facets: { + certmaprule_search: 'certmaprule_search', + certmapconfig: 'certmapconfig_details' + } + } +}; + +var make_certmaprule_spec = function() { +return { + name: 'certmaprule', + facets: [ + { + $type: 'search', + always_request_members: true, + details_facet: 'details', + facet_groups: [certmap.search_facet_group], + facet_group: 'search', + row_enabled_attribute: 'ipaenabledflag', + columns: [ + 'cn', + { + name: 'ipaenabledflag', + label: '@i18n:status.label', + formatter: 'boolean_status' + }, + 'description' + ], + actions: [ + 'batch_disable', + 'batch_enable' + ], + control_buttons: [ + { + name: 'disable', + label: '@i18n:buttons.disable', + icon: 'fa-minus' + }, + { + name: 'enable', + label: '@i18n:buttons.enable', + icon: 'fa-check' + } + ] + }, + { + $type: 'details', + disable_facet_tabs: true, + facet_groups: [certmap.search_facet_group], + facet_group: 'search', + actions: [ + 'enable', + 'disable', + 'delete' + ], + header_actions: ['enable', 'disable', 'delete'], + state: { + evaluators: [ + { + $factory: IPA.enable_state_evaluator, + field: 'ipaenabledflag' + } + ] + }, + sections: [ + { + name: 'details', + fields: [ + 'cn', + { + $type: 'textarea', + name: 'description' + }, + { + name: 'ipacertmapmaprule', + tooltip: { + title: '@mc-opt:certmaprule_add:ipacertmapmaprule:doc' + } + }, + { + name: 'ipacertmapmatchrule', + tooltip: { + title: '@mc-opt:certmaprule_add:ipacertmapmatchrule:doc' + } + }, + { + $type: 'multivalued', + name: 'associateddomain', + tooltip: { + title: '@mc-opt:certmaprule_add:associateddomain:doc' + } + }, + { + name: 'ipacertmappriority', + tooltip: { + title: '@mc-opt:certmaprule_add:ipacertmappriority:doc' + } + } + ] + } + ] + } + ], + adder_dialog: { + fields: [ + 'cn', + { + name: 'ipacertmapmaprule', + tooltip: { + title: '@mc-opt:certmaprule_add:ipacertmapmaprule:doc' + } + }, + { + name: 'ipacertmapmatchrule', + tooltip: { + title: '@mc-opt:certmaprule_add:ipacertmapmatchrule:doc' + } + }, + { + $type: 'multivalued', + name: 'associateddomain', + tooltip: { + title: '@mc-opt:certmaprule_add:associateddomain:doc' + } + }, + { + name: 'ipacertmappriority', + tooltip: { + title: '@mc-opt:certmaprule_add:ipacertmappriority:doc' + } + }, + { + $type: 'textarea', + name: 'description' + } + ] + } +};}; + + +var make_certmapconfig_spec = function() { +return { + name: 'certmapconfig', + defines_key: false, + facets: [ + { + $type: 'details', + facet_groups: [certmap.search_facet_group], + facet_group: 'search', + sections: [ + { + name: 'details', + fields: [ + { + $type: 'checkbox', + name: 'ipacertmappromptusername' + } + ] + } + ] + } + ] +};}; + + +/** + * Multivalued widget which is used for working with user's certmap. + * + * @class + * @extends IPA.custom_command_multivalued_widget + */ +certmap.certmap_multivalued_widget = function (spec) { + + spec = spec || {}; + spec.adder_dialog_spec = spec.adder_dialog_spec || { + name: 'custom-add-dialog', + title: '@i18n:objects.certmap.adder_title', + policies: [ + { + $factory: IPA.multiple_choice_section_policy, + widget: 'type' + } + ], + fields: [ + { + $type: 'multivalued', + name: 'ipacertmapdata', + label: '@i18n:objects.certmap.data_label', + widget: 'type.ipacertmapdata' + }, + { + $type: 'multivalued', + name: 'certificate', + label: '@i18n:objects.certmap.certificate', + widget: 'type.certificate', + child_spec: { + $type: 'textarea' + } + }, + { + name: 'issuer', + label: '@i18n:objects.certmap.issuer', + widget: 'type.issuer' + }, + { + name: 'subject', + label: '@i18n:objects.certmap.subject', + widget: 'type.subject' + } + ], + widgets: [ + { + $type: 'multiple_choice_section', + name: 'type', + choices: [ + { + name: 'data', + label: '@i18n:objects.certmap.data_label', + fields: ['ipacertmapdata', 'certificate'], + required: [], + enabled: true + }, + { + name: 'issuer_subj', + label: '@i18n:objects.certmap.issuer_subject', + fields: ['issuer', 'subject'], + required: ['issuer', 'subject'] + } + ], + widgets: [ + { + $type: 'multivalued', + name: 'ipacertmapdata' + }, + { + $type: 'multivalued', + name: 'certificate', + child_spec: { + $type: 'textarea' + }, + tooltip: { + title: '@mc-opt:user_add_certmapdata:certificate:doc' + } + }, + { + name: 'issuer', + tooltip: { + title: '@mc-opt:user_add_certmapdata:issuer:doc' + } + }, + { + name: 'subject', + tooltip: { + title: '@mc-opt:user_add_certmapdata:subject:doc' + } + } + ] + } + ] + }; + + var that = IPA.custom_command_multivalued_widget(spec); + + that.create_remove_dialog_title = function(row) { + return text.get('@i18n:objects.certmap.deleter_title'); + }; + + that.create_remove_dialog_message = function(row) { + var message = text.get('@i18n:objects.certmap.deleter_content'); + message = message.replace('${data}', row.widget.new_value); + + return message; + }; + + /** + * Compose options for add command. + * @return {Object} options + */ + that.create_add_options = function() { + var options = {}; + var widgets = that.adder_dialog.widgets.get_widgets(); + var widget = widgets[0]; + var inner_widgets = widget.widgets.get_widgets(); + + for (var i = 0, l = inner_widgets.length; i<l; i++) { + var w = inner_widgets[i]; + + if (w.enabled) { + var field = that.adder_dialog.fields.get_field(w.name); + var value = field.save(); + + if (field.name === 'issuer' || field.name === 'subject') { + value = value[0]; + } + + if (!util.is_empty(value)) options[field.name] = value; + } + } + + return options; + }; + + + /** + * Compose options for remove command. + * + * @param {Object} row + * @return {Object} options + */ + that.create_remove_options = function(row) { + var options = {}; + var data = row.widget.new_value; + + options['ipacertmapdata'] = data; + + return options; + }; + + return that; +}; + +/** + * Certificat Mapping Rules entity specification object + * @member certmap + */ +certmap.certmaprule_spec = make_certmaprule_spec(); + +/** + * Certificate Mapping Configuration entity specification object + * @member certmap + */ +certmap.certmapconfig_spec = make_certmapconfig_spec(); + + +/** + * Register entity + * @member cermap + */ +certmap.register = function() { + var e = reg.entity; + var w = reg.widget; + + e.register({type: 'certmaprule', spec: certmap.certmaprule_spec}); + e.register({type: 'certmapconfig', spec: certmap.certmapconfig_spec}); + w.register('certmap_multivalued', + certmap.certmap_multivalued_widget); +}; + +phases.on('registration', certmap.register); + +return certmap; +}); diff --git a/install/ui/src/freeipa/stageuser.js b/install/ui/src/freeipa/stageuser.js index bf24491..f456189 100644 --- a/install/ui/src/freeipa/stageuser.js +++ b/install/ui/src/freeipa/stageuser.js @@ -147,6 +147,18 @@ return { label: '@i18n:objects.sshkeystore.keys' }, { + $type: 'certmap_multivalued', + name: 'ipacertmapdata', + item_name: 'certmapdata', + child_spec: { + $type: 'non_editable_row', + data_name: 'certmap' + }, + tooltip: { + title: '@mc:stageuser_add_certmapdata.doc' + } + }, + { $type: 'checkboxes', name: 'ipauserauthtype', flags: ['w_if_no_aci'], diff --git a/install/ui/src/freeipa/user.js b/install/ui/src/freeipa/user.js index a36b65a..c3a9181 100644 --- a/install/ui/src/freeipa/user.js +++ b/install/ui/src/freeipa/user.js @@ -218,6 +218,18 @@ return { label: '@i18n:objects.cert.certificates' }, { + $type: 'certmap_multivalued', + name: 'ipacertmapdata', + item_name: 'certmapdata', + child_spec: { + $type: 'non_editable_row', + data_name: 'certmap' + }, + tooltip: { + title: '@mc:user_add_certmapdata.doc' + } + }, + { $type: 'checkboxes', name: 'ipauserauthtype', flags: ['w_if_no_aci'], diff --git a/ipaserver/plugins/internal.py b/ipaserver/plugins/internal.py index e82e5fc..a621c8c 100644 --- a/ipaserver/plugins/internal.py +++ b/ipaserver/plugins/internal.py @@ -464,6 +464,18 @@ class i18n_messages(Command): "view_certificate": _("Certificate for ${entity} ${primary_key}"), "view_certificate_btn": _("View Certificate"), }, + "certmap": { + "adder_title": _("Add Certificate Mapping Data"), + "data_label": _("Certificate mapping data"), + "certificate": _("Certificate"), + "conf_str": _("Configuration string"), + "deleter_content": _("Do you want to remove certificate mapping data ${data}?"), + "deleter_title": _("Remove Certificate Mapping Data"), + "issuer": _("Issuer"), + "issuer_subject": _("Issuer and subject"), + "subject": _("Subject"), + "version": _("Version"), + }, "config": { "group": _("Group Options"), "search": _("Search Options"),
-- Manage your subscription for the Freeipa-devel mailing list: https://www.redhat.com/mailman/listinfo/freeipa-devel Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code