From 48abb38904a696bc3db3f3560beb4efe9f5cd515 Mon Sep 17 00:00:00 2001 From: John Kleinschmidt Date: Fri, 9 Dec 2016 15:07:53 -0500 Subject: [PATCH] Fix editing custom roles and using custom roles 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. --- app/admin/roles/controller.js | 40 +++++++++++++++++-------------- app/locales/en/translations.js | 2 +- app/locales/es-CO/translations.js | 2 +- app/locales/es/translations.js | 2 +- app/locales/fr/translations.js | 2 +- app/locales/pt-BR/translations.js | 2 +- app/mixins/navigation.js | 2 +- app/mixins/user-session.js | 4 ++-- 8 files changed, 30 insertions(+), 26 deletions(-) diff --git a/app/admin/roles/controller.js b/app/admin/roles/controller.js index 40a5f30c8e..5f5464a08b 100644 --- a/app/admin/roles/controller.js +++ b/app/admin/roles/controller.js @@ -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'); }), @@ -18,7 +18,7 @@ export default AbstractEditController.extend(UserRoles, UserSession, { 'admin', 'loadDb', 'updateConfig', - 'userRoles' + 'defineUserRoles' ] }, { name: 'appointments', @@ -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); } }, diff --git a/app/locales/en/translations.js b/app/locales/en/translations.js index d70cde059d..38c6bd8d29 100644 --- a/app/locales/en/translations.js +++ b/app/locales/en/translations.js @@ -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.' diff --git a/app/locales/es-CO/translations.js b/app/locales/es-CO/translations.js index 48fb130213..c96be2965b 100644 --- a/app/locales/es-CO/translations.js +++ b/app/locales/es-CO/translations.js @@ -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.' diff --git a/app/locales/es/translations.js b/app/locales/es/translations.js index e95cd9a4af..21ae20d6b1 100644 --- a/app/locales/es/translations.js +++ b/app/locales/es/translations.js @@ -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.' diff --git a/app/locales/fr/translations.js b/app/locales/fr/translations.js index 7e3256cd96..559ad29cbc 100644 --- a/app/locales/fr/translations.js +++ b/app/locales/fr/translations.js @@ -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é.' diff --git a/app/locales/pt-BR/translations.js b/app/locales/pt-BR/translations.js index 7099744a04..94be6033a3 100755 --- a/app/locales/pt-BR/translations.js +++ b/app/locales/pt-BR/translations.js @@ -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.' diff --git a/app/mixins/navigation.js b/app/mixins/navigation.js index 63f4ccc89b..d74d9ebe3b 100644 --- a/app/mixins/navigation.js +++ b/app/mixins/navigation.js @@ -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', diff --git a/app/mixins/user-session.js b/app/mixins/user-session.js index e7ae580126..de0fd46c62 100644 --- a/app/mixins/user-session.js +++ b/app/mixins/user-session.js @@ -446,7 +446,7 @@ export default Ember.Mixin.create({ 'Patient Administration', 'System Administrator' ], - 'user_roles': [ + 'define_user_roles': [ 'System Administrator' ] }, @@ -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;