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 command = IPA.command({
method: that.entity_name+'_add',
entity: that.entity_name,
method: 'add',
on_success: on_success,
on_error: on_error
});

View File

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

View File

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

View File

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

View File

@ -160,7 +160,8 @@ IPA.records_facet = function (spec){
options[key] = dialog.data.val();
var command = IPA.command({
method: 'dnsrecord_add',
entity: 'dnsrecord',
method: 'add',
args: [pkey, resource],
options: options,
on_success: function(data, text_status, xhr) {
@ -256,7 +257,8 @@ IPA.records_facet = function (spec){
var record = records[i];
var command = IPA.command({
method: 'dnsrecord_del',
entity: 'dnsrecord',
method: 'del',
args: [zone, record.resource]
});
@ -434,8 +436,14 @@ IPA.records_facet = function (spec){
if (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({
method: 'entitle_get',
entity: 'entitle',
method: 'get',
options: {
all: that.search_all
},
@ -175,7 +176,8 @@ IPA.entitle.consume_dialog = function(spec) {
that.save(record);
var command = IPA.command({
method: 'entitle_consume',
entity: 'entitle',
method: 'consume',
args: [ record.quantity ],
on_success: function() {
var entity = IPA.get_entity(that.entity_name);

View File

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

View File

@ -268,12 +268,13 @@ IPA.host_provisioning_status_widget = function (spec) {
var pkey = that.facet.get_primary_key();
var command = IPA.command({
'name': that.entity_name+'_disable_'+pkey,
'method': that.entity_name+'_disable',
'args': [pkey],
'options': { 'all': true, 'rights': true },
'on_success': on_success,
'on_error': on_error
name: that.entity_name+'_disable_'+pkey,
entity: that.entity_name,
method: 'disable',
args: [pkey],
options: { all: true, rights: true },
on_success: on_success,
on_error: on_error
});
command.execute();
@ -286,14 +287,15 @@ IPA.host_provisioning_status_widget = function (spec) {
that.otp_input.val('');
var command = IPA.command({
'method': that.entity_name+'_mod',
'args': [pkey],
'options': {
'all': true,
'rights': true,
'userpassword': otp
entity: that.entity_name,
method: 'mod',
args: [pkey],
options: {
all: true,
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);
}
});

View File

@ -55,6 +55,8 @@ var IPA = ( function () {
that.layout = $.bbq.getState('layout');
that.layouts_dir = 'layouts';
that.network_call_count = 0;
that.get_template = function(path) {
var layout = that.layout || 'default';
return that.layouts_dir+'/'+layout+'/'+path;
@ -74,33 +76,54 @@ var IPA = ( function () {
$.ajaxSetup(that.ajax_options);
var batch = IPA.batch_command({
name: 'ipa_init',
on_success: on_success,
on_error: on_error
});
var startup_batch =
[
{"method":"json_metadata","params":[[],{}]},
{"method":"i18n_messages","params":[[],{}]},
{"method":"user_find","params":[[],{
"whoami":"true","all":"true"}]},
{"method":"env","params":[[],{}]},
{"method":"dns_is_enabled","params":[[],{}]}
];
batch.add_command(IPA.command({
method: 'json_metadata',
on_success: function(data, text_status, xhr) {
that.metadata = data;
}
}));
batch.add_command(IPA.command({
method: 'i18n_messages',
on_success: function(data, text_status, xhr) {
that.messages = data.messages;
}
}));
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({
entity: 'user',
method: 'find',
options: {
whoami: true,
all: true
},
on_error,
null,
'ipa_init');
on_success: function(data, text_status, xhr) {
that.whoami = data.result[0];
}
}));
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 () {
@ -184,9 +207,34 @@ var IPA = ( function () {
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;
}());
/**
* 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) {
spec = spec || {};
@ -194,6 +242,8 @@ IPA.command = function(spec) {
var that = {};
that.name = spec.name;
that.entity = spec.entity;
that.method = spec.method;
that.args = $.merge([], spec.args || []);
@ -202,6 +252,10 @@ IPA.command = function(spec) {
that.on_success = spec.on_success;
that.on_error = spec.on_error;
that.get_command = function() {
return (that.entity ? that.entity+'_' : '') + that.method;
};
that.add_arg = function(arg) {
that.args.push(arg);
};
@ -215,20 +269,143 @@ IPA.command = function(spec) {
};
that.execute = function() {
IPA.cmd(
that.method,
that.args,
that.options,
that.on_success,
that.on_error,
null,
that.name);
function dialog_open(xhr, text_status, error_thrown) {
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();
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() {
var json = {};
json.method = that.method;
json.method = that.get_command();
json.params = [];
json.params[0] = that.args || [];
@ -238,7 +415,7 @@ IPA.command = function(spec) {
};
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++) {
string += ' '+that.args[i];
@ -276,11 +453,14 @@ IPA.batch_command = function (spec) {
};
that.execute = function() {
IPA.cmd(
that.method,
that.args,
that.options,
function(data, text_status, xhr) {
IPA.command({
name: that.name,
entity: that.entity,
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++) {
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);
},
function(xhr, text_status, error_thrown) {
on_error: function(xhr, text_status, error_thrown) {
// TODO: undefined behavior
if (that.on_error) {
that.on_error(xhr, text_status, error_thrown);
}
},
null,
that.name);
}
}).execute();
};
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 */
IPA.get_entity_param = function(entity_name, name) {

View File

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

View File

@ -340,7 +340,8 @@ IPA.search_facet = function(spec) {
for (var i=0; i<values.length; i++) {
var command = IPA.command({
'method': that.entity_name+'_del'
entity: that.entity_name,
method: 'del'
});
command.add_arg(values[i]);
batch.add_command(command);
@ -393,7 +394,8 @@ IPA.search_facet = function(spec) {
that.filter = $.bbq.getState(that.entity_name + '-filter', true) || '';
var command = IPA.command({
method: that.entity_name+'_find',
entity: that.entity_name,
method: 'find',
args: [that.filter],
options: {
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() {
var pkey = that.result['krbprincipalname'][0];
IPA.cmd(that.entity_name+'_disable', [pkey], {},
function(data, text_status, xhr) {
IPA.command({
entity: that.entity_name,
method: 'disable',
args: [pkey],
on_success: function(data, text_status, xhr) {
set_status('missing');
dialog.close();
},
function(xhr, text_status, error_thrown) {
on_error: function(xhr, text_status, error_thrown) {
dialog.close();
}
);
}).execute();
});
dialog.init();

View File

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

View File

@ -23,37 +23,47 @@ module('associate');
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 params = {
method: "add_member",
pkey: "test",
entity_name: "user",
other_entity: "group"
method: 'add_member',
pkey: 'test',
entity_name: 'user',
other_entity: 'group'
};
params.values = ['user1', 'user2', 'user3'];
IPA.cmd = function(name, args, options, win_callback, fail_callback, objname) {
counter++;
IPA.command = function(spec) {
equals(
name, params.other_entity+'_'+params.method,
"Checking IPA.cmd() parameter: method"
);
var that = orig_ipa_command(spec);
equals(
args[0], "user"+counter,
"Checking IPA.cmd() parameter: primary key"
);
that.execute = function() {
counter++;
var response = {};
win_callback(response);
return 0;
equals(
that.entity, params.other_entity,
'Checking IPA.command() parameter: entity'
);
equals(
that.method, params.method,
'Checking IPA.command() parameter: method'
);
equals(
that.args[0], 'user'+counter,
'Checking IPA.command() parameter: primary key'
);
that.on_success();
};
return that;
};
params.on_success = function() {
@ -63,14 +73,14 @@ test("Testing serial_associator().", function() {
var associator = IPA.serial_associator(params);
associator.execute();
IPA.cmd = orig_ipa_cmd;
IPA.command = orig_ipa_command;
});
test("Testing bulk_associator().", function() {
expect(4);
expect(5);
var orig_ipa_cmd = IPA.cmd;
var orig_ipa_command = IPA.command;
var counter = 0;
@ -83,27 +93,37 @@ test("Testing bulk_associator().", function() {
params.values = ['user1', 'user2', 'user3'];
IPA.cmd = function(name, args, options, win_callback, fail_callback, objname) {
counter++;
IPA.command = function(spec) {
equals(
name, params.entity_name+'_'+params.method,
"Checking IPA.cmd() parameter: method"
);
var that = orig_ipa_command(spec);
equals(
args[0], params.pkey,
"Checking IPA.cmd() parameter: primary key"
);
that.execute = function() {
counter++;
equals(
options[params.other_entity], "user1,user2,user3",
"Checking IPA.cmd() parameter: options[\""+params.other_entity+"\"]"
);
equals(
that.entity, params.entity_name,
'Checking IPA.command() parameter: entity'
);
var response = {};
win_callback(response);
return 0;
equals(
that.method, params.method,
'Checking IPA.command() parameter: method'
);
equals(
that.args[0], params.pkey,
'Checking IPA.command() parameter: primary key'
);
equals(
that.options[params.other_entity], 'user1,user2,user3',
'Checking IPA.command() parameter: options[\""+params.other_entity+"\"]'
);
that.on_success();
};
return that;
};
params.on_success = function() {
@ -113,5 +133,5 @@ test("Testing bulk_associator().", function() {
var associator = IPA.bulk_associator(params);
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 = {};
IPA.cmd(
'user_show',
['kfrog'],
{},
function(data, text_status, xhr) {
IPA.command({
entity: 'user',
method: 'show',
args: ['kfrog'],
on_success: function(data, text_status, xhr) {
result = data.result.result;
ok(true, "IPA.cmd() succeeded.");
ok(true, "IPA.command() succeeded.");
},
function(xhr, text_status, error_thrown) {
ok(false, "IPA.cmd() failed: "+error_thrown);
on_error: function(xhr, text_status, error_thrown) {
ok(false, "IPA.command() failed: "+error_thrown);
}
);
}).execute();
var setup_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 args = ['arg1', 'arg2', 'arg3'];
@ -148,7 +148,14 @@ test("Testing successful IPA.cmd().", function() {
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(
ajax_counter, 1,
@ -168,7 +175,7 @@ test("Testing successful IPA.cmd().", function() {
$.ajax = orig;
});
test("Testing unsuccessful IPA.cmd().", function() {
test("Testing unsuccessful IPA.command().", function() {
var method = 'method';
var args = ['arg1', 'arg2', 'arg3'];
@ -221,7 +228,14 @@ test("Testing unsuccessful IPA.cmd().", function() {
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');

View File

@ -136,11 +136,17 @@ IPA.user_status_widget = function(spec) {
var jobj = $(this);
var val = jobj.attr('title');
var pkey = $.bbq.getState('user-pkey');
var command = 'user_enable';
var method = 'enable';
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);
}

View File

@ -1346,7 +1346,14 @@ IPA.table_widget = function (spec) {
}
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) {
@ -1400,7 +1407,8 @@ IPA.entity_select_widget = function(spec) {
function find_error(err){
}
IPA.command({
method: entity+'_find',
entity: entity,
method: 'find',
args:[that.entity_filter.val()],
options:{},
on_success:find_success,