@@ -6,26 +6,26 @@ |
||
6 | 6 | |
7 | 7 | class UpdateRole extends FormRequest |
8 | 8 | { |
9 | - /** |
|
10 | - * Determine if the user is authorized to make this request. |
|
11 | - * |
|
12 | - * @return bool |
|
13 | - */ |
|
14 | - public function authorize() |
|
15 | - { |
|
16 | - return true; |
|
17 | - } |
|
9 | + /** |
|
10 | + * Determine if the user is authorized to make this request. |
|
11 | + * |
|
12 | + * @return bool |
|
13 | + */ |
|
14 | + public function authorize() |
|
15 | + { |
|
16 | + return true; |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * Get the validation rules that apply to the request. |
|
21 | - * |
|
22 | - * @return array |
|
23 | - */ |
|
24 | - public function rules() |
|
25 | - { |
|
26 | - return [ |
|
27 | - 'id' => 'required|exists:roles,id', |
|
28 | - 'name' => 'required|string|max:100|unique:roles,name,'.$this->get('id') |
|
29 | - ]; |
|
30 | - } |
|
19 | + /** |
|
20 | + * Get the validation rules that apply to the request. |
|
21 | + * |
|
22 | + * @return array |
|
23 | + */ |
|
24 | + public function rules() |
|
25 | + { |
|
26 | + return [ |
|
27 | + 'id' => 'required|exists:roles,id', |
|
28 | + 'name' => 'required|string|max:100|unique:roles,name,'.$this->get('id') |
|
29 | + ]; |
|
30 | + } |
|
31 | 31 | } |
@@ -6,25 +6,25 @@ |
||
6 | 6 | |
7 | 7 | class InsertRole extends FormRequest |
8 | 8 | { |
9 | - /** |
|
10 | - * Determine if the user is authorized to make this request. |
|
11 | - * |
|
12 | - * @return bool |
|
13 | - */ |
|
14 | - public function authorize() |
|
15 | - { |
|
16 | - return true; |
|
17 | - } |
|
9 | + /** |
|
10 | + * Determine if the user is authorized to make this request. |
|
11 | + * |
|
12 | + * @return bool |
|
13 | + */ |
|
14 | + public function authorize() |
|
15 | + { |
|
16 | + return true; |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * Get the validation rules that apply to the request. |
|
21 | - * |
|
22 | - * @return array |
|
23 | - */ |
|
24 | - public function rules() |
|
25 | - { |
|
26 | - return [ |
|
27 | - 'name' => 'required|string|max:100|unique:roles,name,'.$this->get('id') |
|
28 | - ]; |
|
29 | - } |
|
19 | + /** |
|
20 | + * Get the validation rules that apply to the request. |
|
21 | + * |
|
22 | + * @return array |
|
23 | + */ |
|
24 | + public function rules() |
|
25 | + { |
|
26 | + return [ |
|
27 | + 'name' => 'required|string|max:100|unique:roles,name,'.$this->get('id') |
|
28 | + ]; |
|
29 | + } |
|
30 | 30 | } |
@@ -8,25 +8,25 @@ |
||
8 | 8 | |
9 | 9 | class Role extends JsonResource |
10 | 10 | { |
11 | - /** |
|
12 | - * Transform the resource into an array. |
|
13 | - * |
|
14 | - * @param Request $request |
|
15 | - * @return array |
|
16 | - */ |
|
17 | - public function toArray($request) |
|
18 | - { |
|
19 | - if (! $this->resource) { |
|
20 | - return []; |
|
21 | - } |
|
11 | + /** |
|
12 | + * Transform the resource into an array. |
|
13 | + * |
|
14 | + * @param Request $request |
|
15 | + * @return array |
|
16 | + */ |
|
17 | + public function toArray($request) |
|
18 | + { |
|
19 | + if (! $this->resource) { |
|
20 | + return []; |
|
21 | + } |
|
22 | 22 | |
23 | - return [ |
|
24 | - 'id' => $this->id, |
|
25 | - 'name' => $this->name, |
|
26 | - 'users' => UserResource::collection($this->whenLoaded('users')), |
|
27 | - 'permissions' => PermissionResource::collection($this->whenLoaded('permissions')), |
|
28 | - 'created_at' => $this->created_at, |
|
29 | - 'updated_at' => $this->updated_at, |
|
30 | - ]; |
|
31 | - } |
|
23 | + return [ |
|
24 | + 'id' => $this->id, |
|
25 | + 'name' => $this->name, |
|
26 | + 'users' => UserResource::collection($this->whenLoaded('users')), |
|
27 | + 'permissions' => PermissionResource::collection($this->whenLoaded('permissions')), |
|
28 | + 'created_at' => $this->created_at, |
|
29 | + 'updated_at' => $this->updated_at, |
|
30 | + ]; |
|
31 | + } |
|
32 | 32 | } |
@@ -10,47 +10,47 @@ |
||
10 | 10 | |
11 | 11 | class RoleController extends BaseApiController |
12 | 12 | { |
13 | - /** |
|
14 | - * Init new object. |
|
15 | - * |
|
16 | - * @param RoleRepository $repo |
|
17 | - * @return void |
|
18 | - */ |
|
19 | - public function __construct(RoleRepository $repo) |
|
20 | - { |
|
21 | - parent::__construct($repo, 'App\Modules\Roles\Http\Resources\Role'); |
|
22 | - } |
|
13 | + /** |
|
14 | + * Init new object. |
|
15 | + * |
|
16 | + * @param RoleRepository $repo |
|
17 | + * @return void |
|
18 | + */ |
|
19 | + public function __construct(RoleRepository $repo) |
|
20 | + { |
|
21 | + parent::__construct($repo, 'App\Modules\Roles\Http\Resources\Role'); |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * Insert the given model to storage. |
|
26 | - * |
|
27 | - * @param InsertRole $request |
|
28 | - * @return \Illuminate\Http\Response |
|
29 | - */ |
|
30 | - public function insert(InsertRole $request) |
|
31 | - { |
|
32 | - return new $this->modelResource($this->repo->save($request->all())); |
|
33 | - } |
|
24 | + /** |
|
25 | + * Insert the given model to storage. |
|
26 | + * |
|
27 | + * @param InsertRole $request |
|
28 | + * @return \Illuminate\Http\Response |
|
29 | + */ |
|
30 | + public function insert(InsertRole $request) |
|
31 | + { |
|
32 | + return new $this->modelResource($this->repo->save($request->all())); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Update the given model to storage. |
|
37 | - * |
|
38 | - * @param UpdateRole $request |
|
39 | - * @return \Illuminate\Http\Response |
|
40 | - */ |
|
41 | - public function update(UpdateRole $request) |
|
42 | - { |
|
43 | - return new $this->modelResource($this->repo->save($request->all())); |
|
44 | - } |
|
35 | + /** |
|
36 | + * Update the given model to storage. |
|
37 | + * |
|
38 | + * @param UpdateRole $request |
|
39 | + * @return \Illuminate\Http\Response |
|
40 | + */ |
|
41 | + public function update(UpdateRole $request) |
|
42 | + { |
|
43 | + return new $this->modelResource($this->repo->save($request->all())); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Handle an assign permissions to role request. |
|
48 | - * |
|
49 | - * @param AssignPermissions $request |
|
50 | - * @return \Illuminate\Http\Response |
|
51 | - */ |
|
52 | - public function assignPermissions(AssignPermissions $request) |
|
53 | - { |
|
54 | - return new $this->modelResource($this->repo->assignPermissions($request->get('role_id'), $request->get('permission_ids'))); |
|
55 | - } |
|
46 | + /** |
|
47 | + * Handle an assign permissions to role request. |
|
48 | + * |
|
49 | + * @param AssignPermissions $request |
|
50 | + * @return \Illuminate\Http\Response |
|
51 | + */ |
|
52 | + public function assignPermissions(AssignPermissions $request) |
|
53 | + { |
|
54 | + return new $this->modelResource($this->repo->assignPermissions($request->get('role_id'), $request->get('permission_ids'))); |
|
55 | + } |
|
56 | 56 | } |
@@ -5,32 +5,32 @@ |
||
5 | 5 | |
6 | 6 | class RoleRepository extends BaseRepository |
7 | 7 | { |
8 | - /** |
|
9 | - * Init new object. |
|
10 | - * |
|
11 | - * @param Role $model |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function __construct(Role $model) |
|
15 | - { |
|
16 | - parent::__construct($model); |
|
17 | - } |
|
8 | + /** |
|
9 | + * Init new object. |
|
10 | + * |
|
11 | + * @param Role $model |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function __construct(Role $model) |
|
15 | + { |
|
16 | + parent::__construct($model); |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * Assign the given permission ids to the given role. |
|
21 | - * |
|
22 | - * @param integer $roleId |
|
23 | - * @param array $permissionIds |
|
24 | - * @return object |
|
25 | - */ |
|
26 | - public function assignPermissions($roleId, $permissionIds) |
|
27 | - { |
|
28 | - \DB::transaction(function () use ($roleId, $permissionIds) { |
|
29 | - $role = $this->find($roleId); |
|
30 | - $role->permissions()->detach(); |
|
31 | - $role->permissions()->attach($permissionIds); |
|
32 | - }); |
|
19 | + /** |
|
20 | + * Assign the given permission ids to the given role. |
|
21 | + * |
|
22 | + * @param integer $roleId |
|
23 | + * @param array $permissionIds |
|
24 | + * @return object |
|
25 | + */ |
|
26 | + public function assignPermissions($roleId, $permissionIds) |
|
27 | + { |
|
28 | + \DB::transaction(function () use ($roleId, $permissionIds) { |
|
29 | + $role = $this->find($roleId); |
|
30 | + $role->permissions()->detach(); |
|
31 | + $role->permissions()->attach($permissionIds); |
|
32 | + }); |
|
33 | 33 | |
34 | - return $this->find($roleId); |
|
35 | - } |
|
34 | + return $this->find($roleId); |
|
35 | + } |
|
36 | 36 | } |
@@ -15,12 +15,12 @@ |
||
15 | 15 | |
16 | 16 | Route::role(['prefix' => 'roles'], function () { |
17 | 17 | |
18 | - Route::get('/', 'RoleController@index'); |
|
19 | - Route::get('/{id}', 'RoleController@find'); |
|
20 | - Route::post('/', 'RoleController@insert'); |
|
21 | - Route::put('/', 'RoleController@update'); |
|
22 | - Route::delete('/{id}', 'RoleController@delete'); |
|
23 | - Route::get('list/deleted', 'RoleController@deleted'); |
|
24 | - Route::patch('restore/{id}', 'RoleController@restore'); |
|
25 | - Route::post('assign/permissions', 'RoleController@assignPermissions'); |
|
18 | + Route::get('/', 'RoleController@index'); |
|
19 | + Route::get('/{id}', 'RoleController@find'); |
|
20 | + Route::post('/', 'RoleController@insert'); |
|
21 | + Route::put('/', 'RoleController@update'); |
|
22 | + Route::delete('/{id}', 'RoleController@delete'); |
|
23 | + Route::get('list/deleted', 'RoleController@deleted'); |
|
24 | + Route::patch('restore/{id}', 'RoleController@restore'); |
|
25 | + Route::post('assign/permissions', 'RoleController@assignPermissions'); |
|
26 | 26 | }); |
@@ -6,69 +6,69 @@ |
||
6 | 6 | class RoleObserver |
7 | 7 | { |
8 | 8 | |
9 | - public function saving($model) |
|
10 | - { |
|
11 | - // |
|
12 | - } |
|
9 | + public function saving($model) |
|
10 | + { |
|
11 | + // |
|
12 | + } |
|
13 | 13 | |
14 | - public function saved($model) |
|
15 | - { |
|
16 | - // |
|
17 | - } |
|
14 | + public function saved($model) |
|
15 | + { |
|
16 | + // |
|
17 | + } |
|
18 | 18 | |
19 | - public function creating($model) |
|
20 | - { |
|
21 | - // |
|
22 | - } |
|
19 | + public function creating($model) |
|
20 | + { |
|
21 | + // |
|
22 | + } |
|
23 | 23 | |
24 | - public function created($model) |
|
25 | - { |
|
26 | - // |
|
27 | - } |
|
24 | + public function created($model) |
|
25 | + { |
|
26 | + // |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Prevent updating of the admin role. |
|
31 | - * |
|
32 | - * @param object $model the model beign updated. |
|
33 | - * @return void |
|
34 | - */ |
|
35 | - public function updating($model) |
|
36 | - { |
|
37 | - if ($model->getOriginal('name') == 'Admin') { |
|
38 | - \ErrorHandler::noPermissions(); |
|
39 | - } |
|
40 | - } |
|
29 | + /** |
|
30 | + * Prevent updating of the admin role. |
|
31 | + * |
|
32 | + * @param object $model the model beign updated. |
|
33 | + * @return void |
|
34 | + */ |
|
35 | + public function updating($model) |
|
36 | + { |
|
37 | + if ($model->getOriginal('name') == 'Admin') { |
|
38 | + \ErrorHandler::noPermissions(); |
|
39 | + } |
|
40 | + } |
|
41 | 41 | |
42 | - public function updated($model) |
|
43 | - { |
|
44 | - // |
|
45 | - } |
|
42 | + public function updated($model) |
|
43 | + { |
|
44 | + // |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Prevent deleting the admin role. |
|
49 | - * |
|
50 | - * @param object $model the delted model. |
|
51 | - * @return void |
|
52 | - */ |
|
53 | - public function deleting($model) |
|
54 | - { |
|
55 | - if ($model->getOriginal('name') == 'Admin') { |
|
56 | - \ErrorHandler::noPermissions(); |
|
57 | - } |
|
58 | - } |
|
47 | + /** |
|
48 | + * Prevent deleting the admin role. |
|
49 | + * |
|
50 | + * @param object $model the delted model. |
|
51 | + * @return void |
|
52 | + */ |
|
53 | + public function deleting($model) |
|
54 | + { |
|
55 | + if ($model->getOriginal('name') == 'Admin') { |
|
56 | + \ErrorHandler::noPermissions(); |
|
57 | + } |
|
58 | + } |
|
59 | 59 | |
60 | - public function deleted($model) |
|
61 | - { |
|
62 | - // |
|
63 | - } |
|
60 | + public function deleted($model) |
|
61 | + { |
|
62 | + // |
|
63 | + } |
|
64 | 64 | |
65 | - public function restoring($model) |
|
66 | - { |
|
67 | - // |
|
68 | - } |
|
65 | + public function restoring($model) |
|
66 | + { |
|
67 | + // |
|
68 | + } |
|
69 | 69 | |
70 | - public function restored($model) |
|
71 | - { |
|
72 | - // |
|
73 | - } |
|
70 | + public function restored($model) |
|
71 | + { |
|
72 | + // |
|
73 | + } |
|
74 | 74 | } |
@@ -6,42 +6,42 @@ |
||
6 | 6 | class Role extends Model |
7 | 7 | { |
8 | 8 | |
9 | - use SoftDeletes; |
|
10 | - protected $table = 'roles'; |
|
11 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
12 | - protected $hidden = ['deleted_at']; |
|
13 | - protected $guarded = ['id']; |
|
14 | - protected $fillable = ['name']; |
|
15 | - public $searchable = ['name']; |
|
16 | - |
|
17 | - public function getCreatedAtAttribute($value) |
|
18 | - { |
|
19 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
20 | - } |
|
21 | - |
|
22 | - public function getUpdatedAtAttribute($value) |
|
23 | - { |
|
24 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
25 | - } |
|
26 | - |
|
27 | - public function getDeletedAtAttribute($value) |
|
28 | - { |
|
29 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
30 | - } |
|
31 | - |
|
32 | - public function users() |
|
33 | - { |
|
34 | - return $this->belongsToMany('App\Modules\Users\AclUser', 'users_roles', 'role_id', 'user_id')->whereNull('users_roles.deleted_at')->withTimestamps(); |
|
35 | - } |
|
36 | - |
|
37 | - public function permissions() |
|
38 | - { |
|
39 | - return $this->belongsToMany('App\Modules\Permissions\Permission', 'roles_permissions', 'role_id', 'permission_id')->whereNull('roles_permissions.deleted_at')->withTimestamps(); |
|
40 | - } |
|
41 | - |
|
42 | - public static function boot() |
|
43 | - { |
|
44 | - parent::boot(); |
|
45 | - Role::observe(\App::make('App\Modules\Roles\ModelObservers\RoleObserver')); |
|
46 | - } |
|
9 | + use SoftDeletes; |
|
10 | + protected $table = 'roles'; |
|
11 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
12 | + protected $hidden = ['deleted_at']; |
|
13 | + protected $guarded = ['id']; |
|
14 | + protected $fillable = ['name']; |
|
15 | + public $searchable = ['name']; |
|
16 | + |
|
17 | + public function getCreatedAtAttribute($value) |
|
18 | + { |
|
19 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
20 | + } |
|
21 | + |
|
22 | + public function getUpdatedAtAttribute($value) |
|
23 | + { |
|
24 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
25 | + } |
|
26 | + |
|
27 | + public function getDeletedAtAttribute($value) |
|
28 | + { |
|
29 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
30 | + } |
|
31 | + |
|
32 | + public function users() |
|
33 | + { |
|
34 | + return $this->belongsToMany('App\Modules\Users\AclUser', 'users_roles', 'role_id', 'user_id')->whereNull('users_roles.deleted_at')->withTimestamps(); |
|
35 | + } |
|
36 | + |
|
37 | + public function permissions() |
|
38 | + { |
|
39 | + return $this->belongsToMany('App\Modules\Permissions\Permission', 'roles_permissions', 'role_id', 'permission_id')->whereNull('roles_permissions.deleted_at')->withTimestamps(); |
|
40 | + } |
|
41 | + |
|
42 | + public static function boot() |
|
43 | + { |
|
44 | + parent::boot(); |
|
45 | + Role::observe(\App::make('App\Modules\Roles\ModelObservers\RoleObserver')); |
|
46 | + } |
|
47 | 47 | } |
@@ -6,15 +6,15 @@ |
||
6 | 6 | |
7 | 7 | class ClearDataSeeder extends Seeder |
8 | 8 | { |
9 | - /** |
|
10 | - * Run the database seeds. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function run() |
|
15 | - { |
|
16 | - $permissions = \DB::table('permissions')->whereIn('model', ['oauthClient']); |
|
17 | - \DB::table('roles_permissions')->whereIn('permission_id', $permissions->pluck('id'))->delete(); |
|
18 | - $permissions->delete(); |
|
19 | - } |
|
9 | + /** |
|
10 | + * Run the database seeds. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function run() |
|
15 | + { |
|
16 | + $permissions = \DB::table('permissions')->whereIn('model', ['oauthClient']); |
|
17 | + \DB::table('roles_permissions')->whereIn('permission_id', $permissions->pluck('id'))->delete(); |
|
18 | + $permissions->delete(); |
|
19 | + } |
|
20 | 20 | } |