Skip to content

Commit

Permalink
fix(role): update creation doc and validation rules
Browse files Browse the repository at this point in the history
  • Loading branch information
warlof committed Dec 30, 2020
1 parent 11c2abc commit 4d8d91e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/Http/Controllers/Api/v2/RoleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ public function getDetail(int $role_id)
* type="string",
* format="byte",
* description="Base64 encoded new role logo"
* ),
* @OA\Property(
* property="permissions",
* description="A list of the permissions which have to be attached to the role.",
* type="array",
* @OA\Items(
* type="string",
* description="A permission name"
* )
* )
* )
* )
Expand Down
18 changes: 17 additions & 1 deletion src/Http/Validation/NewRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
namespace Seat\Api\Http\Validation;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

/**
* Class NewRole.
Expand Down Expand Up @@ -53,8 +54,23 @@ public function rules()
return [
'title' => 'string|unique:roles,title|required',
'description' => 'string',
'permissions' => 'array',
'permissions' => [
'array',
Rule::in($this->getPermissionsList()),
],
'logo' => 'base64image',
];
}

/**
* @return array
*/
private function getPermissionsList(): array
{
return collect(config('seat.permissions'))->map(function ($permissions, $scope) {
return collect(array_keys($permissions))->transform(function ($permission) use ($scope) {
return $scope . '.' . $permission;
});
})->flatten()->all();
}
}

0 comments on commit 4d8d91e

Please sign in to comment.