Modifying hosts to work with new concept

https://fedorahosted.org/freeipa/ticket/2040
This commit is contained in:
Petr Vobornik
2011-11-23 13:42:23 +01:00
committed by Endi S. Dewata
parent b55d154375
commit 9b362ce6e1
2 changed files with 195 additions and 102 deletions

View File

@@ -712,9 +712,8 @@ IPA.cert.status_widget = function(spec) {
}); });
}; };
that.load = function(result) { that.update = function() {
that.result = result;
that.pkey = that.get_entity_pkey(that.result); that.pkey = that.get_entity_pkey(that.result);
var entity_certificate = that.get_entity_certificate(that.result); var entity_certificate = that.get_entity_certificate(that.result);
@@ -922,3 +921,18 @@ IPA.cert.status_widget = function(spec) {
return that; return that;
}; };
IPA.cert.status_field = function(spec) {
spec = spec || {};
var that = IPA.field(spec);
that.load = function(result) {
that.widget.result = result;
that.reset();
};
return that;
};

View File

@@ -49,13 +49,13 @@ IPA.host.entity = function(spec) {
name: 'details', name: 'details',
fields: [ fields: [
{ {
factory: IPA.host_dnsrecord_entity_link_widget, type: 'host_dnsrecord_entity_link',
name: 'fqdn', name: 'fqdn',
other_entity: 'dnsrecord' other_entity: 'dnsrecord'
}, },
'krbprincipalname', 'krbprincipalname',
{ {
factory: IPA.textarea_widget, type: 'textarea',
name: 'description' name: 'description'
}, },
'l', 'l',
@@ -65,7 +65,6 @@ IPA.host.entity = function(spec) {
] ]
}, },
{ {
factory: IPA.host_enrollment_section,
name: 'enrollment', name: 'enrollment',
fields: [ fields: [
{ {
@@ -74,7 +73,7 @@ IPA.host.entity = function(spec) {
label: IPA.messages.objects.host.keytab label: IPA.messages.objects.host.keytab
}, },
{ {
factory: IPA.host_password_widget, type: 'host_password',
name: 'has_password', name: 'has_password',
label: IPA.messages.objects.host.password label: IPA.messages.objects.host.password
} }
@@ -84,12 +83,15 @@ IPA.host.entity = function(spec) {
name: 'certificate', name: 'certificate',
fields: [ fields: [
{ {
factory: IPA.host_certificate_status_widget, type: 'host_certificate_status',
name: 'certificate_status', name: 'certificate_status',
label: IPA.messages.objects.host.status label: IPA.messages.objects.host.status
} }
] ]
} }
],
policies: [
IPA.host_enrollment_policy()
] ]
}). }).
association_facet({ association_facet({
@@ -127,27 +129,12 @@ IPA.host.entity = function(spec) {
height: 300, height: 300,
sections: [ sections: [
{ {
factory: IPA.host_fqdn_section, factory: IPA.composite_widget,
name: 'fqdn', name: 'fqdn',
fields: [ fields: [
{ {
factory: IPA.widget, type: 'host_fqdn',
name: 'fqdn', name: 'fqdn',
required: false,
hidden: true
},
{
factory: IPA.text_widget,
name: 'hostname',
label: IPA.messages.objects.service.host,
required: true
},
{
factory: IPA.dnszone_select_widget,
name: 'dnszone',
label: IPA.metadata.objects.dnszone.label_singular,
editable: true,
empty_option: false,
required: true required: true
} }
] ]
@@ -156,12 +143,11 @@ IPA.host.entity = function(spec) {
name: 'other', name: 'other',
fields: [ fields: [
{ {
factory: IPA.text_widget,
name: 'ip_address', name: 'ip_address',
metadata: IPA.get_method_option('host_add', 'ip_address') metadata: IPA.get_method_option('host_add', 'ip_address')
}, },
{ {
factory: IPA.force_host_add_checkbox_widget, type: 'force_host_add_checkbox',
name: 'force', name: 'force',
metadata: IPA.get_method_option('host_add', 'force') metadata: IPA.get_method_option('host_add', 'force')
} }
@@ -188,17 +174,35 @@ IPA.host.details_facet = function(spec) {
return that; return that;
}; };
IPA.host_fqdn_section = function(spec) { IPA.host_fqdn_widget = function(spec) {
spec = spec || {}; spec = spec || {};
var that = IPA.details_section(spec); spec.widgets = [
{
type: 'text',
name: 'hostname',
label: IPA.messages.objects.service.host,
required: true
},
{
type: 'dnszone_select',
name: 'dnszone',
label: IPA.metadata.objects.dnszone.label_singular,
editable: true,
empty_option: false,
required: true,
searchable: true
}
];
var that = IPA.composite_widget(spec);
that.create = function(container) { that.create = function(container) {
that.container = container; that.container = container;
var hostname = that.fields.get_field('hostname'); var hostname = that.widgets.get_widget('hostname');
var dnszone = that.fields.get_field('dnszone'); var dnszone = that.widgets.get_widget('dnszone');
var table = $('<table/>', { var table = $('<table/>', {
'class': 'fqdn' 'class': 'fqdn'
@@ -267,19 +271,71 @@ IPA.host_fqdn_section = function(spec) {
}); });
}; };
that.save = function(record) { return that;
var field = that.fields.get_field('hostname'); };
var hostname = field.save()[0];
field = that.fields.get_field('dnszone'); IPA.host_fqdn_field = function(spec) {
var dnszone = field.save()[0];
spec = spec || {};
var that = IPA.field(spec);
that.validate_required = function() {
var hostname = that.hostname_widget.save();
var dnszone = that.dns_zone_widget.save();
var valid = true;
if(!hostname.length || hostname[0] === '') {
that.hostname_widget.show_error(IPA.messages.widget.validation.required);
that.valid = valid = false;
}
if(!dnszone.length || dnszone[0] === '') {
that.dns_zone_widget.show_error(IPA.messages.widget.validation.required);
that.valid = valid = false;
}
return valid;
};
that.hide_error = function() {
that.hostname_widget.hide_error();
that.dns_zone_widget.hide_error();
};
that.save = function(record) {
if(!record) record = {};
var hostname = that.hostname_widget.save()[0];
var dnszone = that.dns_zone_widget.save()[0];
record.fqdn = hostname && dnszone ? [ hostname+'.'+dnszone ] : []; record.fqdn = hostname && dnszone ? [ hostname+'.'+dnszone ] : [];
return record.fqdn;
};
that.reset = function() {
that.hostname_widget.update([]);
that.dns_zone_widget.update([]);
};
that.widgets_created = function() {
that.widget = that.container.widgets.get_widget(that.widget_name);
that.hostname_widget = that.widget.widgets.get_widget('hostname');
that.dns_zone_widget = that.widget.widgets.get_widget('dnszone');
}; };
return that; return that;
}; };
IPA.field_factories['host_fqdn'] = IPA.host_fqdn_field;
IPA.widget_factories['host_fqdn'] = IPA.host_fqdn_widget;
IPA.host_adder_dialog = function(spec) { IPA.host_adder_dialog = function(spec) {
spec = spec || {}; spec = spec || {};
@@ -386,8 +442,11 @@ IPA.dnszone_select_widget = function(spec) {
return that; return that;
}; };
IPA.host_dnsrecord_entity_link_widget = function(spec){ IPA.field_factories['dnszone_select'] = IPA.field;
var that = IPA.entity_link_widget(spec); IPA.widget_factories['dnszone_select'] = IPA.dnszone_select_widget;
IPA.host_dnsrecord_entity_link_field = function(spec){
var that = IPA.link_field(spec);
that.other_pkeys = function(){ that.other_pkeys = function(){
var pkey = that.entity.get_primary_key()[0]; var pkey = that.entity.get_primary_key()[0];
@@ -397,9 +456,13 @@ IPA.host_dnsrecord_entity_link_widget = function(spec){
pkeys[0] = pkey.substring(first_dot+1); pkeys[0] = pkey.substring(first_dot+1);
return pkeys; return pkeys;
}; };
return that; return that;
}; };
IPA.field_factories['host_dnsrecord_entity_link'] = IPA.host_dnsrecord_entity_link_field;
IPA.widget_factories['host_dnsrecord_entity_link'] = IPA.link_widget;
/* Take an LDAP format date in UTC and format it */ /* Take an LDAP format date in UTC and format it */
IPA.utc_date_column_format = function(value){ IPA.utc_date_column_format = function(value){
if (!value) { if (!value) {
@@ -435,26 +498,18 @@ IPA.force_host_add_checkbox_widget = function(spec) {
return IPA.checkbox_widget(spec); return IPA.checkbox_widget(spec);
}; };
IPA.host_enrollment_section = function(spec) { IPA.widget_factories['force_host_add_checkbox'] = IPA.force_host_add_checkbox_widget;
IPA.field_factories['force_host_add_checkbox'] = IPA.checkbox_field;
spec = spec || {}; IPA.host_enrollment_policy = function(spec) {
var that = IPA.details_table_section(spec); var that = IPA.facet_policy();
that.create = function(container) { that.init = function() {
that.table_section_create(container);
var keytab_field = that.fields.get_field('has_keytab'); var keytab_field = that.container.fields.get_field('has_keytab');
var password_field = that.fields.get_field('has_password'); var password_field = that.container.fields.get_field('has_password');
/**
* The set_password() in the password field is being customized to
* update the keytab field.
*
* The customization needs to be done here because the section
* doesn't create the fields. The IPA.entity_builder adds the fields
* after creating the section. This needs to be improved.
*/
var super_set_password = password_field.set_password; var super_set_password = password_field.set_password;
password_field.set_password = function(password, on_success, on_error) { password_field.set_password = function(password, on_success, on_error) {
super_set_password.call( super_set_password.call(
@@ -579,10 +634,8 @@ IPA.host_keytab_widget = function(spec) {
command.execute(); command.execute();
}; };
that.load = function(result) { that.update = function(values) {
that.result = result; set_status(values[0] ? 'present' : 'missing');
var value = result[that.name];
set_status(value ? 'present' : 'missing');
}; };
that.clear = function() { that.clear = function() {
@@ -604,6 +657,8 @@ IPA.host_password_widget = function(spec) {
var that = IPA.input_widget(spec); var that = IPA.input_widget(spec);
that.password_change_request = IPA.observer();
that.create = function(container) { that.create = function(container) {
that.widget_create(container); that.widget_create(container);
@@ -660,22 +715,28 @@ IPA.host_password_widget = function(spec) {
label = IPA.messages.objects.host.password_reset_button; label = IPA.messages.objects.host.password_reset_button;
} }
var dialog = IPA.dialog({
title: title,
width: 400
});
var password1 = dialog.add_field(IPA.text_widget({ var dialog = that.dialog = IPA.dialog({
title: title,
width: 400,
sections: [
{
fields: [
{
name: 'password1', name: 'password1',
label: IPA.messages.password.new_password, label: IPA.messages.password.new_password,
type: 'password' type: 'password'
})); },
{
var password2 = dialog.add_field(IPA.text_widget({
name: 'password2', name: 'password2',
label: IPA.messages.password.verify_password, label: IPA.messages.password.verify_password,
type: 'password' type: 'password'
})); }
]
}
]
});
dialog.create_button({ dialog.create_button({
name: 'set_password', name: 'set_password',
@@ -693,16 +754,8 @@ IPA.host_password_widget = function(spec) {
return; return;
} }
that.set_password( that.password_change_request.notify([new_password], that);
new_password,
function(data, text_status, xhr) {
that.load(data.result.result);
dialog.close();
},
function(xhr, text_status, error_thrown) {
dialog.close();
}
);
dialog.close(); dialog.close();
} }
}); });
@@ -718,29 +771,8 @@ IPA.host_password_widget = function(spec) {
dialog.open(that.container); dialog.open(that.container);
}; };
that.set_password = function(password, on_success, on_error) { that.update = function(values) {
var pkey = that.entity.get_primary_key(); set_status(values[0] ? 'present' : 'missing');
var command = IPA.command({
entity: that.entity.name,
method: 'mod',
args: pkey,
options: {
all: true,
rights: true,
userpassword: password
},
on_success: on_success,
on_error: on_error
});
command.execute();
};
that.load = function(result) {
that.result = result;
var value = result[that.name];
set_status(value ? 'present' : 'missing');
}; };
that.clear = function() { that.clear = function() {
@@ -770,6 +802,50 @@ IPA.host_password_widget = function(spec) {
return that; return that;
}; };
IPA.host_password_field = function (spec) {
spec = spec || {};
var that = IPA.field(spec);
that.widgets_created = function() {
that.field_widgets_created();
that.widget.password_change_request.attach(that.set_password);
that.widget.search = that.search;
};
that.set_password = function(password) {
var pkey = that.entity.get_primary_key();
var command = IPA.command({
entity: that.entity.name,
method: 'mod',
args: pkey,
options: {
all: true,
rights: true,
userpassword: password
},
on_success: function(result) {
that.load(result.result.result);
that.widget.dialog.close();
},
on_error: function() {
that.widget.dialog.close();
}
});
command.execute();
};
return that;
};
IPA.widget_factories['host_password'] = IPA.host_password_widget;
IPA.field_factories['host_password'] = IPA.host_password_field;
IPA.host_certificate_status_widget = function (spec) { IPA.host_certificate_status_widget = function (spec) {
spec = spec || {}; spec = spec || {};
@@ -798,4 +874,7 @@ IPA.host_certificate_status_widget = function (spec) {
return that; return that;
}; };
IPA.widget_factories['host_certificate_status'] = IPA.host_certificate_status_widget;
IPA.field_factories['host_certificate_status'] = IPA.cert.status_field;
IPA.register('host', IPA.host.entity); IPA.register('host', IPA.host.entity);