Skip to content

Commit

Permalink
added migration for user_role and updated command to add use sets fro…
Browse files Browse the repository at this point in the history
…m configs
  • Loading branch information
Oleksandr-Moik committed Jan 27, 2022
1 parent f68610e commit e54884c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 20 additions & 0 deletions database/migrations/2020_05_27_110200_role_user_pivot_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
public function up()
{
Schema::create('role_user', function (Blueprint $table) {
$table->foreignId('user_id')->constrained()->cascadeOnDelete()->cascadeOnUpdate();
$table->foreignId('role_id')->constrained()->cascadeOnDelete()->restrictOnDelete();
});
}

public function down()
{
Schema::dropIfExists('role_user');
}
};
14 changes: 10 additions & 4 deletions src/Commands/CreatePermissionsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ 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);

if ($this->option('no-prefix')) {
$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 {
Expand All @@ -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();
Expand All @@ -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)'),
];
}
}

0 comments on commit e54884c

Please sign in to comment.