|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* NOTICE OF LICENSE |
|
5
|
|
|
* |
|
6
|
|
|
* Part of the Rinvex Fort Package. |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to The MIT License (MIT) |
|
9
|
|
|
* that is bundled with this package in the LICENSE file. |
|
10
|
|
|
* |
|
11
|
|
|
* Package: Rinvex Fort Package |
|
12
|
|
|
* License: The MIT License (MIT) |
|
13
|
|
|
* Link: https://rinvex.com |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace Rinvex\Fort\Console\Commands; |
|
17
|
|
|
|
|
18
|
|
|
use Illuminate\Console\Command; |
|
19
|
|
|
use Illuminate\Support\Facades\Lang; |
|
20
|
|
|
|
|
21
|
|
|
class RoleRevokeAbilityCommand extends Command |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* The name and signature of the console command. |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $signature = 'fort:role:revokeability |
|
29
|
|
|
{role? : The role identifier} |
|
30
|
|
|
{ability? : The ability identifier}'; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* The console command description. |
|
34
|
|
|
* |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $description = 'Revoke a ability from a role.'; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Execute the console command. |
|
41
|
|
|
* |
|
42
|
|
|
* @return void |
|
43
|
|
|
*/ |
|
44
|
|
|
public function handle() |
|
45
|
|
|
{ |
|
46
|
|
|
$roleField = $this->argument('role') ?: $this->ask(Lang::get('rinvex.fort::artisan.role.identifier')); |
|
47
|
|
|
|
|
48
|
|
|
if (intval($roleField)) { |
|
49
|
|
|
$role = $this->laravel['rinvex.fort.role']->find($roleField); |
|
50
|
|
|
} else { |
|
51
|
|
|
$role = $this->laravel['rinvex.fort.role']->findWhere(['slug' => $roleField])->first(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
if (! $role) { |
|
55
|
|
|
return $this->error(Lang::get('rinvex.fort::artisan.role.invalid', ['field' => $roleField])); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
$abilityField = $this->argument('ability') ?: $this->anticipate(Lang::get('rinvex.fort::artisan.role.ability'), $this->laravel['rinvex.fort.ability']->findAll()->lists('slug', 'id')->toArray()); |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
if (intval($abilityField)) { |
|
62
|
|
|
$ability = $this->laravel['rinvex.fort.ability']->find($abilityField); |
|
63
|
|
|
} else { |
|
64
|
|
|
$ability = $this->laravel['rinvex.fort.ability']->findWhere(['slug' => $abilityField])->first(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
if (! $ability) { |
|
68
|
|
|
return $this->error(Lang::get('rinvex.fort::artisan.ability.invalid', ['field' => $abilityField])); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
// Revoke role ability to.. |
|
72
|
|
|
$role->revokeAbilityTo($ability); |
|
73
|
|
|
|
|
74
|
|
|
$this->info(Lang::get('rinvex.fort::artisan.role.abilityrevoked', ['role' => $role->id, 'ability' => $ability->id])); |
|
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.