Skip to content

Commit 4d8d91e

Browse files
committed
fix(role): update creation doc and validation rules
1 parent 11c2abc commit 4d8d91e

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Http/Controllers/Api/v2/RoleController.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ public function getDetail(int $role_id)
151151
* type="string",
152152
* format="byte",
153153
* description="Base64 encoded new role logo"
154+
* ),
155+
* @OA\Property(
156+
* property="permissions",
157+
* description="A list of the permissions which have to be attached to the role.",
158+
* type="array",
159+
* @OA\Items(
160+
* type="string",
161+
* description="A permission name"
162+
* )
154163
* )
155164
* )
156165
* )

src/Http/Validation/NewRole.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
namespace Seat\Api\Http\Validation;
2424

2525
use Illuminate\Foundation\Http\FormRequest;
26+
use Illuminate\Validation\Rule;
2627

2728
/**
2829
* Class NewRole.
@@ -53,8 +54,23 @@ public function rules()
5354
return [
5455
'title' => 'string|unique:roles,title|required',
5556
'description' => 'string',
56-
'permissions' => 'array',
57+
'permissions' => [
58+
'array',
59+
Rule::in($this->getPermissionsList()),
60+
],
5761
'logo' => 'base64image',
5862
];
5963
}
64+
65+
/**
66+
* @return array
67+
*/
68+
private function getPermissionsList(): array
69+
{
70+
return collect(config('seat.permissions'))->map(function ($permissions, $scope) {
71+
return collect(array_keys($permissions))->transform(function ($permission) use ($scope) {
72+
return $scope . '.' . $permission;
73+
});
74+
})->flatten()->all();
75+
}
6076
}

0 commit comments

Comments
 (0)