Auth Indicators WebUI part

Add custom_checkbox_widget on service page. The old  aci.attribute_widget
now inherits from the new base class custom_checkboxes_widget and overrides
the populate method.

https://fedorahosted.org/freeipa/ticket/5872

Reviewed-By: Petr Vobornik <pvoborni@redhat.com>
This commit is contained in:
Pavel Vomacka 2016-06-06 12:11:06 +02:00 committed by Petr Vobornik
parent 1d9425dab7
commit afededacb9
5 changed files with 233 additions and 169 deletions

View File

@ -537,146 +537,24 @@ return {
}
};};
/**
* @class aci.attributes_widget
* @extends IPA.checkboxes_widget
*/
aci.attributes_widget = function(spec) {
spec = spec || {};
spec.layout = spec.layout || 'columns attribute_widget';
spec.sort = spec.sort === undefined ? true : spec.sort;
spec.add_dialog_title = spec.add_dialog_title ||
"@i18n:objects.permission.add_custom_attr";
spec.add_field_label = spec.add_field_label ||
'@i18n:objects.permission.attribute';
var that = IPA.checkboxes_widget(spec);
/**
* Additional options which are not defined in metadata
* @property {string[]}
*/
that.custom_options = spec.custom_options || [];
var that = IPA.custom_checkboxes_widget(spec);
that.object_type = spec.object_type;
that.skip_unmatched = spec.skip_unmatched === undefined ? false : spec.skip_unmatched;
var id = spec.name;
that.populate = function() {
that.create = function(container) {
that.container = container;
that.widget_create(container);
if (!that.object_type || that.object_type === '') return;
that.controls = $('<div/>', {
'class': 'form-inline controls'
});
that.controls.appendTo(container);
that.create_search_filter(that.controls);
that.create_add_control(that.controls);
if (that.undo) {
that.create_undo(that.controls);
}
that.owb_create(container);
that.create_error_link(container);
};
that.create_search_filter = function(container) {
var filter_container = $('<div/>', {
'class': 'search-filter'
});
that.filter = $('<input/>', {
type: 'text',
name: 'filter',
'class': 'form-control',
placeholder: text.get('@i18n:objects.permission.filter')
}).appendTo(filter_container);
that.filter.keyup(function(e) {
that.filter_options();
});
var find_button = IPA.action_button({
name: 'find',
icon: 'fa-search',
click: function() {
that.filter_options();
return false;
}
}).appendTo(filter_container);
filter_container.appendTo(container);
};
that.create_add_control = function(container) {
that.add_button = IPA.button({
label: '@i18n:buttons.add',
click: that.show_add_dialog
});
container.append(' ');
that.add_button.appendTo(container);
};
that.show_add_dialog = function() {
var dialog = IPA.form_dialog({
name: "add_option",
title: "@i18n:objects.permission.add_custom_attr",
fields: [
{
name: 'attr',
label: '@i18n:objects.permission.attribute',
required: true
}
]
});
dialog.on_confirm = function() {
if (!dialog.validate()) return;
var attr = dialog.get_field('attr');
var value = attr.get_value()[0];
that.add_custom_option(value, false, true, true);
dialog.close();
};
dialog.open();
};
that.filter_options = function() {
$("li", that.$node).each(function() {
var item = $(this);
if(item.find('input').val().indexOf(that.filter.val()) === -1) {
item.css('display','none');
} else {
item.css('display','inline');
}
});
};
that.update = function(values) {
that.values = [];
values = values || [];
for (var i=0; i<values.length; i++) {
var value = values[i];
if (!value || value === '') continue;
value = value.toLowerCase();
that.values.push(value);
}
that.populate(that.object_type);
that.append();
that.owb_create(that.container);
that.owb_update(values);
};
that.populate = function(object_type) {
if (!object_type || object_type === '') return;
var metadata = metadata_provider.get('@mo:'+object_type);
var metadata = metadata_provider.get('@mo:'+that.object_type);
if (!metadata) return;
var aciattrs = metadata.aciattrs;
@ -684,41 +562,6 @@ aci.attributes_widget = function(spec) {
that.options = that.prepare_options(aciattrs);
};
that.append = function() {
var unmatched = [];
function add_unmatched(source) {
for (var i=0, l=source.length; i<l; i++) {
if (!that.has_option(source[i])) {
that.add_option(source[i], true /* suppress update */);
}
}
}
add_unmatched(that.custom_options);
if (that.values && !that.skip_unmatched) {
add_unmatched(that.values);
}
};
that.add_custom_option = function(name, to_custom, check, update) {
var value = (name || '').toLowerCase();
if (to_custom) that.custom_options.push(value);
if (check) that.values.push(value);
if (update) that.update(that.values);
};
that.has_option = function(value) {
var o = that.options;
for (var i=0, l=o.length; i<l; i++) {
if (o[i].value === value) return true;
}
return false;
};
return that;
};

View File

@ -108,6 +108,26 @@ return {
}
]
},
{
$type: 'custom_checkboxes',
label: '@i18n:objects.service.auth_indicators',
name: 'krbprincipalauthind',
add_dialog_title: '@i18n:objects.service.custom_auth_ind_title',
add_field_label: '@i18n:objects.service.auth_indicator',
options: [
{
label: '@i18n:authtype.otp',
value: 'otp'
},
{
label: '@i18n:authtype.type_radius',
value: 'radius'
}
],
tooltip: {
title: '@mc-opt:service_add:krbprincipalauthind:doc'
}
},
{
name: 'ipakrbokasdelegate',
$type: 'checkbox',

View File

@ -1980,6 +1980,192 @@ IPA.checkboxes_widget = function (spec) {
return that;
};
/**
* @class IPA.custom_checkboxes_widget
* @extends IPA.checkboxes_widget
*/
IPA.custom_checkboxes_widget = function(spec) {
spec = spec || {};
spec.layout = spec.layout || 'columns attribute_widget';
spec.sort = spec.sort === undefined ? true : spec.sort;
var that = IPA.checkboxes_widget(spec);
that.add_dialog_title = spec.add_dialog_title ||
"@i18n:dialogs.add_custom_value";
that.add_field_label = spec.add_field_label ||
'@i18n:dialogs.custom_value';
/**
* Additional options
* @property {string[]}
*/
that.custom_options = spec.custom_options || [];
that.skip_unmatched = spec.skip_unmatched === undefined ? false : spec.skip_unmatched;
var id = spec.name;
that.create = function(container) {
that.container = container;
that.widget_create(container);
that.controls = $('<div/>', {
'class': 'form-inline controls'
});
that.controls.appendTo(container);
that.create_search_filter(that.controls);
that.create_add_control(that.controls);
if (that.undo) {
that.create_undo(that.controls);
}
that.owb_create(container);
that.create_error_link(container);
};
that.create_search_filter = function(container) {
var filter_container = $('<div/>', {
'class': 'search-filter'
});
that.filter = $('<input/>', {
type: 'text',
name: 'filter',
'class': 'form-control',
placeholder: text.get('@i18n:search.placeholder_filter')
}).appendTo(filter_container);
that.filter.keyup(function(e) {
that.filter_options();
});
var find_button = IPA.action_button({
name: 'find',
icon: 'fa-search',
click: function() {
that.filter_options();
return false;
}
}).appendTo(filter_container);
filter_container.appendTo(container);
};
that.create_add_control = function(container) {
that.add_button = IPA.button({
label: '@i18n:buttons.add',
click: that.show_add_dialog
});
container.append(' ');
that.add_button.appendTo(container);
};
that.show_add_dialog = function() {
var dialog = IPA.form_dialog({
name: "add_option",
title: that.add_dialog_title,
fields: [
{
name: 'custom_value',
label: that.add_field_label,
required: true
}
]
});
dialog.on_confirm = function() {
if (!dialog.validate()) return;
var attr = dialog.get_field('custom_value');
var value = attr.get_value()[0];
that.add_custom_option(value, false, true, true);
dialog.close();
};
dialog.open();
};
that.filter_options = function() {
$("li", that.$node).each(function() {
var item = $(this);
if(item.find('input').val().indexOf(that.filter.val()) === -1) {
item.css('display','none');
} else {
item.css('display','inline');
}
});
};
that.update = function(values) {
that.values = [];
values = values || [];
for (var i=0; i<values.length; i++) {
var value = values[i];
if (!value || value === '') continue;
value = value.toLowerCase();
that.values.push(value);
}
that.populate();
that.append();
that.owb_create(that.container);
that.owb_update(values);
};
/**
* Method which can be overridden by child class for adding own
* autogenerated values. These values should be prepared using
* that.prepare_option() method and stored in that.options.
*/
that.populate = function() {};
that.append = function() {
var unmatched = [];
function add_unmatched(source) {
for (var i=0, l=source.length; i<l; i++) {
if (!that.has_option(source[i])) {
that.add_option(source[i], true /* suppress update */);
}
}
}
add_unmatched(that.custom_options);
if (that.values && !that.skip_unmatched) {
add_unmatched(that.values);
}
};
that.add_custom_option = function(name, to_custom, check, update) {
var value = (name || '').toLowerCase();
if (to_custom) that.custom_options.push(value);
if (check) that.values.push(value);
if (update) that.update(that.values);
};
that.has_option = function(value) {
var o = that.options;
for (var i=0, l=o.length; i<l; i++) {
if (o[i].value === value) return true;
}
return false;
};
return that;
};
/**
* Creates input with properties defined by `spec` and an empty label which
* targets the input.
@ -6436,6 +6622,7 @@ exp.register = function() {
w.register('action_panel', IPA.action_panel);
w.register('activity', IPA.activity_widget);
w.register('attribute_table', IPA.attribute_table_widget);
w.register('custom_checkboxes', IPA.custom_checkboxes_widget);
w.register('button', IPA.button_widget);
w.register('checkbox', IPA.checkbox_widget);
w.register('checkboxes', IPA.checkboxes_widget);

View File

@ -50,9 +50,10 @@
},
"authtype": {
"config_tooltip": "<p>Implicit method (password) will be used if no method is chosen.</p><p><strong>Password + Two-factor:</strong> LDAP and Kerberos allow authentication with either one of the authentication types but Kerberos uses pre-authentication method which requires to use armor ccache.</p><p><strong>RADIUS with another type:</strong> Kerberos always use RADIUS, but LDAP never does. LDAP only recognize the password and two-factor authentication options.</p>",
"otp": "OTP",
"type_otp": "Two factor authentication (password + OTP)",
"type_password": "Password",
"type_radius": "Radius",
"type_radius": "RADIUS",
"type_disabled": "Disable per-user override",
"user_tooltip": "<p>Per-user setting, overwrites the global setting if any option is checked.</p><p><strong>Password + Two-factor:</strong> LDAP and Kerberos allow authentication with either one of the authentication types but Kerberos uses pre-authentication method which requires to use armor ccache.</p><p><strong>RADIUS with another type:</strong> Kerberos always use RADIUS, but LDAP never does. LDAP only recognize the password and two-factor authentication options.</p>",
},
@ -106,11 +107,13 @@
},
"dialogs": {
"add_confirmation": "${entity} successfully added",
"add_custom_value": "Add custom value",
"add_title": "Add ${entity}",
"available": "Available",
"batch_error_message": "Some operations failed.",
"batch_error_title": "Operations Error",
"confirmation": "Confirmation",
"custom_value": "Custom value",
"dirty_message": "This page has unsaved changes. Please save or revert.",
"dirty_title": "Unsaved Changes",
"edit_title": "Edit ${entity}",
@ -469,7 +472,7 @@
"type_totp": "Time-based (TOTP)"
},
"permission": {
"add_custom_attr": "Add custom attribute",
"add_custom_attr": "Add Custom Attribute",
"attribute": "Attribute",
"filter": "Filter",
"identity": "Permission settings",
@ -519,7 +522,10 @@
"user": "User"
},
"service": {
"auth_indicators": "Authentication indicators",
"auth_indicator": "Authentication indicator",
"certificate": "Service Certificate",
"custom_auth_ind_title": "Add Custom Authentication Indicator",
"delete_key_unprovision": "Delete Key, Unprovision",
"details": "Service Settings",
"host": "Host Name",
@ -660,6 +666,7 @@
"enabled": "${count} item(s) enabled",
"partial_delete": "Some entries were not deleted",
"placeholder": "Search",
"placeholder_filter": "Filter",
"quick_links": "Quick Links",
"select_all": "Select All",
"truncated": "Query returned more results than the configured size limit. Displaying the first ${counter} results.",

View File

@ -185,9 +185,10 @@ class i18n_messages(Command):
},
"authtype": {
"config_tooltip": _("<p>Implicit method (password) will be used if no method is chosen.</p><p><strong>Password + Two-factor:</strong> LDAP and Kerberos allow authentication with either one of the authentication types but Kerberos uses pre-authentication method which requires to use armor ccache.</p><p><strong>RADIUS with another type:</strong> Kerberos always use RADIUS, but LDAP never does. LDAP only recognize the password and two-factor authentication options.</p>"),
"otp": _("OTP"),
"type_otp": _("Two factor authentication (password + OTP)"),
"type_password": _("Password"),
"type_radius": _("Radius"),
"type_radius": _("RADIUS"),
"type_disabled": _("Disable per-user override"),
"user_tooltip": _("<p>Per-user setting, overwrites the global setting if any option is checked.</p><p><strong>Password + Two-factor:</strong> LDAP and Kerberos allow authentication with either one of the authentication types but Kerberos uses pre-authentication method which requires to use armor ccache.</p><p><strong>RADIUS with another type:</strong> Kerberos always use RADIUS, but LDAP never does. LDAP only recognize the password and two-factor authentication options.</p>"),
},
@ -242,11 +243,13 @@ class i18n_messages(Command):
},
"dialogs": {
"add_confirmation": _("${entity} successfully added"),
"add_custom_value": _("Add custom value"),
"add_title": _("Add ${entity}"),
"available": _("Available"),
"batch_error_message": _("Some operations failed."),
"batch_error_title": _("Operations Error"),
"confirmation": _("Confirmation"),
"custom_value": _("Custom value"),
"dirty_message": _("This page has unsaved changes. Please save or revert."),
"dirty_title": _("Unsaved Changes"),
"edit_title": _("Edit ${entity}"),
@ -607,7 +610,7 @@ class i18n_messages(Command):
"type_totp": _("Time-based (TOTP)"),
},
"permission": {
"add_custom_attr": _("Add custom attribute"),
"add_custom_attr": _("Add Custom Attribute"),
"attribute": _("Attribute"),
"filter": _("Filter"),
"identity": _("Permission settings"),
@ -658,7 +661,10 @@ class i18n_messages(Command):
"user": _("User"),
},
"service": {
"auth_indicators": _("Authentication indicators"),
"auth_indicator": _("Authentication indicator"),
"certificate": _("Service Certificate"),
"custom_auth_ind_title": _("Add Custom Authentication Indicator"),
"delete_key_unprovision": _("Delete Key, Unprovision"),
"details": _("Service Settings"),
"host": _("Host Name"),
@ -799,6 +805,7 @@ class i18n_messages(Command):
"enabled": _("${count} item(s) enabled"),
"partial_delete": _("Some entries were not deleted"),
"placeholder": _("Search"),
"placeholder_filter": _("Filter"),
"quick_links": _("Quick Links"),
"select_all": _("Select All"),
"truncated": _("Query returned more results than the configured size limit. Displaying the first ${counter} results."),