Browse Source

UI-3135: Fix user type assignment on user create/update (#79)

* Only allow user type update if different from original

* Clean up user type assignment on user update

* Clean-up user type assignment on user creation
4.3
Joris Tirado 7 years ago
committed by GitHub
parent
commit
0b7ee38cb9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 20 deletions
  1. +43
    -19
      submodules/users/users.js
  2. +1
    -1
      submodules/users/views/licensed-roles.html

+ 43
- 19
submodules/users/users.js View File

@ -1181,15 +1181,27 @@ define(function(require) {
$(this).blur();
});
template.on('change', '#licensed_role', function(event) {
event.preventDefault();
var planId = $(this).val();
if (!currentUser.hasOwnProperty('service')
|| planId !== Object.keys(currentUser.service.plans)[0]) {
template
.find('.save-user-role')
.prop('disabled', false);
} else {
template
.find('.save-user-role')
.prop('disabled', true);
}
});
/* Events for License Roles */
template.on('click', '.save-user-role', function() {
var planId = template.find('#licensed_role').val();
/*currentUser.service = currentUser.service || {};
currentUser.service.plans = {};
currentUser.service.plans[planId] = {
account_id: monster.config.resellerId,
overrides: {}
};*/
currentUser.extra = currentUser.extra || {};
currentUser.extra.licensedRole = planId;
@ -3060,15 +3072,20 @@ define(function(require) {
}
}
/**
* When updating the user type, override existing one with new
* user type selected.
* Once set the `service` prop should not be removed by the UI.
*
*/
if (userData.extra.hasOwnProperty('licensedRole')) {
userData.service = userData.service || {};
userData.service.plans = {};
userData.service = {
plans: {}
};
userData.service.plans[userData.extra.licensedRole] = {
account_id: monster.config.resellerId,
overrides: {}
};
} else {
delete userData.service;
}
}
@ -3534,6 +3551,9 @@ define(function(require) {
callerIdName = fullName.substring(0, 15),
formattedData = {
user: $.extend(true, {}, {
service: {
plans: {}
},
caller_id: {
internal: {
name: callerIdName,
@ -3572,15 +3592,19 @@ define(function(require) {
extra: data.extra
};
if (formattedData.user.extra) {
if (formattedData.user.extra.hasOwnProperty('licensedRole') && formattedData.user.extra.licensedRole !== 'none') {
formattedData.user.service = formattedData.user.service || {};
formattedData.user.service.plans = {};
formattedData.user.service.plans[formattedData.user.extra.licensedRole] = {
account_id: monster.config.resellerId,
overrides: {}
};
}
/**
* Only set the `service` property if a user type (e.g. service plan)
* is selected
*/
if (formattedData.user.hasOwnProperty('extra')
&& formattedData.user.extra.hasOwnProperty('licensedRole')
&& formattedData.user.extra.licensedRole !== 'none') {
formattedData.user.service.plans[formattedData.user.extra.licensedRole] = {
accountId: monster.config.resellerId,
overrides: {}
};
} else {
delete formattedData.user.service;
}
delete formattedData.user.extra;


+ 1
- 1
submodules/users/views/licensed-roles.html View File

@ -18,7 +18,7 @@
<div class="actions">
<div class="pull-right">
<a class="cancel-link monster-link blue" href="javascript:void(0);">{{ i18n.cancel }}</a>
<button type="button" class="monster-button monster-button-success save-user-role">{{ i18n.saveChanges }}</button>
<button type="button" class="monster-button monster-button-success save-user-role" disabled>{{ i18n.saveChanges }}</button>
</div>
</div>
</div>

Loading…
Cancel
Save