Skip to content

Commit e54884c

Browse files
added migration for user_role and updated command to add use sets from configs
1 parent f68610e commit e54884c

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "control access to models using groups and permissions",
44
"license": "MIT",
55
"type": "library",
6-
"version": "2.1.2",
6+
"version": "2.2.0",
77
"authors": [
88
{
99
"name": "Oleksandr-Moik",
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration {
8+
public function up()
9+
{
10+
Schema::create('role_user', function (Blueprint $table) {
11+
$table->foreignId('user_id')->constrained()->cascadeOnDelete()->cascadeOnUpdate();
12+
$table->foreignId('role_id')->constrained()->cascadeOnDelete()->restrictOnDelete();
13+
});
14+
}
15+
16+
public function down()
17+
{
18+
Schema::dropIfExists('role_user');
19+
}
20+
};

src/Commands/CreatePermissionsCommand.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@ public function handle(): int
1616
{
1717
$this->withProgressBar($this->argument('module'), function ($module) {
1818
$this->newLine();
19-
$this->info('Module: '. $module);
19+
$this->info('Module: ' . $module);
2020

2121
$pm_builder = PermissionRelation::touch($module);
2222

2323
if ($this->option('no-prefix')) {
2424
$pm_builder->disablePrefix();
2525
}
2626

27-
if ($custom = $this->option('custom')) {
28-
$custom = array_filter($custom);
27+
if ($custom = array_filter($this->option('custom-set'))) {
2928
if (empty($custom)) {
3029
$pm_builder->addCustomSet();
3130
} else {
@@ -40,6 +39,12 @@ public function handle(): int
4039
} else {
4140
$pm_builder->addResourceSet();
4241
}
42+
43+
if ($sets = array_filter($this->option('sets'))) {
44+
foreach ($sets as $set) {
45+
$pm_builder->addSet($set);
46+
}
47+
}
4348
});
4449

4550
$this->newLine();
@@ -58,9 +63,10 @@ protected function getOptions(): array
5863
{
5964
return [
6065
new InputOption('no-prefix', null, InputOption::VALUE_NONE, 'Create permissions without touching module name.'),
61-
new InputOption('custom', 'c', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'List of custom attributes.'),
66+
new InputOption('custom-set', 'c', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'List of custom attributes.'),
6267
new InputOption('except', 'e', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Skip this permissions.'),
6368
new InputOption('only', 'o', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Create only this.'),
69+
new InputOption('set', 's', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'List of set names (from config file)'),
6470
];
6571
}
6672
}

0 commit comments

Comments
 (0)