update permissions for settings in json
This commit is contained in:
@ -59,7 +59,6 @@ class Roles extends Seeder
|
|||||||
'modules-tiles' => 'r',
|
'modules-tiles' => 'r',
|
||||||
'notifications' => 'r,u',
|
'notifications' => 'r,u',
|
||||||
'offline-payments-settings' => 'r,u,d',
|
'offline-payments-settings' => 'r,u,d',
|
||||||
'paypal-standard-settings' => 'r,u',
|
|
||||||
'reports-expense-summary' => 'r',
|
'reports-expense-summary' => 'r',
|
||||||
'reports-income-summary' => 'r',
|
'reports-income-summary' => 'r',
|
||||||
'reports-income-expense-summary' => 'r',
|
'reports-income-expense-summary' => 'r',
|
||||||
@ -115,7 +114,6 @@ class Roles extends Seeder
|
|||||||
'install-updates' => 'r,u',
|
'install-updates' => 'r,u',
|
||||||
'notifications' => 'r,u',
|
'notifications' => 'r,u',
|
||||||
'offline-payments-settings' => 'r,u,d',
|
'offline-payments-settings' => 'r,u,d',
|
||||||
'paypal-standard-settings' => 'r,u',
|
|
||||||
'reports-expense-summary' => 'r',
|
'reports-expense-summary' => 'r',
|
||||||
'reports-income-summary' => 'r',
|
'reports-income-summary' => 'r',
|
||||||
'reports-income-expense-summary' => 'r',
|
'reports-income-expense-summary' => 'r',
|
||||||
|
@ -7,6 +7,8 @@ use App\Models\Module\ModuleHistory;
|
|||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use App\Models\Auth\Permission;
|
||||||
|
use App\Models\Auth\Role;
|
||||||
|
|
||||||
class InstallCommand extends Command
|
class InstallCommand extends Command
|
||||||
{
|
{
|
||||||
@ -54,6 +56,10 @@ class InstallCommand extends Command
|
|||||||
'description' => trans('modules.installed', ['module' => $alias]),
|
'description' => trans('modules.installed', ['module' => $alias]),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if (!empty($module->get('settings'))) {
|
||||||
|
$this->updatePermissions($module);
|
||||||
|
}
|
||||||
|
|
||||||
$this->call('cache:clear');
|
$this->call('cache:clear');
|
||||||
|
|
||||||
// Update database
|
// Update database
|
||||||
@ -82,4 +88,32 @@ class InstallCommand extends Command
|
|||||||
array('company_id', InputArgument::REQUIRED, 'Company ID.'),
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user