From ce39bdc231c2b87c344bfc1a2a76baa815a23e40 Mon Sep 17 00:00:00 2001 From: Endi S. Dewata Date: Tue, 16 Nov 2010 18:10:40 -0600 Subject: [PATCH] Service and Host Provisioning The service and host details pages have been modified to display Kerberos key provisioning status and to provide a way to unprovision. The host enrollment via OTP has not been implemented yet. The ipa_details_field has been modified to remove any old
tags it created in the previous load operation. This is to support other widgets that need to perform load operation without removing
tags. The certificate_status_panel has been converted into a widget. The host entity has been rewritten using the new framework. The unit tests has been updated. --- install/static/add.js | 1 + install/static/certificate.js | 181 +++++++++++------ install/static/details.js | 231 ++++++++++------------ install/static/entity.js | 2 + install/static/host.js | 367 +++++++++++++++++++++++++++++----- install/static/ipa.css | 14 ++ install/static/search.js | 2 + install/static/service.js | 220 +++++++++++++++------ install/static/test/details_tests.js | 71 ++++--- install/static/user.js | 56 +++--- install/static/widget.js | 1 + 11 files changed, 791 insertions(+), 355 deletions(-) diff --git a/install/static/add.js b/install/static/add.js index 6b31a6ede03dc14cebc3db61026d05c9b1aed879..1ebd28886c71d41aed17db7b7eee76693664c1e9 100644 --- a/install/static/add.js +++ b/install/static/add.js @@ -95,6 +95,7 @@ function ipa_add_dialog(spec) { }; that.superior_init = that.superior('init'); + that.add_dialog_init = that.init; return that; } diff --git a/install/static/certificate.js b/install/static/certificate.js index affc58aa4a2680e189f546da97e41dbb17dfe808..265568a0436678217234a0be15e25049c0eced0f 100755 --- a/install/static/certificate.js +++ b/install/static/certificate.js @@ -389,12 +389,13 @@ function certificate_request_dialog(spec) { return that; } -function certificate_status_panel(spec) { - var that = $('
'); +function certificate_status_widget(spec) { + spec = spec || {}; - that.entity_type = spec.entity_type; - that.entity_label = spec.entity_label || that.entity_type; + var that = ipa_widget(spec); + + that.entity_label = spec.entity_label || that.entity_name; that.result = spec.result; @@ -403,17 +404,16 @@ function certificate_status_panel(spec) { that.get_entity_principal = spec.get_entity_principal; that.get_entity_certificate = spec.get_entity_certificate; - var li1, li2, li3; + that.create = function(container) { - function init() { - var pkey = that.get_entity_pkey(that.result); + that.widget_create(container); - var table = $('').appendTo(that); + var table = $('
').appendTo(container); var tr = $('').appendTo(table); var td = $('').appendTo(table); + + td = $('').appendTo(table); + + td = $('').appendTo(table); + that.revocation_reason = $('span[name=revocation_reason]', that.container); - td = $('').appendTo(table); - - td = $('
').appendTo(tr); - li1 = $('
  • ', { + $('
  • ', { 'class': 'certificate-status-valid' }).appendTo(td); @@ -421,88 +421,141 @@ function certificate_status_panel(spec) { td.append('Valid Certificate Present:'); td = $('
  • ').appendTo(tr); - ipa_button({ - 'id': 'get_button', + + $('', { + 'type': 'button', + 'name': 'get', + 'value': 'Get' + }).appendTo(td); + + $('', { + 'type': 'button', + 'name': 'revoke', + 'value': 'Revoke' + }).appendTo(td); + + $('', { + 'type': 'button', + 'name': 'view', + 'value': 'View' + }).appendTo(td); + + tr = $('
    ').appendTo(tr); + $('
  • ', { + 'class': 'certificate-status-revoked' + }).appendTo(td); + + td = $('
  • ').appendTo(tr); + td.append('Certificate Revoked:'); + + td = $('').appendTo(tr); + td.append($('', { + 'name': 'revocation_reason' + })); + td.append(' '); + + $('', { + 'type': 'button', + 'name': 'restore', + 'value': 'Restore' + }).appendTo(td); + + tr = $('
    ').appendTo(tr); + $('
  • ', { + 'class': 'certificate-status-missing' + }).appendTo(td); + + td = $('
  • ').appendTo(tr); + td.append('No Valid Certificate:'); + + td = $('').appendTo(tr); + $('', { + 'type': 'button', + 'name': 'create', + 'value': 'New Certificate' + }).appendTo(td); + }; + + that.setup = function(container) { + + that.container = container; + + that.valid = $('li.certificate-status-valid', that.container); + that.revoked = $('li.certificate-status-revoked', that.container); + that.missing = $('li.certificate-status-missing', that.container); + + var button = $('input[name=get]', that.container); + that.get_button = ipa_button({ 'label': 'Get', 'click': function() { - ipa_cmd(that.entity_type+'_show', [pkey], {}, + ipa_cmd(that.entity_name+'_show', [that.pkey], {}, function(data, text_status, xhr) { get_certificate(data.result.result); } ); } - }).appendTo(td); + }); + button.replaceWith(that.get_button); - ipa_button({ - 'id': 'revoke_button', + button = $('input[name=revoke]', that.container); + that.revoke_button = ipa_button({ 'label': 'Revoke', 'click': function() { - ipa_cmd(that.entity_type+'_show', [pkey], {}, + ipa_cmd(that.entity_name+'_show', [that.pkey], {}, function(data, text_status, xhr) { revoke_certificate(data.result.result); } ); } - }).appendTo(td); + }); + button.replaceWith(that.revoke_button); - ipa_button({ - 'id': 'view_button', + button = $('input[name=view]', that.container); + that.view_button = ipa_button({ 'label': 'View', 'click': function() { - ipa_cmd(that.entity_type+'_show', [pkey], {}, + ipa_cmd(that.entity_name+'_show', [that.pkey], {}, function(data, text_status, xhr) { view_certificate(data.result.result); } ); } - }).appendTo(td); + }); + button.replaceWith(that.view_button); - tr = $('
    ').appendTo(tr); - li2 = $('
  • ', { - 'class': 'certificate-status-revoked' - }).appendTo(td); - - td = $('
  • ').appendTo(tr); - td.append('Certificate Revoked:'); - - td = $('').appendTo(tr); - td.append($('', { - 'id': 'revocation_reason' - })); - td.append(' '); - - ipa_button({ - 'id': 'restore_button', + button = $('input[name=restore]', that.container); + that.restore_button = ipa_button({ 'label': 'Restore', 'click': function() { - ipa_cmd(that.entity_type+'_show', [pkey], {}, + ipa_cmd(that.entity_name+'_show', [that.pkey], {}, function(data, text_status, xhr) { restore_certificate(data.result.result); } ); } - }).appendTo(td); + }); + button.replaceWith(that.restore_button); - tr = $('
    ').appendTo(tr); - li3 = $('
  • ', { - 'class': 'certificate-status-missing' - }).appendTo(td); - - td = $('
  • ').appendTo(tr); - td.append('No Valid Certificate:'); - - td = $('').appendTo(tr); - ipa_button({ - 'id': 'create_button', + button = $('input[name=create]', that.container); + that.create_button = ipa_button({ 'label': 'New Certificate', 'click': function() { request_certificate(that.result); } - }).appendTo(td); + }); + button.replaceWith(that.create_button); + }; + + that.load = function(container, result) { + + that.result = result; + that.pkey = that.get_entity_pkey(that.result); var entity_certificate = that.get_entity_certificate(that.result); if (entity_certificate) { @@ -510,18 +563,18 @@ function certificate_status_panel(spec) { } else { set_status(CERTIFICATE_STATUS_MISSING); } - } + }; function set_status(status, revocation_reason) { - li1.toggleClass('certificate-status-active', status == CERTIFICATE_STATUS_VALID); - li2.toggleClass('certificate-status-active', status == CERTIFICATE_STATUS_REVOKED); - li3.toggleClass('certificate-status-active', status == CERTIFICATE_STATUS_MISSING); + that.valid.toggleClass('certificate-status-active', status == CERTIFICATE_STATUS_VALID); + that.revoked.toggleClass('certificate-status-active', status == CERTIFICATE_STATUS_REVOKED); + that.missing.toggleClass('certificate-status-active', status == CERTIFICATE_STATUS_MISSING); - $('#get_button', that).css('visibility', status == CERTIFICATE_STATUS_VALID ? 'visible' : 'hidden'); - $('#revoke_button', that).css('visibility', status == CERTIFICATE_STATUS_VALID ? 'visible' : 'hidden'); - $('#view_button', that).css('visibility', status == CERTIFICATE_STATUS_VALID ? 'visible' : 'hidden'); - $('#revocation_reason', that).html(revocation_reason == undefined ? '' : CRL_REASON[revocation_reason]); - $('#restore_button', that).css('visibility', revocation_reason == 6 ? 'visible' : 'hidden'); + that.get_button.css('visibility', status == CERTIFICATE_STATUS_VALID ? 'visible' : 'hidden'); + that.revoke_button.css('visibility', status == CERTIFICATE_STATUS_VALID ? 'visible' : 'hidden'); + that.view_button.css('visibility', status == CERTIFICATE_STATUS_VALID ? 'visible' : 'hidden'); + that.revocation_reason.html(revocation_reason == undefined ? '' : CRL_REASON[revocation_reason]); + that.restore_button.css('visibility', revocation_reason == 6 ? 'visible' : 'hidden'); } function check_status(serial_number) { @@ -668,7 +721,5 @@ function certificate_status_panel(spec) { dialog.open(); } - init(); - return that; } diff --git a/install/static/details.js b/install/static/details.js index ee61f0cfeba5e58fd9d601a2b1cf38bad7ca640b..f7afcece9e49f28069de141bb1a706f10c423e91 100644 --- a/install/static/details.js +++ b/install/static/details.js @@ -39,38 +39,20 @@ function ipa_details_field(spec) { var that = ipa_widget(spec); - that.create = spec.create || create; that.load = spec.load || load; that.save = spec.save || save; - function create(container) { - - var title = that.name; - var label = ''; - - var param_info = ipa_get_param_info(that.entity_name, that.name); - if (param_info) - label = param_info['label']; - - if (!label) - label = that.label; - - $('
    ', { - id: that.name, - title: title, - html: label + ':' - }).appendTo(container); - } - function load(container, result) { + that.values = result[that.name]; + + /* remove all
    tags i.e. all attribute values */ + $('dd', that.container).remove(); + var multivalue = false; var hint_span = null; var dd; - var dt = $('dt[title='+that.name+']', container); - if (!dt.length) return; - var param_info = ipa_get_param_info(that.entity_name, that.name); if (param_info) { if (param_info['multivalue'] || param_info['class'] == 'List') @@ -83,44 +65,39 @@ function ipa_details_field(spec) { } } - var value = result[that.name]; var rights = 'rsc'; + if (result.attributelevelrights){ rights = result.attributelevelrights[this.name] || rights ; } - if (value) { - dd = ipa_create_first_dd( - that.name,ipa_create_input( - that.entity_name, that.name, value[0],hint_span,rights) - ); - dt.after(dd); - var last_dd = dd; - for (var i = 1; i < value.length; ++i) { - dd = ipa_create_other_dd( - that.name, ipa_create_input(that.entity_name, that.name, - value[i],hint_span,rights) - ); - last_dd.after(dd); - last_dd = dd; + + if (that.values) { + dd = ipa_create_first_dd(that.name); + dd.append(ipa_details_field_create_input.call(that, that.values[0], hint_span, rights, 0)); + dd.appendTo(that.container); + + for (var i = 1; i < that.values.length; ++i) { + dd = ipa_create_other_dd(that.name); + dd.append(ipa_details_field_create_input.call(that, that.values[i], hint_span, rights, i)); + dd.appendTo(that.container); } + if (multivalue && IPA.is_field_writable(rights) ) { - dd = ipa_create_other_dd( - that.name, _ipa_a_add_template.replace('A', that.name) - ); - last_dd.after(dd); + dd = ipa_create_other_dd(that.name); + dd.append(ipa_details_field_create_add_link.call(that, that.name, rights, that.values.length)); + dd.appendTo(that.container); } + } else { if (multivalue && IPA.is_field_writable(rights)) { - dd = ipa_create_first_dd( - that.name, _ipa_a_add_template.replace('A', that.name) - ); - dt.after(dd); + dd = ipa_create_first_dd(that.name); + dd.append(ipa_details_field_create_add_link.call(that, that.name, rights, 0)); + dd.appendTo(that.container); + } else { - dd = ipa_create_first_dd( - that.name, ipa_create_input( - that.entity_name, that.name,'',hint_span,rights) - ); - dt.after(dd); + dd = ipa_create_first_dd(that.name); + dd.append(ipa_details_field_create_input.call(that, '', hint_span, rights, 0)); + dd.appendTo(that.container); } } } @@ -128,8 +105,8 @@ function ipa_details_field(spec) { function save(container) { var values = []; - var dd = $('dd[title='+that.name+']', container); - dd.each(function () { + $('dd', that.container).each(function () { + var input = $('input', $(this)); if (!input.length) return; @@ -298,6 +275,30 @@ function ipa_details_section(spec){ return that; } +/** + * This class creates a details section formatted as a list of + * attributes names and values. The list is defined using
    tag. + * The attribute name is defined inside a
    tag. The attribute + * value is defined using a
    tag inside a tag. If the + * attribute has multiple values the content inside will + * be duplicated to display each value. + * + * Example: + *
    + * + *
    First Name:
    + * + *
    + *
    + * + *
    Telephone Number:
    + * + *
    + *
    + *
    + * + *
    + */ function ipa_details_list_section(spec){ spec = spec || {}; @@ -319,34 +320,20 @@ function ipa_details_list_section(spec){ for (var i = 0; i < fields.length; ++i) { var field = fields[i]; + var label = field.label; + + var param_info = ipa_get_param_info(that.entity_name, field.name); + if (param_info && param_info['label']) label = param_info['label']; + + $('
    ', { + html: label + ':' + }).appendTo(dl); + var span = $('', { 'name': field.name }).appendTo(dl); field.create(span); } }; - /* populate definition lists with the class 'entryattrs' with entry attributes - * - * The list has to be specially crafted for this function to work properly: - *
    tags should have the 'title' attribute set to an LDAP attribute name - * OR to a javascript function name prefixed with 'call_', which will be given - * the
    object and entry_attrs as arguments. - * Example: - *
    - *
    First Name:
    - *
    Some Attribute:
    - *
    - * - * arguments: - * result - 'result' field as returned by ipa *-show commnads - * (basically an associative array with attr:value pairs) */ - that.load = function(result) { - /* remove all
    tags i.e. all attribute values */ - $('dd', that.container).remove(); - - /* go through all
    tags and pair them with newly created
    s */ - that.section_load(result); - }; - // Deprecated: Used for backward compatibility only. function input(spec){ that.create_field(spec); @@ -415,6 +402,8 @@ function ipa_details_facet(spec) { } }; + that.details_facet_init = that.init; + return that; } @@ -621,8 +610,6 @@ function ipa_details_update(container, pkey, on_win, on_fail) /* HTML templates for ipa_details_display() */ -var _ipa_a_add_template = - 'Add'; var _ipa_span_doc_template = 'Hint: D'; var _ipa_span_hint_template = 'Hint: D'; @@ -641,10 +628,12 @@ function ipa_details_display(result) function ipa_create_first_dd(field_name, content){ - return $('
    ', { + var dd = $('
    ', { 'class': 'first', 'title': field_name - }).append(content); + }); + if (content) dd.append(content); + return dd; } function ipa_create_other_dd(field_name, content){ @@ -678,13 +667,15 @@ var _ipa_param_type_2_handler_map = { * arguments: * attr - LDAP attribute name * value - the attributes value */ -function ipa_create_input(entity_name, attr, value,hint,rights) +function ipa_details_field_create_input(value,hint,rights, index) { + var that = this; + var input = $("