From e54884c4260d1ba48c5ff2db4287a614af904467 Mon Sep 17 00:00:00 2001 From: Oleksand-Moik Date: Thu, 27 Jan 2022 05:31:38 +0200 Subject: [PATCH] added migration for user_role and updated command to add use sets from configs --- composer.json | 2 +- ...020_05_27_110200_role_user_pivot_table.php | 20 +++++++++++++++++++ src/Commands/CreatePermissionsCommand.php | 14 +++++++++---- 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 database/migrations/2020_05_27_110200_role_user_pivot_table.php diff --git a/composer.json b/composer.json index 3855391..ca00e9a 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "control access to models using groups and permissions", "license": "MIT", "type": "library", - "version": "2.1.2", + "version": "2.2.0", "authors": [ { "name": "Oleksandr-Moik", diff --git a/database/migrations/2020_05_27_110200_role_user_pivot_table.php b/database/migrations/2020_05_27_110200_role_user_pivot_table.php new file mode 100644 index 0000000..ac7f331 --- /dev/null +++ b/database/migrations/2020_05_27_110200_role_user_pivot_table.php @@ -0,0 +1,20 @@ +foreignId('user_id')->constrained()->cascadeOnDelete()->cascadeOnUpdate(); + $table->foreignId('role_id')->constrained()->cascadeOnDelete()->restrictOnDelete(); + }); + } + + public function down() + { + Schema::dropIfExists('role_user'); + } +}; diff --git a/src/Commands/CreatePermissionsCommand.php b/src/Commands/CreatePermissionsCommand.php index 3b43b27..f80f918 100644 --- a/src/Commands/CreatePermissionsCommand.php +++ b/src/Commands/CreatePermissionsCommand.php @@ -16,7 +16,7 @@ public function handle(): int { $this->withProgressBar($this->argument('module'), function ($module) { $this->newLine(); - $this->info('Module: '. $module); + $this->info('Module: ' . $module); $pm_builder = PermissionRelation::touch($module); @@ -24,8 +24,7 @@ public function handle(): int $pm_builder->disablePrefix(); } - if ($custom = $this->option('custom')) { - $custom = array_filter($custom); + if ($custom = array_filter($this->option('custom-set'))) { if (empty($custom)) { $pm_builder->addCustomSet(); } else { @@ -40,6 +39,12 @@ public function handle(): int } else { $pm_builder->addResourceSet(); } + + if ($sets = array_filter($this->option('sets'))) { + foreach ($sets as $set) { + $pm_builder->addSet($set); + } + } }); $this->newLine(); @@ -58,9 +63,10 @@ protected function getOptions(): array { return [ new InputOption('no-prefix', null, InputOption::VALUE_NONE, 'Create permissions without touching module name.'), - new InputOption('custom', 'c', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'List of custom attributes.'), + new InputOption('custom-set', 'c', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'List of custom attributes.'), new InputOption('except', 'e', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Skip this permissions.'), new InputOption('only', 'o', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Create only this.'), + new InputOption('set', 's', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'List of set names (from config file)'), ]; } }