Merged IPA.cmd() into IPA.command().

The IPA.cmd() has been merged into IPA.command(). All invocations
and test cases have been converted.

Ticket #988
This commit is contained in:
Endi S. Dewata 2011-04-12 02:13:30 -05:00 committed by Adam Young
parent 9cac1d88fc
commit 805b94f22d
18 changed files with 572 additions and 429 deletions

View File

@ -97,7 +97,8 @@ IPA.add_dialog = function (spec) {
var pkey_name = IPA.metadata.objects[that.entity_name].primary_key; var pkey_name = IPA.metadata.objects[that.entity_name].primary_key;
var command = IPA.command({ var command = IPA.command({
method: that.entity_name+'_add', entity: that.entity_name,
method: 'add',
on_success: on_success, on_success: on_success,
on_error: on_error on_error: on_error
}); });

View File

@ -75,7 +75,8 @@ IPA.serial_associator = function(spec) {
options[that.entity_name] = that.pkey; options[that.entity_name] = that.pkey;
var command = IPA.command({ var command = IPA.command({
method: that.other_entity+'_'+that.method, entity: that.other_entity,
method: that.method,
args: args, args: args,
options: options, options: options,
on_success: that.execute, on_success: that.execute,
@ -122,7 +123,8 @@ IPA.bulk_associator = function(spec) {
options[that.other_entity] = value; options[that.other_entity] = value;
var command = IPA.command({ var command = IPA.command({
method: that.entity_name+'_'+that.method, entity: that.entity_name,
method: that.method,
args: args, args: args,
options: options, options: options,
on_success: that.on_success, on_success: that.on_success,
@ -206,7 +208,13 @@ IPA.association_adder_dialog = function (spec) {
} }
} }
IPA.cmd('find', [that.get_filter()], options, on_success, null, that.other_entity); IPA.command({
entity: that.other_entity,
method: 'find',
args: [that.get_filter()],
options: options,
on_success: on_success
}).execute();
}; };
that.association_adder_dialog_init = that.init; that.association_adder_dialog_init = that.init;
@ -474,11 +482,12 @@ IPA.association_table_widget = function (spec) {
var value = that.values[i]; var value = that.values[i];
var command = IPA.command({ var command = IPA.command({
'method': that.other_entity+'_show', entity: that.other_entity,
'args': [value], method: 'show',
'options': { args: [value],
'all': true, options: {
'rights': true all: true,
rights: true
} }
}); });
@ -569,10 +578,11 @@ IPA.association_table_widget = function (spec) {
var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || '';
var command = IPA.command({ var command = IPA.command({
'method': that.entity_name+'_'+that.add_method, entity: that.entity_name,
'args': [pkey], method: that.add_method,
'on_success': on_success, args: [pkey],
'on_error': on_error on_success: on_success,
on_error: on_error
}); });
command.set_option(that.other_entity, values.join(',')); command.set_option(that.other_entity, values.join(','));
@ -631,10 +641,11 @@ IPA.association_table_widget = function (spec) {
var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || '';
var command = IPA.command({ var command = IPA.command({
'method': that.entity_name+'_'+that.remove_method, entity: that.entity_name,
'args': [pkey], method: that.remove_method,
'on_success': on_success, args: [pkey],
'on_error': on_error on_success: on_success,
on_error: on_error
}); });
command.set_option(that.other_entity, values.join(',')); command.set_option(that.other_entity, values.join(','));
@ -985,11 +996,12 @@ IPA.association_facet = function (spec) {
options[relationship_filter] = pkey; options[relationship_filter] = pkey;
var command = IPA.command({ var command = IPA.command({
'on_success': on_success, entity: that.other_entity,
'on_error': on_error, method: 'find',
'method': that.other_entity+'_find', args: args,
'args': args, options: options,
options: options on_success: on_success,
on_error: on_error
}); });
command.execute(); command.execute();
@ -1036,7 +1048,14 @@ IPA.association_facet = function (spec) {
} }
var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || '';
IPA.cmd('show', [pkey], {'all': true, 'rights': true}, on_success, on_error, that.entity_name); IPA.command({
entity: that.entity_name,
method: 'show',
args: [pkey],
options: {'all': true, 'rights': true},
on_success: on_success,
on_error: on_error
}).execute();
}; };
that.association_facet_init = that.init; that.association_facet_init = that.init;

View File

@ -511,11 +511,14 @@ IPA.cert.status_widget = function(spec) {
that.get_button = IPA.button({ that.get_button = IPA.button({
label: IPA.messages.buttons.get, label: IPA.messages.buttons.get,
'click': function() { 'click': function() {
IPA.cmd(that.entity_name+'_show', [that.pkey], {}, IPA.command({
function(data, text_status, xhr) { entity: that.entity_name,
method: 'show',
args: [that.pkey],
on_success: function(data, text_status, xhr) {
get_certificate(data.result.result); get_certificate(data.result.result);
} }
); }).execute();
} }
}); });
button.replaceWith(that.get_button); button.replaceWith(that.get_button);
@ -524,11 +527,14 @@ IPA.cert.status_widget = function(spec) {
that.revoke_button = IPA.button({ that.revoke_button = IPA.button({
label: IPA.messages.buttons.revoke, label: IPA.messages.buttons.revoke,
'click': function() { 'click': function() {
IPA.cmd(that.entity_name+'_show', [that.pkey], {}, IPA.command({
function(data, text_status, xhr) { entity: that.entity_name,
method: 'show',
args: [that.pkey],
on_success: function(data, text_status, xhr) {
revoke_certificate(data.result.result); revoke_certificate(data.result.result);
} }
); }).execute();
} }
}); });
button.replaceWith(that.revoke_button); button.replaceWith(that.revoke_button);
@ -537,11 +543,14 @@ IPA.cert.status_widget = function(spec) {
that.view_button = IPA.button({ that.view_button = IPA.button({
label: IPA.messages.buttons.view, label: IPA.messages.buttons.view,
'click': function() { 'click': function() {
IPA.cmd(that.entity_name+'_show', [that.pkey], {}, IPA.command({
function(data, text_status, xhr) { entity: that.entity_name,
method: 'show',
args: [that.pkey],
on_success: function(data, text_status, xhr) {
view_certificate(data.result.result); view_certificate(data.result.result);
} }
); }).execute();
} }
}); });
button.replaceWith(that.view_button); button.replaceWith(that.view_button);
@ -552,11 +561,14 @@ IPA.cert.status_widget = function(spec) {
that.restore_button = IPA.button({ that.restore_button = IPA.button({
label: IPA.messages.buttons.restore, label: IPA.messages.buttons.restore,
'click': function() { 'click': function() {
IPA.cmd(that.entity_name+'_show', [that.pkey], {}, IPA.command({
function(data, text_status, xhr) { entity: that.entity_name,
method: 'show',
args: [that.pkey],
on_success: function(data, text_status, xhr) {
restore_certificate(data.result.result); restore_certificate(data.result.result);
} }
); }).execute();
} }
}); });
button.replaceWith(that.restore_button); button.replaceWith(that.restore_button);
@ -605,11 +617,11 @@ IPA.cert.status_widget = function(spec) {
return; return;
} }
IPA.cmd( IPA.command({
'cert_show', entity: 'cert',
[serial_number], method: 'show',
{ }, args: [serial_number],
function(data, text_status, xhr) { on_success: function(data, text_status, xhr) {
var revocation_reason = data.result.result.revocation_reason; var revocation_reason = data.result.result.revocation_reason;
if (revocation_reason == undefined) { if (revocation_reason == undefined) {
set_status(IPA.cert.CERTIFICATE_STATUS_VALID); set_status(IPA.cert.CERTIFICATE_STATUS_VALID);
@ -617,7 +629,7 @@ IPA.cert.status_widget = function(spec) {
set_status(IPA.cert.CERTIFICATE_STATUS_REVOKED, revocation_reason); set_status(IPA.cert.CERTIFICATE_STATUS_REVOKED, revocation_reason);
} }
} }
); }).execute();
} }
function view_certificate(result) { function view_certificate(result) {
@ -686,16 +698,17 @@ IPA.cert.status_widget = function(spec) {
'request': function(values) { 'request': function(values) {
var request = values['request']; var request = values['request'];
IPA.cmd( IPA.command({
'cert_request', entity: 'cert',
[request], method: 'request',
{ args: [request],
options: {
'principal': entity_principal 'principal': entity_principal
}, },
function(data, text_status, xhr) { on_success: function(data, text_status, xhr) {
check_status(data.result.result.serial_number); check_status(data.result.result.serial_number);
} }
); }).execute();
} }
}); });
@ -723,16 +736,17 @@ IPA.cert.status_widget = function(spec) {
'revoke': function(values) { 'revoke': function(values) {
var reason = values['reason']; var reason = values['reason'];
IPA.cmd( IPA.command({
'cert_revoke', entity: 'cert',
[serial_number], method: 'revoke',
{ args: [serial_number],
options: {
'revocation_reason': reason 'revocation_reason': reason
}, },
function(data, text_status, xhr) { on_success: function(data, text_status, xhr) {
check_status(serial_number); check_status(serial_number);
} }
); }).execute();
} }
}); });
@ -758,14 +772,14 @@ IPA.cert.status_widget = function(spec) {
var dialog = IPA.cert.restore_dialog({ var dialog = IPA.cert.restore_dialog({
'title': title, 'title': title,
'restore': function(values) { 'restore': function(values) {
IPA.cmd( IPA.command({
'cert_remove_hold', entity: 'cert',
[serial_number], method: 'remove_hold',
{ }, args: [serial_number],
function(data, text_status, xhr) { on_success: function(data, text_status, xhr) {
check_status(serial_number); check_status(serial_number);
} }
); }).execute();
} }
}); });

View File

@ -572,9 +572,9 @@ IPA.details_refresh = function() {
that.pkey = $.bbq.getState(that.entity_name + '-pkey', true) ; that.pkey = $.bbq.getState(that.entity_name + '-pkey', true) ;
var command = IPA.command({ var command = IPA.command({
method: that.entity_name+'_show', entity: that.entity_name,
args: [], method: 'show',
options: { 'all': true, 'rights': true } options: { all: true, rights: true }
}); });
if (IPA.details_refresh_devel_hook){ if (IPA.details_refresh_devel_hook){
@ -671,7 +671,8 @@ IPA.details_update = function(on_win, on_fail) {
var args = pkey ? [pkey] : []; var args = pkey ? [pkey] : [];
var command = IPA.command({ var command = IPA.command({
method: entity_name+'_mod', entity: entity_name,
method: 'mod',
args: args, args: args,
options: modlist, options: modlist,
on_success: on_success, on_success: on_success,

View File

@ -160,7 +160,8 @@ IPA.records_facet = function (spec){
options[key] = dialog.data.val(); options[key] = dialog.data.val();
var command = IPA.command({ var command = IPA.command({
method: 'dnsrecord_add', entity: 'dnsrecord',
method: 'add',
args: [pkey, resource], args: [pkey, resource],
options: options, options: options,
on_success: function(data, text_status, xhr) { on_success: function(data, text_status, xhr) {
@ -256,7 +257,8 @@ IPA.records_facet = function (spec){
var record = records[i]; var record = records[i];
var command = IPA.command({ var command = IPA.command({
method: 'dnsrecord_del', entity: 'dnsrecord',
method: 'del',
args: [zone, record.resource] args: [zone, record.resource]
}); });
@ -434,8 +436,14 @@ IPA.records_facet = function (spec){
if (resource_filter){ if (resource_filter){
pkey.push(resource_filter); pkey.push(resource_filter);
} }
IPA.cmd('dnsrecord_find',pkey,options,load_on_win, load_on_fail); IPA.command({
entity: 'dnsrecord',
method: 'find',
args: pkey,
options: options,
on_success: load_on_win,
on_error:load_on_fail
}).execute();
} }

View File

@ -150,7 +150,8 @@ IPA.entitle.search_facet = function(spec) {
} }
var command = IPA.command({ var command = IPA.command({
method: 'entitle_get', entity: 'entitle',
method: 'get',
options: { options: {
all: that.search_all all: that.search_all
}, },
@ -175,7 +176,8 @@ IPA.entitle.consume_dialog = function(spec) {
that.save(record); that.save(record);
var command = IPA.command({ var command = IPA.command({
method: 'entitle_consume', entity: 'entitle',
method: 'consume',
args: [ record.quantity ], args: [ record.quantity ],
on_success: function() { on_success: function() {
var entity = IPA.get_entity(that.entity_name); var entity = IPA.get_entity(that.entity_name);

View File

@ -343,17 +343,19 @@ IPA.hbacrule_details_facet = function (spec) {
var modify_operation = { var modify_operation = {
'execute': false, 'execute': false,
'command': IPA.command({ 'command': IPA.command({
'method': that.entity_name+'_mod', entity: that.entity_name,
'args': [pkey], method: 'mod',
'options': {'all': true, 'rights': true} args: [pkey],
options: {all: true, rights: true}
}) })
}; };
var remove_accesstime = { var remove_accesstime = {
'template': IPA.command({ 'template': IPA.command({
'method': that.entity_name+'_remove_accesstime', entity: that.entity_name,
'args': [pkey], method: 'remove_accesstime',
'options': {'all': true, 'rights': true} args: [pkey],
options: {all: true, rights: true}
}), }),
'commands': [] 'commands': []
}; };
@ -378,36 +380,40 @@ IPA.hbacrule_details_facet = function (spec) {
'category': 'usercategory', 'category': 'usercategory',
'has_values': false, 'has_values': false,
'command': IPA.command({ 'command': IPA.command({
'method': that.entity_name+'_remove_user', entity: that.entity_name,
'args': [pkey], method: 'remove_user',
'options': {'all': true, 'rights': true} args: [pkey],
options: {all: true, rights: true}
}) })
}, },
'memberhost': { 'memberhost': {
'category': 'hostcategory', 'category': 'hostcategory',
'has_values': false, 'has_values': false,
'command': IPA.command({ 'command': IPA.command({
'method': that.entity_name+'_remove_host', entity: that.entity_name,
'args': [pkey], method: 'remove_host',
'options': {'all': true, 'rights': true} args: [pkey],
options: {all: true, rights: true}
}) })
}, },
'memberservice': { 'memberservice': {
'category': 'servicecategory', 'category': 'servicecategory',
'has_values': false, 'has_values': false,
'command': IPA.command({ 'command': IPA.command({
'method': that.entity_name+'_remove_service', entity: that.entity_name,
'args': [pkey], method: 'remove_service',
'options': {'all': true, 'rights': true} args: [pkey],
options: {all: true, rights: true}
}) })
}, },
'sourcehost': { 'sourcehost': {
'category': 'sourcehostcategory', 'category': 'sourcehostcategory',
'has_values': false, 'has_values': false,
'command': IPA.command({ 'command': IPA.command({
'method': that.entity_name+'_remove_sourcehost', entity: that.entity_name,
'args': [pkey], method: 'remove_sourcehost',
'options': {'all': true, 'rights': true} args: [pkey],
options: {all: true, rights: true}
}) })
} }
}; };
@ -415,9 +421,10 @@ IPA.hbacrule_details_facet = function (spec) {
var enable_operation = { var enable_operation = {
'execute': false, 'execute': false,
'command': IPA.command({ 'command': IPA.command({
'method': that.entity_name+'_enable', entity: that.entity_name,
'args': [pkey], method: 'enable',
'options': {'all': true, 'rights': true} args: [pkey],
options: {all: true, rights: true}
}) })
}; };
@ -883,13 +890,14 @@ IPA.hbacrule_accesstime_widget = function (spec) {
var value = field.save()[0]; var value = field.save()[0];
var command = IPA.command({ var command = IPA.command({
'method': that.entity_name+'_add_'+that.name, entity: that.entity_name,
'args': [pkey], method: 'add_'+that.name,
'on_success': function() { args: [pkey],
on_success: function() {
that.refresh(); that.refresh();
if (on_success) on_success(); if (on_success) on_success();
}, },
'on_error': function() { on_error: function() {
that.refresh(); that.refresh();
if (on_error) on_error(); if (on_error) on_error();
} }
@ -960,8 +968,9 @@ IPA.hbacrule_accesstime_widget = function (spec) {
for (var i=0; i<values.length; i++) { for (var i=0; i<values.length; i++) {
var command = IPA.command({ var command = IPA.command({
'method': that.entity_name+'_remove_'+that.name, entity: that.entity_name,
'args': [pkey] method: 'remove_'+that.name,
args: [pkey]
}); });
command.set_option(that.name, values[i]); command.set_option(that.name, values[i]);
@ -991,7 +1000,14 @@ IPA.hbacrule_accesstime_widget = function (spec) {
} }
var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || '';
IPA.cmd('show', [pkey], {'rights': true}, on_success, on_error, that.entity_name); IPA.command({
entity: that.entity_name,
method: 'show',
args: [pkey],
options: {'rights': true},
on_success: on_success,
on_error: on_error
}).execute();
}; };
return that; return that;

View File

@ -268,12 +268,13 @@ IPA.host_provisioning_status_widget = function (spec) {
var pkey = that.facet.get_primary_key(); var pkey = that.facet.get_primary_key();
var command = IPA.command({ var command = IPA.command({
'name': that.entity_name+'_disable_'+pkey, name: that.entity_name+'_disable_'+pkey,
'method': that.entity_name+'_disable', entity: that.entity_name,
'args': [pkey], method: 'disable',
'options': { 'all': true, 'rights': true }, args: [pkey],
'on_success': on_success, options: { all: true, rights: true },
'on_error': on_error on_success: on_success,
on_error: on_error
}); });
command.execute(); command.execute();
@ -286,14 +287,15 @@ IPA.host_provisioning_status_widget = function (spec) {
that.otp_input.val(''); that.otp_input.val('');
var command = IPA.command({ var command = IPA.command({
'method': that.entity_name+'_mod', entity: that.entity_name,
'args': [pkey], method: 'mod',
'options': { args: [pkey],
'all': true, options: {
'rights': true, all: true,
'userpassword': otp rights: true,
userpassword: otp
}, },
'on_success': function(data, text_status, xhr) { on_success: function(data, text_status, xhr) {
alert(IPA.messages.objects.host.otp_confirmation); alert(IPA.messages.objects.host.otp_confirmation);
} }
}); });

View File

@ -55,6 +55,8 @@ var IPA = ( function () {
that.layout = $.bbq.getState('layout'); that.layout = $.bbq.getState('layout');
that.layouts_dir = 'layouts'; that.layouts_dir = 'layouts';
that.network_call_count = 0;
that.get_template = function(path) { that.get_template = function(path) {
var layout = that.layout || 'default'; var layout = that.layout || 'default';
return that.layouts_dir+'/'+layout+'/'+path; return that.layouts_dir+'/'+layout+'/'+path;
@ -74,33 +76,54 @@ var IPA = ( function () {
$.ajaxSetup(that.ajax_options); $.ajaxSetup(that.ajax_options);
var batch = IPA.batch_command({
name: 'ipa_init',
on_success: on_success,
on_error: on_error
});
var startup_batch = batch.add_command(IPA.command({
[ method: 'json_metadata',
{"method":"json_metadata","params":[[],{}]}, on_success: function(data, text_status, xhr) {
{"method":"i18n_messages","params":[[],{}]}, that.metadata = data;
{"method":"user_find","params":[[],{
"whoami":"true","all":"true"}]},
{"method":"env","params":[[],{}]},
{"method":"dns_is_enabled","params":[[],{}]}
];
IPA.cmd('batch', startup_batch, {},
function (data, text_status, xhr) {
that.metadata = data.result.results[0];
that.messages = data.result.results[1].messages;
that.whoami = data.result.results[2].result[0];
that.env = data.result.results[3].result;
that.dns_enabled = data.result.results[4].result;
if (on_success) {
on_success(data, text_status, xhr);
} }
}));
batch.add_command(IPA.command({
method: 'i18n_messages',
on_success: function(data, text_status, xhr) {
that.messages = data.messages;
}
}));
batch.add_command(IPA.command({
entity: 'user',
method: 'find',
options: {
whoami: true,
all: true
}, },
on_error, on_success: function(data, text_status, xhr) {
null, that.whoami = data.result[0];
'ipa_init'); }
}));
batch.add_command(IPA.command({
method: 'env',
on_success: function(data, text_status, xhr) {
that.env = data.result;
}
}));
batch.add_command(IPA.command({
entity: 'dns',
method: 'is_enabled',
on_success: function(data, text_status, xhr) {
that.dns_enabled = data.result;
}
}));
batch.execute();
}; };
that.get_entities = function () { that.get_entities = function () {
@ -184,9 +207,34 @@ var IPA = ( function () {
return true; return true;
}; };
that.display_activity_icon = function() {
that.network_call_count++;
$('.network-activity-indicator').css('display','inline');
};
that.hide_activity_icon = function() {
that.network_call_count--;
if (0 === that.network_call_count) {
$('.network-activity-indicator').css('display','none');
}
};
return that; return that;
}()); }());
/**
* Call an IPA command over JSON-RPC.
*
* Arguments:
* name - command name (optional)
* entity - command entity (optional)
* method - command method
* args - list of arguments, e.g. [username]
* options - dict of options, e.g. {givenname: 'Pavel'}
* on_success - callback function if command succeeds
* on_error - callback function if command fails
*/
IPA.command = function(spec) { IPA.command = function(spec) {
spec = spec || {}; spec = spec || {};
@ -194,6 +242,8 @@ IPA.command = function(spec) {
var that = {}; var that = {};
that.name = spec.name; that.name = spec.name;
that.entity = spec.entity;
that.method = spec.method; that.method = spec.method;
that.args = $.merge([], spec.args || []); that.args = $.merge([], spec.args || []);
@ -202,6 +252,10 @@ IPA.command = function(spec) {
that.on_success = spec.on_success; that.on_success = spec.on_success;
that.on_error = spec.on_error; that.on_error = spec.on_error;
that.get_command = function() {
return (that.entity ? that.entity+'_' : '') + that.method;
};
that.add_arg = function(arg) { that.add_arg = function(arg) {
that.args.push(arg); that.args.push(arg);
}; };
@ -215,20 +269,143 @@ IPA.command = function(spec) {
}; };
that.execute = function() { that.execute = function() {
IPA.cmd(
that.method, function dialog_open(xhr, text_status, error_thrown) {
that.args,
that.options, IPA.error_dialog = $('<div/>', {
that.on_success, id: 'error_dialog'
that.on_error, });
null,
that.name); if (error_thrown.url) {
$('<p/>', {
text: 'URL: '+error_thrown.url
}).appendTo(IPA.error_dialog);
}
$('<p/>', {
html: error_thrown.message
}).appendTo(IPA.error_dialog);
function close() {
IPA.error_dialog.dialog('destroy');
IPA.error_dialog.remove();
IPA.error_dialog = null;
}
var buttons = {};
/**
* When a user initially opens the Web UI without a Kerberos
* ticket, the messages including the button labels have not
* been loaded yet, so the button labels need default values.
*/
var label = IPA.messages.buttons ? IPA.messages.buttons.retry : 'Retry';
buttons[label] = function() {
close();
that.execute();
};
label = IPA.messages.buttons ? IPA.messages.buttons.cancel : 'Cancel';
buttons[label] = function() {
close();
if (that.on_error) {
that.on_error.call(this, xhr, text_status, error_thrown);
}
};
IPA.error_dialog.dialog({
modal: true,
title: error_thrown.title,
width: 400,
buttons: buttons,
close: function() {
close();
}
});
}
function error_handler(xhr, text_status, error_thrown) {
IPA.hide_activity_icon();
if (!error_thrown) {
error_thrown = {
name: xhr.responseText || 'Unknown Error',
message: xhr.statusText || 'Unknown Error'
};
}
if (xhr.status === 401) {
error_thrown.name = 'Kerberos ticket no longer valid.';
if (IPA.messages && IPA.messages.ajax) {
error_thrown.message = IPA.messages.ajax["401"];
} else {
error_thrown.message =
"Your kerberos ticket is no longer valid. "+
"Please run kinit and then click 'Retry'. "+
"If this is your first time running the IPA Web UI "+
"<a href='/ipa/config/unauthorized.html'>"+
"follow these directions</a> to configure your browser.";
}
}
if (!error_thrown.title) {
error_thrown.title = 'AJAX Error: '+error_thrown.name;
}
dialog_open.call(this, xhr, text_status, error_thrown);
}
function success_handler(data, text_status, xhr) {
IPA.hide_activity_icon();
if (!data) {
var error_thrown = {
title: 'HTTP Error '+xhr.status,
url: this.url,
message: data ? xhr.statusText : "No response"
};
dialog_open.call(this, xhr, text_status, error_thrown);
} else if (data.error) {
error_handler.call(this, xhr, text_status, /* error_thrown */ {
title: 'IPA Error '+data.error.code,
message: data.error.message
});
} else if (that.on_success) {
that.on_success.call(this, data, text_status, xhr);
}
}
var url = IPA.json_url;
var command = that.get_command();
if (IPA.use_static_files) {
url += '/' + (that.name ? that.name : command) + '.json';
}
var data = {
method: command,
params: [that.args, that.options]
};
var request = {
url: url,
data: JSON.stringify(data),
success: success_handler,
error: error_handler
};
IPA.display_activity_icon();
$.ajax(request);
}; };
that.to_json = function() { that.to_json = function() {
var json = {}; var json = {};
json.method = that.method; json.method = that.get_command();
json.params = []; json.params = [];
json.params[0] = that.args || []; json.params[0] = that.args || [];
@ -238,7 +415,7 @@ IPA.command = function(spec) {
}; };
that.to_string = function() { that.to_string = function() {
var string = that.method.replace(/_/g, '-'); var string = that.get_command().replace(/_/g, '-');
for (var i=0; i<that.args.length; i++) { for (var i=0; i<that.args.length; i++) {
string += ' '+that.args[i]; string += ' '+that.args[i];
@ -276,11 +453,14 @@ IPA.batch_command = function (spec) {
}; };
that.execute = function() { that.execute = function() {
IPA.cmd(
that.method, IPA.command({
that.args, name: that.name,
that.options, entity: that.entity,
function(data, text_status, xhr) { method: that.method,
args: that.args,
options: that.options,
on_success: function(data, text_status, xhr) {
for (var i=0; i<that.commands.length; i++) { for (var i=0; i<that.commands.length; i++) {
var command = that.commands[i]; var command = that.commands[i];
@ -311,186 +491,18 @@ IPA.batch_command = function (spec) {
} }
if (that.on_success) that.on_success(data, text_status, xhr); if (that.on_success) that.on_success(data, text_status, xhr);
}, },
function(xhr, text_status, error_thrown) { on_error: function(xhr, text_status, error_thrown) {
// TODO: undefined behavior // TODO: undefined behavior
if (that.on_error) { if (that.on_error) {
that.on_error(xhr, text_status, error_thrown); that.on_error(xhr, text_status, error_thrown);
} }
}, }
null, }).execute();
that.name);
}; };
return that; return that;
}; };
/* call an IPA command over JSON-RPC
* arguments:
* name - name of the command or method if objname is set
* args - list of positional arguments, e.g. [username]
* options - dict of options, e.g. {givenname: 'Pavel'}
* win_callback - function to call if the JSON request succeeds
* fail_callback - function to call if the JSON request fails
* objname - name of an IPA object (optional) */
IPA.cmd = function (name, args, options, win_callback, fail_callback, objname, command_name) {
var default_json_url = '/ipa/json';
var network_call_count = 0;
function display_activity_icon(){
network_call_count += 1;
$('.network-activity-indicator').css('display','inline');
}
function hide_activity_icon(){
network_call_count -= 1;
if (0 === network_call_count){
$('.network-activity-indicator').css('display','none');
}
}
function dialog_open(xhr, text_status, error_thrown) {
var that = this;
IPA.error_dialog = $('<div/>', {
id: 'error_dialog'
});
if (error_thrown.url) {
$('<p/>', {
text: 'URL: '+error_thrown.url
}).appendTo(IPA.error_dialog);
}
$('<p/>', {
html: error_thrown.message
}).appendTo(IPA.error_dialog);
function close() {
IPA.error_dialog.dialog('destroy');
IPA.error_dialog.remove();
IPA.error_dialog = null;
}
var buttons = {};
/**
* When a user initially opens the Web UI without a Kerberos
* ticket, the messages including the button labels have not
* been loaded yet, so the button labels need default values.
*/
var label = IPA.messages.buttons ? IPA.messages.buttons.retry : 'Retry';
buttons[label] = function() {
close();
IPA.cmd(name, args, options, win_callback, fail_callback,
objname, command_name);
};
label = IPA.messages.buttons ? IPA.messages.buttons.cancel : 'Cancel';
buttons[label] = function() {
close();
if (fail_callback) {
fail_callback.call(that, xhr, text_status, error_thrown);
}
};
IPA.error_dialog.dialog({
modal: true,
title: error_thrown.title,
width: 400,
buttons: buttons,
close: function() {
close();
}
});
}
function error_handler(xhr, text_status, error_thrown) {
hide_activity_icon();
if (!error_thrown) {
error_thrown = {
name: xhr.responseText || 'Unknown Error',
message: xhr.statusText || 'Unknown Error'
};
}
if (xhr.status === 401) {
error_thrown.name = 'Kerberos ticket no longer valid.';
if (IPA.messages && IPA.messages.ajax){
error_thrown.message = IPA.messages.ajax["401"];
} else {
error_thrown.message =
"Your kerberos ticket is no longer valid. "+
"Please run kinit and then click 'Retry'. "+
"If this is your first time running the IPA Web UI "+
"<a href='/ipa/config/unauthorized.html'>"+
"follow these directions</a> to configure your browser.";
}
}
if (!error_thrown.title) {
error_thrown.title = 'AJAX Error: '+error_thrown.name;
}
dialog_open.call(this, xhr, text_status, error_thrown);
}
function success_handler(data, text_status, xhr) {
hide_activity_icon();
if (!data) {
var error_thrown = {
title: 'HTTP Error '+xhr.status,
url: this.url,
message: data ? xhr.statusText : "No response"
};
dialog_open.call(this, xhr, text_status, error_thrown);
} else if (data.error) {
error_handler.call(this, xhr, text_status, /* error_thrown */ {
title: 'IPA Error '+data.error.code,
message: data.error.message
});
} else if (win_callback) {
win_callback.call(this, data, text_status, xhr);
}
}
IPA.jsonrpc_id += 1;
var id = IPA.jsonrpc_id;
var method_name = name;
if (objname){
method_name = objname + '_' + name;
}
var url = IPA.json_url;
if (IPA.use_static_files){
if (command_name) {
url += '/' + command_name + '.json';
} else {
url += '/' + method_name + '.json';
}
}
var data = {
method: method_name,
params: [args, options],
id: id
};
var request = {
url: url,
data: JSON.stringify(data),
success: success_handler,
error: error_handler
};
display_activity_icon();
$.ajax(request);
return (id);
};
/* helper function used to retrieve information about an attribute */ /* helper function used to retrieve information about an attribute */
IPA.get_entity_param = function(entity_name, name) { IPA.get_entity_param = function(entity_name, name) {

View File

@ -145,10 +145,11 @@ IPA.rule_association_table_widget = function (spec) {
if (that.category) { if (that.category) {
command = IPA.command({ command = IPA.command({
'method': that.entity_name+'_mod', entity: that.entity_name,
'args': [pkey], method: 'mod',
'options': {'all': true, 'rights': true}, args: [pkey],
'on_success': function() { options: {all: true, rights: true},
on_success: function() {
var record = {}; var record = {};
record[that.category.name] = ['']; record[that.category.name] = [''];
that.category.load(record); that.category.load(record);
@ -159,8 +160,9 @@ IPA.rule_association_table_widget = function (spec) {
} }
command = IPA.command({ command = IPA.command({
'method': that.entity_name+'_'+that.add_method, entity: that.entity_name,
'args': [pkey] method: that.add_method,
args: [pkey]
}); });
command.set_option(that.other_entity, values.join(',')); command.set_option(that.other_entity, values.join(','));
batch.add_command(command); batch.add_command(command);

View File

@ -340,7 +340,8 @@ IPA.search_facet = function(spec) {
for (var i=0; i<values.length; i++) { for (var i=0; i<values.length; i++) {
var command = IPA.command({ var command = IPA.command({
'method': that.entity_name+'_del' entity: that.entity_name,
method: 'del'
}); });
command.add_arg(values[i]); command.add_arg(values[i]);
batch.add_command(command); batch.add_command(command);
@ -393,7 +394,8 @@ IPA.search_facet = function(spec) {
that.filter = $.bbq.getState(that.entity_name + '-filter', true) || ''; that.filter = $.bbq.getState(that.entity_name + '-filter', true) || '';
var command = IPA.command({ var command = IPA.command({
method: that.entity_name+'_find', entity: that.entity_name,
method: 'find',
args: [that.filter], args: [that.filter],
options: { options: {
all: that.search_all all: that.search_all

View File

@ -279,15 +279,18 @@ IPA.service_provisioning_status_widget = function (spec) {
dialog.add_button(IPA.messages.objects.service.unprovision, function() { dialog.add_button(IPA.messages.objects.service.unprovision, function() {
var pkey = that.result['krbprincipalname'][0]; var pkey = that.result['krbprincipalname'][0];
IPA.cmd(that.entity_name+'_disable', [pkey], {}, IPA.command({
function(data, text_status, xhr) { entity: that.entity_name,
method: 'disable',
args: [pkey],
on_success: function(data, text_status, xhr) {
set_status('missing'); set_status('missing');
dialog.close(); dialog.close();
}, },
function(xhr, text_status, error_thrown) { on_error: function(xhr, text_status, error_thrown) {
dialog.close(); dialog.close();
} }
); }).execute();
}); });
dialog.init(); dialog.init();

View File

@ -167,11 +167,12 @@ IPA.sudocmd_member_sudocmdgroup_table_widget = function (spec) {
var value = that.values[i]; var value = that.values[i];
var command = IPA.command({ var command = IPA.command({
'method': that.other_entity+'_show', entity: that.other_entity,
'args': [value], method: 'show',
'options': { args: [value],
'all': true, options: {
'rights': true all: true,
rights: true
} }
}); });
@ -197,8 +198,9 @@ IPA.sudocmd_member_sudocmdgroup_table_widget = function (spec) {
var value = values[i]; var value = values[i];
var command = IPA.command({ var command = IPA.command({
'method': that.other_entity+'_add_member', entity: that.other_entity,
'args': [value] method: 'add_member',
args: [value]
}); });
command.set_option('sudocmd', pkey); command.set_option('sudocmd', pkey);
@ -225,8 +227,9 @@ IPA.sudocmd_member_sudocmdgroup_table_widget = function (spec) {
var value = values[i]; var value = values[i];
var command = IPA.command({ var command = IPA.command({
'method': that.other_entity+'_remove_member', entity: that.other_entity,
'args': [value] method: 'remove_member',
args: [value]
}); });
command.set_option('sudocmd', pkey); command.set_option('sudocmd', pkey);
@ -351,9 +354,10 @@ IPA.sudorule_details_facet = function (spec) {
var modify_operation = { var modify_operation = {
'execute': false, 'execute': false,
'command': IPA.command({ 'command': IPA.command({
'method': that.entity_name+'_mod', entity: that.entity_name,
'args': [pkey], method: 'mod',
'options': {'all': true, 'rights': true} args: [pkey],
options: {all: true, rights: true}
}) })
}; };
@ -380,45 +384,50 @@ IPA.sudorule_details_facet = function (spec) {
'category': 'usercategory', 'category': 'usercategory',
'has_values': false, 'has_values': false,
'command': IPA.command({ 'command': IPA.command({
'method': that.entity_name+'_remove_user', entity: that.entity_name,
'args': [pkey], method: 'remove_user',
'options': {'all': true, 'rights': true} args: [pkey],
options: {all: true, rights: true}
}) })
}, },
'memberhost': { 'memberhost': {
'category': 'hostcategory', 'category': 'hostcategory',
'has_values': false, 'has_values': false,
'command': IPA.command({ 'command': IPA.command({
'method': that.entity_name+'_remove_host', entity: that.entity_name,
'args': [pkey], method: 'remove_host',
'options': {'all': true, 'rights': true} args: [pkey],
options: {all: true, rights: true}
}) })
}, },
'memberallowcmd': { 'memberallowcmd': {
'category': 'cmdcategory', 'category': 'cmdcategory',
'has_values': false, 'has_values': false,
'command': IPA.command({ 'command': IPA.command({
'method': that.entity_name+'_remove_allow_command', entity: that.entity_name,
'args': [pkey], method: 'remove_allow_command',
'options': {'all': true, 'rights': true} args: [pkey],
options: {all: true, rights: true}
}) })
}, },
'ipasudorunas': { 'ipasudorunas': {
'category': 'ipasudorunasusercategory', 'category': 'ipasudorunasusercategory',
'has_values': false, 'has_values': false,
'command': IPA.command({ 'command': IPA.command({
'method': that.entity_name+'_remove_runasuser', entity: that.entity_name,
'args': [pkey], method: 'remove_runasuser',
'options': {'all': true, 'rights': true} args: [pkey],
options: {all: true, rights: true}
}) })
}, },
'ipasudorunasgroup': { 'ipasudorunasgroup': {
'category': 'ipasudorunasgroupcategory', 'category': 'ipasudorunasgroupcategory',
'has_values': false, 'has_values': false,
'command': IPA.command({ 'command': IPA.command({
'method': that.entity_name+'_remove_runasgroup', entity: that.entity_name,
'args': [pkey], method: 'remove_runasgroup',
'options': {'all': true, 'rights': true} args: [pkey],
options: {all: true, rights: true}
}) })
} }
}; };
@ -426,9 +435,10 @@ IPA.sudorule_details_facet = function (spec) {
var enable_operation = { var enable_operation = {
'execute': false, 'execute': false,
'command': IPA.command({ 'command': IPA.command({
'method': that.entity_name+'_enable', entity: that.entity_name,
'args': [pkey], method: 'enable',
'options': {'all': true, 'rights': true} args: [pkey],
options: {all: true, rights: true}
}) })
}; };
@ -1234,10 +1244,11 @@ IPA.sudorule_command_table_widget = function (spec) {
if (that.category) { if (that.category) {
command = IPA.command({ command = IPA.command({
'method': that.entity_name+'_mod', entity: that.entity_name,
'args': [pkey], method: 'mod',
'options': {'all': true, 'rights': true}, args: [pkey],
'on_success': function() { options: {all: true, rights: true},
on_success: function() {
var record = {}; var record = {};
record[that.category.name] = ['']; record[that.category.name] = [''];
that.category.load(record); that.category.load(record);
@ -1248,8 +1259,9 @@ IPA.sudorule_command_table_widget = function (spec) {
} }
command = IPA.command({ command = IPA.command({
'method': that.entity_name+'_'+that.add_method, entity: that.entity_name,
'args': [pkey] method: that.add_method,
args: [pkey]
}); });
command.set_option(that.other_entity, values.join(',')); command.set_option(that.other_entity, values.join(','));
batch.add_command(command); batch.add_command(command);
@ -1262,10 +1274,11 @@ IPA.sudorule_command_table_widget = function (spec) {
var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || '';
var command = IPA.command({ var command = IPA.command({
'method': that.entity_name+'_'+that.remove_method, entity: that.entity_name,
'args': [pkey], method: that.remove_method,
'on_success': on_success, args: [pkey],
'on_error': on_error on_success: on_success,
on_error: on_error
}); });
command.set_option(that.other_entity, values.join(',')); command.set_option(that.other_entity, values.join(','));

View File

@ -23,37 +23,47 @@ module('associate');
test("Testing serial_associator().", function() { test("Testing serial_associator().", function() {
expect(7); expect(10);
var orig_ipa_cmd = IPA.cmd; var orig_ipa_command = IPA.command;
var counter = 0; var counter = 0;
var params = { var params = {
method: "add_member", method: 'add_member',
pkey: "test", pkey: 'test',
entity_name: "user", entity_name: 'user',
other_entity: "group" other_entity: 'group'
}; };
params.values = ['user1', 'user2', 'user3']; params.values = ['user1', 'user2', 'user3'];
IPA.cmd = function(name, args, options, win_callback, fail_callback, objname) { IPA.command = function(spec) {
var that = orig_ipa_command(spec);
that.execute = function() {
counter++; counter++;
equals( equals(
name, params.other_entity+'_'+params.method, that.entity, params.other_entity,
"Checking IPA.cmd() parameter: method" 'Checking IPA.command() parameter: entity'
); );
equals( equals(
args[0], "user"+counter, that.method, params.method,
"Checking IPA.cmd() parameter: primary key" 'Checking IPA.command() parameter: method'
); );
var response = {}; equals(
win_callback(response); that.args[0], 'user'+counter,
return 0; 'Checking IPA.command() parameter: primary key'
);
that.on_success();
};
return that;
}; };
params.on_success = function() { params.on_success = function() {
@ -63,14 +73,14 @@ test("Testing serial_associator().", function() {
var associator = IPA.serial_associator(params); var associator = IPA.serial_associator(params);
associator.execute(); associator.execute();
IPA.cmd = orig_ipa_cmd; IPA.command = orig_ipa_command;
}); });
test("Testing bulk_associator().", function() { test("Testing bulk_associator().", function() {
expect(4); expect(5);
var orig_ipa_cmd = IPA.cmd; var orig_ipa_command = IPA.command;
var counter = 0; var counter = 0;
@ -83,27 +93,37 @@ test("Testing bulk_associator().", function() {
params.values = ['user1', 'user2', 'user3']; params.values = ['user1', 'user2', 'user3'];
IPA.cmd = function(name, args, options, win_callback, fail_callback, objname) { IPA.command = function(spec) {
var that = orig_ipa_command(spec);
that.execute = function() {
counter++; counter++;
equals( equals(
name, params.entity_name+'_'+params.method, that.entity, params.entity_name,
"Checking IPA.cmd() parameter: method" 'Checking IPA.command() parameter: entity'
); );
equals( equals(
args[0], params.pkey, that.method, params.method,
"Checking IPA.cmd() parameter: primary key" 'Checking IPA.command() parameter: method'
); );
equals( equals(
options[params.other_entity], "user1,user2,user3", that.args[0], params.pkey,
"Checking IPA.cmd() parameter: options[\""+params.other_entity+"\"]" 'Checking IPA.command() parameter: primary key'
); );
var response = {}; equals(
win_callback(response); that.options[params.other_entity], 'user1,user2,user3',
return 0; 'Checking IPA.command() parameter: options[\""+params.other_entity+"\"]'
);
that.on_success();
};
return that;
}; };
params.on_success = function() { params.on_success = function() {
@ -113,5 +133,5 @@ test("Testing bulk_associator().", function() {
var associator = IPA.bulk_associator(params); var associator = IPA.bulk_associator(params);
associator.execute(); associator.execute();
IPA.cmd = orig_ipa_cmd; IPA.command = orig_ipa_command;
}); });

View File

@ -114,18 +114,18 @@ test("Testing details lifecycle: create, setup, load.", function(){
var result = {}; var result = {};
IPA.cmd( IPA.command({
'user_show', entity: 'user',
['kfrog'], method: 'show',
{}, args: ['kfrog'],
function(data, text_status, xhr) { on_success: function(data, text_status, xhr) {
result = data.result.result; result = data.result.result;
ok(true, "IPA.cmd() succeeded."); ok(true, "IPA.command() succeeded.");
}, },
function(xhr, text_status, error_thrown) { on_error: function(xhr, text_status, error_thrown) {
ok(false, "IPA.cmd() failed: "+error_thrown); ok(false, "IPA.command() failed: "+error_thrown);
} }
); }).execute();
var setup_called = false; var setup_called = false;
var save_called= false; var save_called= false;

View File

@ -95,7 +95,7 @@ test("Testing IPA.get_member_attribute().", function() {
); );
}); });
test("Testing successful IPA.cmd().", function() { test("Testing successful IPA.command().", function() {
var method = 'method'; var method = 'method';
var args = ['arg1', 'arg2', 'arg3']; var args = ['arg1', 'arg2', 'arg3'];
@ -148,7 +148,14 @@ test("Testing successful IPA.cmd().", function() {
request.success(xhr, text_status, error_thrown); request.success(xhr, text_status, error_thrown);
}; };
IPA.cmd(method, args, options, success_handler, error_handler, object); IPA.command({
entity: object,
method: method,
args: args,
options: options,
on_success: success_handler,
on_error: error_handler
}).execute();
equals( equals(
ajax_counter, 1, ajax_counter, 1,
@ -168,7 +175,7 @@ test("Testing successful IPA.cmd().", function() {
$.ajax = orig; $.ajax = orig;
}); });
test("Testing unsuccessful IPA.cmd().", function() { test("Testing unsuccessful IPA.command().", function() {
var method = 'method'; var method = 'method';
var args = ['arg1', 'arg2', 'arg3']; var args = ['arg1', 'arg2', 'arg3'];
@ -221,7 +228,14 @@ test("Testing unsuccessful IPA.cmd().", function() {
request.error(xhr, text_status, error_thrown); request.error(xhr, text_status, error_thrown);
}; };
IPA.cmd(method, args, options, success_handler, error_handler, object); IPA.command({
entity: object,
method: method,
args: args,
options: options,
on_success: success_handler,
on_error: error_handler
}).execute();
var dialog = IPA.error_dialog.parent('.ui-dialog'); var dialog = IPA.error_dialog.parent('.ui-dialog');

View File

@ -136,11 +136,17 @@ IPA.user_status_widget = function(spec) {
var jobj = $(this); var jobj = $(this);
var val = jobj.attr('title'); var val = jobj.attr('title');
var pkey = $.bbq.getState('user-pkey'); var pkey = $.bbq.getState('user-pkey');
var command = 'user_enable'; var method = 'enable';
if (val == IPA.messages.objects.user.active) { if (val == IPA.messages.objects.user.active) {
command = 'user_disable'; method = 'disable';
} }
IPA.cmd(command, [pkey], {}, on_lock_win,on_lock_fail); IPA.command({
entity: 'user',
method: method,
args: [pkey],
on_success: on_lock_win,
on_error: on_lock_fail
}).execute();
return (false); return (false);
} }

View File

@ -1346,7 +1346,14 @@ IPA.table_widget = function (spec) {
} }
var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || ''; var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || '';
IPA.cmd('show', [pkey], {'all': true, 'rights': true}, on_success, on_error, that.entity_name); IPA.command({
entity: that.entity_name,
method: 'show',
args: [pkey],
options: {'all': true, 'rights': true},
on_success: on_success,
on_error: on_error
}).execute();
}; };
if (spec.columns) { if (spec.columns) {
@ -1400,7 +1407,8 @@ IPA.entity_select_widget = function(spec) {
function find_error(err){ function find_error(err){
} }
IPA.command({ IPA.command({
method: entity+'_find', entity: entity,
method: 'find',
args:[that.entity_filter.val()], args:[that.entity_filter.val()],
options:{}, options:{},
on_success:find_success, on_success:find_success,