From 0ca58c658529e77fc047aaf0e632d37ffe33de82 Mon Sep 17 00:00:00 2001 From: Nicolas Widart Date: Wed, 11 Oct 2017 17:01:02 +0200 Subject: [PATCH] Creating and using a current_permission_value_for_roles helper, which defaults to -1 (deny) --- .../User/Assets/js/components/AsgardPermissions.vue | 4 +++- Modules/User/Assets/js/components/RoleForm.vue | 1 + Modules/User/Transformers/FullRoleTransformer.php | 2 +- Modules/User/helpers.php | 11 +++++++++++ public/js/app.js | 8 ++++++-- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Modules/User/Assets/js/components/AsgardPermissions.vue b/Modules/User/Assets/js/components/AsgardPermissions.vue index 439f9b04d..f50fa51e2 100644 --- a/Modules/User/Assets/js/components/AsgardPermissions.vue +++ b/Modules/User/Assets/js/components/AsgardPermissions.vue @@ -14,6 +14,7 @@ {{ trans('roles.allow all') }} {{ trans('roles.inherit all') }} @@ -40,7 +41,7 @@
{{ trans('roles.allow') }} - {{ trans('roles.inherit') }} + {{ trans('roles.inherit') }} {{ trans('roles.deny') }}
@@ -59,6 +60,7 @@ export default { mixins: [StringHelpers], props: { + isRole: { type: Boolean }, currentPermissions: { default: null }, }, data() { diff --git a/Modules/User/Assets/js/components/RoleForm.vue b/Modules/User/Assets/js/components/RoleForm.vue index 04594e056..8e2f85425 100644 --- a/Modules/User/Assets/js/components/RoleForm.vue +++ b/Modules/User/Assets/js/components/RoleForm.vue @@ -44,6 +44,7 @@ diff --git a/Modules/User/Transformers/FullRoleTransformer.php b/Modules/User/Transformers/FullRoleTransformer.php index 7cbe924b5..55c22aaa7 100644 --- a/Modules/User/Transformers/FullRoleTransformer.php +++ b/Modules/User/Transformers/FullRoleTransformer.php @@ -38,7 +38,7 @@ private function buildPermissionList(array $permissionsConfig) : array foreach ($permissionsConfig as $mainKey => $subPermissions) { foreach ($subPermissions as $key => $permissionGroup) { foreach ($permissionGroup as $lastKey => $description) { - $list[strtolower($key) . '.' . $lastKey] = current_permission_value($this, $key, $lastKey); + $list[strtolower($key) . '.' . $lastKey] = current_permission_value_for_roles($this, $key, $lastKey); } } } diff --git a/Modules/User/helpers.php b/Modules/User/helpers.php index c51d6bf82..b77a9a50e 100644 --- a/Modules/User/helpers.php +++ b/Modules/User/helpers.php @@ -14,3 +14,14 @@ function current_permission_value($model, $permissionTitle, $permissionAction) return 0; } } + +if (function_exists('current_permission_value_for_roles') === false) { + function current_permission_value_for_roles($model, $permissionTitle, $permissionAction) + { + $value = array_get($model->permissions, "$permissionTitle.$permissionAction"); + if ($value === true) { + return 1; + } + return -1; + } +} diff --git a/public/js/app.js b/public/js/app.js index 16ca14e37..3a9f7b796 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -106410,6 +106410,7 @@ exports.default = { // // // +// /***/ }), /* 508 */ @@ -106580,10 +106581,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de // // // +// exports.default = { mixins: [_StringHelpers2.default], props: { + isRole: { type: Boolean }, currentPermissions: { default: null } }, data: function data() { @@ -106690,7 +106693,7 @@ var render = function() { _c( "el-button", { - attrs: { type: "text" }, + attrs: { type: "text", disabled: _vm.isRole }, on: { click: function($event) { _vm.changeState( @@ -106815,7 +106818,7 @@ var render = function() { _c( "el-radio-button", { - attrs: { label: 0 }, + attrs: { label: 0, disabled: _vm.isRole }, on: { click: _vm.triggerEvent } }, [_vm._v(_vm._s(_vm.trans("roles.inherit")))] @@ -107057,6 +107060,7 @@ var render = function() { [ _c("asgard-permissions", { attrs: { + "is-role": "", "current-permissions": _vm.role.permissions }, model: {