File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff 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 * )
Original file line number Diff line number Diff line change 2323namespace Seat \Api \Http \Validation ;
2424
2525use 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}
You can’t perform that action at this time.
0 commit comments