Browse Source

UI-3274: Clean up HTTP 402 error guards on callApi error callbacks (#113)

* Remove guard for 402 error status

* Continue user creation w/o vmbox or device, if charges are declined

* Fix typo
4.3
Guillermo Gutiérrez 7 years ago
committed by GitHub
parent
commit
3e1b26e829
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 82 additions and 48 deletions
  1. +1
    -1
      i18n/en-US.json
  2. +81
    -47
      submodules/users/users.js

+ 1
- 1
i18n/en-US.json View File

@ -536,7 +536,7 @@
"nameHelp": "Type the User's First Name in the first input, and the User's Last Name in the second one",
"loginHelp": "This is the Username of this user, used to login to the application",
"vmboxHelp": "This is the Voicemail Box Number of this user, click on Change PIN to reset the PIN of the Voicemail box of this user",
"roleHelp": "The \"Admin\" will have rights to access the App Exchange and add apps to this accoutn, whereas the \"User\" will only be able to access the apps that are enabled for them",
"roleHelp": "The \"Admin\" will have rights to access the App Exchange and add apps to this account, whereas the \"User\" will only be able to access the apps that are enabled for them",
"languageHelp": "This will change the language of the text displayed in the UI",
"timezoneHelp": "This will set the Timezone used for this User's devices and Voicemail Box",
"ringingHelp": "This will set the Ringing Timeout for this User and his Devices. For example, if you set it to 20, this user will be rung for 20 seconds before the system moves to his Voicemail Box",


+ 81
- 47
submodules/users/users.js View File

@ -1653,22 +1653,26 @@ define(function(require) {
popup = args.popup;
template.find('.create_user').on('click', function() {
var action = $(this).data('action');
if (monster.ui.valid(template.find('#form_user_creation'))) {
var $buttons = template.find('.create_user'),
dataForm = _.merge(monster.ui.getFormData('form_user_creation'), {
user: {
device: {
family: template.find('#device_model').find(':selected').data('family')
}
if (!monster.ui.valid(template.find('#form_user_creation'))) {
return;
}
var action = $(this).data('action'),
$buttons = template.find('.create_user'),
dataForm = _.merge(monster.ui.getFormData('form_user_creation'), {
user: {
device: {
family: template.find('#device_model').find(':selected').data('family')
}
}),
formattedData = self.usersFormatCreationData(dataForm);
}
}),
formattedData = self.usersFormatCreationData(dataForm);
$buttons.prop('disabled', true);
$buttons.prop('disabled', true);
self.usersCreate(formattedData, function(data) {
self.usersCreate({
data: formattedData,
success: function(data) {
popup.dialog('close').remove();
switch (action) {
@ -1680,10 +1684,11 @@ define(function(require) {
self.usersRender({ userId: data.user.id });
break;
}
}, function() {
},
error: function() {
$buttons.prop('disabled', false);
});
}
}
});
});
template.find('#notification_email').on('change', function() {
@ -3913,8 +3918,16 @@ define(function(require) {
});
},
usersCreate: function(data, success, error) {
/**
* Creates an user, with all its related components
* @param {Object} args
* @param {Object} args.data User formatted data
* @param {Function} args.success Success callback
* @param {Function} args.error Error callback
*/
usersCreate: function(args) {
var self = this,
data = args.data,
deviceData = _.get(data, 'user.device');
delete data.user.device;
@ -3929,12 +3942,7 @@ define(function(require) {
data.user.id = _dataUser.id;
callback(null, _dataUser);
},
error: function(parsedError) {
if (parsedError.error === '402') {
error();
return;
}
error: function() {
callback(true);
},
onChargesCancelled: function() {
@ -3956,6 +3964,16 @@ define(function(require) {
success: function(_dataVM) {
data.callflow.flow.children._.data.id = _dataVM.id;
callback(null, _dataUser);
},
error: function() {
callback(true);
},
onChargesCancelled: function() {
// VMBox won't be created, so let's remove its data
data.extra.createVmbox = false;
delete data.vmbox;
delete data.callflow.flow.children._;
callback(null, _dataUser);
}
});
},
@ -3986,30 +4004,30 @@ define(function(require) {
}
deviceData.owner_id = _dataUser.id;
self.usersAddUserDevice({
data: deviceData,
data: {
data: deviceData
},
success: function(_device) {
callback(null);
},
error: function(parsedError) {
if (parsedError.error === '402') {
error();
return;
}
error: function() {
callback(true);
},
onChargesCancelled: function() {
// Allow to complete without errors, although the device won't be created
callback(null);
}
});
}
],
function(err) {
if (err) {
error();
args.error();
return;
}
success(data);
args.success(data);
});
},
@ -4209,21 +4227,31 @@ define(function(require) {
});
},
/**
* Creates a device for a user
* @param {Object} args
* @param {Object} args.data Data to be sent by the SDK to the API
* @param {Object} args.data.data Data provided for the device to be created
* @param {Function} [args.success] Success callback
* @param {Function} [args.error] Error callback
* @param {Function} [args.onChargesCancelled] Callback to be executed when charges are
* not accepted
*/
usersAddUserDevice: function(args) {
var self = this,
dataDevice = args.data;
var self = this;
self.callApi({
resource: 'device.create',
data: {
accountId: self.accountId,
data: dataDevice
data: _.merge({
accountId: self.accountId
}, args.data),
success: function(data) {
args.hasOwnProperty('success') && args.success(data.data);
},
success: function(device) {
args.hasOwnProperty('success') && args.success(device);
error: function(parsedError) {
args.hasOwnProperty('error') && args.error(parsedError);
},
error: function(error) {
args.hasOwnProperty('error') && args.error(error);
onChargesCancelled: function() {
args.hasOwnProperty('onChargesCancelled') && args.onChargesCancelled();
}
});
},
@ -4438,10 +4466,13 @@ define(function(require) {
/**
* Creates a Voicemail Box
* @param {Object} args
* @param {Object} args.data Data to be sent by the SDK to the API
* @param {Object} args.data.data Data provided for the Voicemail Box to be created
* @param {Function} args.success Success callback
* @param {Function} args.error Error callback
* @param {Object} args.data Data to be sent by the SDK to the API
* @param {Object} args.data.data Data provided for the Voicemail Box to be
* created
* @param {Function} [args.success] Success callback
* @param {Function} [args.error] Error callback
* @param {Function} [args.onChargesCancelled] Callback to be executed when charges are
* not accepted
*/
usersCreateVMBox: function(args) {
var self = this;
@ -4456,6 +4487,9 @@ define(function(require) {
},
error: function(parsedError) {
args.hasOwnProperty('error') && args.error(parsedError);
},
onChargesCancelled: function() {
args.hasOwnProperty('onChargesCancelled') && args.onChargesCancelled();
}
});
},


Loading…
Cancel
Save