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

Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
Reviewed-By: Petr Vobornik <pvoborni@redhat.com>
This commit is contained in:
Pavel Vomacka 2017-01-16 13:59:16 +01:00 committed by Tomas Krizek
parent adf8aabf10
commit 27027bbc9c
No known key found for this signature in database
GPG Key ID: 22A2A94B5E49415A
2 changed files with 52 additions and 26 deletions

View File

@ -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);

View File

@ -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);
}
});
else {
that.add(that.adder_dialog);
}
};
that.adder_dialog.create_button({
name: 'cancel',
label: '@i18n:buttons.cancel',
click: function() {
that.adder_dialog.close();
}
});
that.adder_dialog = IPA.custom_command_multivalued_dialog(spec);
};
/* on button 'Add' on adder dialog click */