Skip to content

Commit

Permalink
UI-3135: Fix user type assignment on user create/update (#79)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
joristirado authored Aug 10, 2018
1 parent 4a0f3b8 commit 0b7ee38
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 20 deletions.
62 changes: 43 additions & 19 deletions submodules/users/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -3534,6 +3551,9 @@ define(function(require) {
callerIdName = fullName.substring(0, 15),
formattedData = {
user: $.extend(true, {}, {
service: {
plans: {}
},
caller_id: {
internal: {
name: callerIdName,
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion submodules/users/views/licensed-roles.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit 0b7ee38

Please sign in to comment.