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 UserRevokeAbilityCommand extends Command |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* The name and signature of the console command. |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $signature = 'fort:user:revokeability |
29
|
|
|
{user? : The user 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 user.'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Execute the console command. |
41
|
|
|
* |
42
|
|
|
* @return void |
43
|
|
|
*/ |
44
|
|
|
public function handle() |
45
|
|
|
{ |
46
|
|
|
$userField = $this->argument('user') ?: $this->ask(Lang::get('rinvex.fort::artisan.user.identifier')); |
47
|
|
|
|
48
|
|
|
if (intval($userField)) { |
49
|
|
|
$user = $this->laravel['rinvex.fort.user']->find($userField); |
50
|
|
|
} else if (filter_var($userField, FILTER_VALIDATE_EMAIL)) { |
51
|
|
|
$user = $this->laravel['rinvex.fort.user']->findWhere(['email' => $userField])->first(); |
52
|
|
|
} else { |
53
|
|
|
$user = $this->laravel['rinvex.fort.user']->findWhere(['username' => $userField])->first(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
if (! $user) { |
57
|
|
|
return $this->error(Lang::get('rinvex.fort::artisan.user.invalid', ['field' => $userField])); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
$abilityField = $this->argument('ability') ?: $this->anticipate(Lang::get('rinvex.fort::artisan.user.ability'), $this->laravel['rinvex.fort.ability']->findAll()->lists('slug', 'id')->toArray()); |
|
|
|
|
62
|
|
|
|
63
|
|
|
if (intval($abilityField)) { |
64
|
|
|
$ability = $this->laravel['rinvex.fort.ability']->find($abilityField); |
65
|
|
|
} else { |
66
|
|
|
$ability = $this->laravel['rinvex.fort.ability']->findWhere(['slug' => $abilityField])->first(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if (! $ability) { |
70
|
|
|
return $this->error(Lang::get('rinvex.fort::artisan.ability.invalid', ['field' => $abilityField])); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
// Revoke user ability to.. |
74
|
|
|
$user->revokeAbilityTo($ability); |
75
|
|
|
|
76
|
|
|
$this->info(Lang::get('rinvex.fort::artisan.user.abilityrevoked', ['user' => $user->id, 'ability' => $ability->id])); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
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.