Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Fix editing custom roles and using custom roles
Browse files Browse the repository at this point in the history
Fixes #845
Custom roles were not properly applying and the admin screen to modify
user roles was breaking any time you create/edit a user role.
  • Loading branch information
jkleinsc committed Dec 9, 2016
1 parent 57eed6c commit 48abb38
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 26 deletions.
40 changes: 22 additions & 18 deletions app/admin/roles/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default AbstractEditController.extend(UserRoles, UserSession, {
currentRole: '',
disabledAction: false,
hideCancelButton: true,
updateCapability: 'user_roles',
updateCapability: 'define_user_roles',
filteredRoles: Ember.computed.filter('userRoles', function(userRole) {
return (userRole.name !== 'System Administrator');
}),
Expand All @@ -18,7 +18,7 @@ export default AbstractEditController.extend(UserRoles, UserSession, {
'admin',
'loadDb',
'updateConfig',
'userRoles'
'defineUserRoles'
]
}, {
name: 'appointments',
Expand Down Expand Up @@ -122,27 +122,31 @@ export default AbstractEditController.extend(UserRoles, UserSession, {
let roleToUpdate = this.get('model').findBy('id', role.dasherize());
this.set('currentRole', role);
this.set('roleToUpdate', roleToUpdate);
if (roleToUpdate) {
let capabilities = roleToUpdate.get('capabilities');
this.get('availableCapabilities').forEach((section) => {
section.capabilities.forEach((capability) => {
if (capabilities.includes(capability)) {
try {
if (roleToUpdate) {
let capabilities = roleToUpdate.get('capabilities');
this.get('availableCapabilities').forEach((section) => {
section.capabilities.forEach((capability) => {
if (capabilities.includes(capability)) {
this.set(capability, true);
} else {
this.set(capability, false);
}
});
});
} else {
let defaultCapabilities = this.get('defaultCapabilities');
Object.keys(defaultCapabilities).forEach((capability) => {
let capabilityRoles = defaultCapabilities[capability];
if (capabilityRoles.includes(role)) {
this.set(capability, true);
} else {
this.set(capability, false);
}
});
});
} else {
let defaultCapabilities = this.get('defaultCapabilities');
Object.keys(defaultCapabilities).forEach((capability) => {
let capabilityRoles = defaultCapabilities[capability];
if (capabilityRoles.includes(role)) {
this.set(capability, true);
} else {
this.set(capability, false);
}
});
}
} catch(ex) {
console.log('ex setting role:', ex);
}
},

Expand Down
2 changes: 1 addition & 1 deletion app/locales/en/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export default {
adjustInventoryLocation: 'Adjust Inventory Location',
deleteInventoryItem: 'Delete Inventory Item',
fulfillInventory: 'Fulfill Inventory',
userRoles: 'User Roles'
defineUserRoles: 'Define User Roles'
},
messages: {
roleSaved: 'The {{roleName}} role has been saved.'
Expand Down
2 changes: 1 addition & 1 deletion app/locales/es-CO/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export default {
deleteInventoryItem: 'Eliminar elemento del inventario',
deleteInventoryPurchase: 'Eliminar compra del inventario',
fulfillInventory: 'Cumplimiento de inventario',
userRoles: 'Roles de usuario'
defineUserRoles: 'Roles de usuario'
},
messages: {
roleSaved: 'El {{roleName}} rol ha sido salvado.'
Expand Down
2 changes: 1 addition & 1 deletion app/locales/es/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export default {
deleteInventoryItem: 'Eliminar elemento del inventario',
deleteInventoryPurchase: 'Eliminar compra del inventario',
fulfillInventory: 'Cumplimiento de inventario',
userRoles: 'Roles de usuario'
defineUserRoles: 'Roles de usuario'
},
messages: {
roleSaved: 'El {{roleName}} rol ha sido salvado.'
Expand Down
2 changes: 1 addition & 1 deletion app/locales/fr/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export default {
deleteInventoryItem: 'Supprimer un article d\'inventaire',
deleteInventoryPurchase: 'Supprimer un achat d\'inventaire',
fulfillInventory: 'Traiter l\'inventaire',
userRoles: 'Rôles d\'utilisateur'
defineUserRoles: 'Rôles d\'utilisateur'
},
messages: {
roleSaved: 'Le rôle {{roleName}} a été enregistré.'
Expand Down
2 changes: 1 addition & 1 deletion app/locales/pt-BR/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export default {
adjustInventoryLocation: 'Ajustar Localização de Inventário',
deleteInventoryItem: 'Excluir Item de Inventário',
fulfillInventory: 'Preencher Inventário',
userRoles: 'Perfis de Usuários'
defineUserRoles: 'Perfis de Usuários'
},
messages: {
roleSaved: 'O perfil {{roleName}} foi salvo.'
Expand Down
2 changes: 1 addition & 1 deletion app/mixins/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export default Ember.Mixin.create({
title: 'User Roles',
iconClass: 'octicon-chevron-right',
route: 'admin.roles',
capability: 'user_roles'
capability: 'define_user_roles'
},
{
title: 'Workflow',
Expand Down
4 changes: 2 additions & 2 deletions app/mixins/user-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ export default Ember.Mixin.create({
'Patient Administration',
'System Administrator'
],
'user_roles': [
'define_user_roles': [
'System Administrator'
]
},
Expand All @@ -469,7 +469,7 @@ export default Ember.Mixin.create({
return supportedRoles.includes(sessionVars.role);
}
} else {
return userCaps.includes(capability);
return userCaps.includes(capability.camelize()); // User defined capabilities are camelcased.
}
}
return false;
Expand Down

0 comments on commit 48abb38

Please sign in to comment.