Skip to content

Commit

Permalink
Creating and using a current_permission_value_for_roles helper, which…
Browse files Browse the repository at this point in the history
… defaults to -1 (deny)
  • Loading branch information
nWidart committed Oct 11, 2017
1 parent d22a026 commit 0ca58c6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Modules/User/Assets/js/components/AsgardPermissions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
{{ trans('roles.allow all') }}
</el-button>
<el-button type="text"
:disabled="isRole"
@click="changeState(subPermissionTitle, permissionActions, 0)">
{{ trans('roles.inherit all') }}
</el-button>
Expand All @@ -40,7 +41,7 @@
<div class="col-md-9">
<el-radio-group v-model="permissions[`${subPermissionTitle}.${permissionAction}`]">
<el-radio-button :label="1" @click="triggerEvent">{{ trans('roles.allow') }}</el-radio-button>
<el-radio-button :label="0" @click="triggerEvent">{{ trans('roles.inherit') }}</el-radio-button>
<el-radio-button :label="0" @click="triggerEvent" :disabled="isRole">{{ trans('roles.inherit') }}</el-radio-button>
<el-radio-button :label="-1" @click="triggerEvent">{{ trans('roles.deny') }}</el-radio-button>
</el-radio-group>
</div>
Expand All @@ -59,6 +60,7 @@
export default {
mixins: [StringHelpers],
props: {
isRole: { type: Boolean },
currentPermissions: { default: null },
},
data() {
Expand Down
1 change: 1 addition & 0 deletions Modules/User/Assets/js/components/RoleForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
</el-tab-pane>
<el-tab-pane :label="trans('roles.tabs.permissions')">
<asgard-permissions v-model="role.permissions"
is-role
:current-permissions="role.permissions"></asgard-permissions>
</el-tab-pane>
<el-tab-pane :label="trans('users.title.users')">
Expand Down
2 changes: 1 addition & 1 deletion Modules/User/Transformers/FullRoleTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions Modules/User/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
8 changes: 6 additions & 2 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -106410,6 +106410,7 @@ exports.default = {
//
//
//
//

/***/ }),
/* 508 */
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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")))]
Expand Down Expand Up @@ -107057,6 +107060,7 @@ var render = function() {
[
_c("asgard-permissions", {
attrs: {
"is-role": "",
"current-permissions": _vm.role.permissions
},
model: {
Expand Down

0 comments on commit 0ca58c6

Please sign in to comment.