From 137a2538012fab9f0dfbb83a999e8d47718067ab Mon Sep 17 00:00:00 2001 From: denisdulici Date: Mon, 6 Jan 2020 17:52:46 +0300 Subject: [PATCH] update permissions for settings in json --- database/seeds/Roles.php | 2 -- .../module/Commands/InstallCommand.php | 34 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/database/seeds/Roles.php b/database/seeds/Roles.php index 8453d8419..cd42fa2bf 100644 --- a/database/seeds/Roles.php +++ b/database/seeds/Roles.php @@ -59,7 +59,6 @@ class Roles extends Seeder 'modules-tiles' => 'r', 'notifications' => 'r,u', 'offline-payments-settings' => 'r,u,d', - 'paypal-standard-settings' => 'r,u', 'reports-expense-summary' => 'r', 'reports-income-summary' => 'r', 'reports-income-expense-summary' => 'r', @@ -115,7 +114,6 @@ class Roles extends Seeder 'install-updates' => 'r,u', 'notifications' => 'r,u', 'offline-payments-settings' => 'r,u,d', - 'paypal-standard-settings' => 'r,u', 'reports-expense-summary' => 'r', 'reports-income-summary' => 'r', 'reports-income-expense-summary' => 'r', diff --git a/overrides/akaunting/module/Commands/InstallCommand.php b/overrides/akaunting/module/Commands/InstallCommand.php index 67603c32d..579a2527d 100644 --- a/overrides/akaunting/module/Commands/InstallCommand.php +++ b/overrides/akaunting/module/Commands/InstallCommand.php @@ -7,6 +7,8 @@ use App\Models\Module\ModuleHistory; use Illuminate\Console\Command; use Illuminate\Support\Str; use Symfony\Component\Console\Input\InputArgument; +use App\Models\Auth\Permission; +use App\Models\Auth\Role; class InstallCommand extends Command { @@ -54,6 +56,10 @@ class InstallCommand extends Command 'description' => trans('modules.installed', ['module' => $alias]), ]); + if (!empty($module->get('settings'))) { + $this->updatePermissions($module); + } + $this->call('cache:clear'); // Update database @@ -82,4 +88,32 @@ class InstallCommand extends Command array('company_id', InputArgument::REQUIRED, 'Company ID.'), ); } + + protected function updatePermissions($module) + { + $permissions = []; + + $permissions[] = Permission::firstOrCreate([ + 'name' => 'read-' . $module->getAlias() . '-settings', + 'display_name' => 'Read ' . $module->getName() . ' Settings', + 'description' => 'Read ' . $module->getName() . ' Settings', + ]); + + $permissions[] = Permission::firstOrCreate([ + 'name' => 'update-' . $module->getAlias() . '-settings', + 'display_name' => 'Update ' . $module->getName() . ' Settings', + 'description' => 'Update ' . $module->getName() . ' Settings', + ]); + + // Attach permission to roles + $roles = Role::all()->filter(function ($r) { + return $r->hasPermission('read-admin-panel'); + }); + + foreach ($roles as $role) { + foreach ($permissions as $permission) { + $role->attachPermission($permission); + } + } + } }