Skip to content

Commit 950c02e

Browse files
committed
Added role API responses & requests
Also applied other slight tweaks and comment updates based upon manual endpoint testing.
1 parent 9502f34 commit 950c02e

File tree

9 files changed

+147
-9
lines changed

9 files changed

+147
-9
lines changed

app/Auth/Role.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class Role extends Model implements Loggable
3131

3232
protected $hidden = ['pivot'];
3333

34+
protected $casts = [
35+
'mfa_enforced' => 'boolean',
36+
];
37+
3438
/**
3539
* The roles that belong to the role.
3640
*/

app/Http/Controllers/Api/RoleApiController.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ class RoleApiController extends ApiController
1717

1818
protected $rules = [
1919
'create' => [
20-
'display_name' => ['required', 'min:3', 'max:180'],
21-
'description' => ['max:180'],
20+
'display_name' => ['required', 'string', 'min:3', 'max:180'],
21+
'description' => ['string', 'max:180'],
2222
'mfa_enforced' => ['boolean'],
2323
'external_auth_id' => ['string'],
2424
'permissions' => ['array'],
2525
'permissions.*' => ['string'],
2626
],
2727
'update' => [
28-
'display_name' => ['min:3', 'max:180'],
29-
'description' => ['max:180'],
28+
'display_name' => ['string', 'min:3', 'max:180'],
29+
'description' => ['string', 'max:180'],
3030
'mfa_enforced' => ['boolean'],
3131
'external_auth_id' => ['string'],
3232
'permissions' => ['array'],
@@ -64,6 +64,7 @@ public function list()
6464

6565
/**
6666
* Create a new role in the system.
67+
* Permissions should be provided as an array of permission name strings.
6768
* Requires permission to manage roles.
6869
*/
6970
public function create(Request $request)
@@ -81,7 +82,8 @@ public function create(Request $request)
8182
}
8283

8384
/**
84-
* View the details of a single user.
85+
* View the details of a single role.
86+
* Provides the permissions and a high-level list of the users assigned.
8587
* Requires permission to manage roles.
8688
*/
8789
public function read(string $id)
@@ -94,6 +96,10 @@ public function read(string $id)
9496

9597
/**
9698
* Update an existing role in the system.
99+
* Permissions should be provided as an array of permission name strings.
100+
* An empty "permissions" array would clear granted permissions.
101+
* In many cases, where permissions are changed, you'll want to fetch the existing
102+
* permissions and then modify before providing in your update request.
97103
* Requires permission to manage roles.
98104
*/
99105
public function update(Request $request, string $id)
@@ -107,9 +113,7 @@ public function update(Request $request, string $id)
107113
}
108114

109115
/**
110-
* Delete a user from the system.
111-
* Can optionally accept a user id via `migrate_ownership_id` to indicate
112-
* who should be the new owner of their related content.
116+
* Delete a role from the system.
113117
* Requires permission to manage roles.
114118
*/
115119
public function delete(string $id)

dev/api/requests/roles-create.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"display_name": "Book Maintainer",
3+
"description": "People who maintain books",
4+
"mfa_enforced": true,
5+
"permissions": [
6+
"book-view-all",
7+
"book-update-all",
8+
"book-delete-all",
9+
"restrictions-manage-all"
10+
]
11+
}

dev/api/requests/roles-update.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"display_name": "Book & Shelf Maintainers",
3+
"description": "All those who maintain books & shelves",
4+
"mfa_enforced": false,
5+
"permissions": [
6+
"book-view-all",
7+
"book-update-all",
8+
"book-delete-all",
9+
"bookshelf-view-all",
10+
"bookshelf-update-all",
11+
"bookshelf-delete-all",
12+
"restrictions-manage-all"
13+
]
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"display_name": "Book Maintainer",
3+
"description": "People who maintain books",
4+
"mfa_enforced": true,
5+
"updated_at": "2023-02-19T15:38:40.000000Z",
6+
"created_at": "2023-02-19T15:38:40.000000Z",
7+
"id": 26,
8+
"permissions": [
9+
"book-delete-all",
10+
"book-update-all",
11+
"book-view-all",
12+
"restrictions-manage-all"
13+
],
14+
"users": []
15+
}

dev/api/responses/roles-list.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"data": [
3+
{
4+
"id": 1,
5+
"display_name": "Admin",
6+
"description": "Administrator of the whole application",
7+
"created_at": "2021-09-29T16:29:19.000000Z",
8+
"updated_at": "2022-11-03T13:26:18.000000Z",
9+
"system_name": "admin",
10+
"external_auth_id": "wizards",
11+
"mfa_enforced": true,
12+
"users_count": 11,
13+
"permissions_count": 54
14+
},
15+
{
16+
"id": 2,
17+
"display_name": "Editor",
18+
"description": "User can edit Books, Chapters & Pages",
19+
"created_at": "2021-09-29T16:29:19.000000Z",
20+
"updated_at": "2022-12-01T02:32:57.000000Z",
21+
"system_name": "",
22+
"external_auth_id": "",
23+
"mfa_enforced": false,
24+
"users_count": 17,
25+
"permissions_count": 49
26+
},
27+
{
28+
"id": 3,
29+
"display_name": "Public",
30+
"description": "The role given to public visitors if allowed",
31+
"created_at": "2021-09-29T16:29:19.000000Z",
32+
"updated_at": "2022-09-02T12:32:12.000000Z",
33+
"system_name": "public",
34+
"external_auth_id": "",
35+
"mfa_enforced": false,
36+
"users_count": 1,
37+
"permissions_count": 2
38+
}
39+
],
40+
"total": 3
41+
}

dev/api/responses/roles-read.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"id": 26,
3+
"display_name": "Book Maintainer",
4+
"description": "People who maintain books",
5+
"created_at": "2023-02-19T15:38:40.000000Z",
6+
"updated_at": "2023-02-19T15:38:40.000000Z",
7+
"system_name": "",
8+
"external_auth_id": "",
9+
"mfa_enforced": true,
10+
"permissions": [
11+
"book-delete-all",
12+
"book-update-all",
13+
"book-view-all",
14+
"restrictions-manage-all"
15+
],
16+
"users": [
17+
{
18+
"id": 11,
19+
"name": "Barry Scott",
20+
"slug": "barry-scott"
21+
}
22+
]
23+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"id": 26,
3+
"display_name": "Book & Shelf Maintainers",
4+
"description": "All those who maintain books & shelves",
5+
"created_at": "2023-02-19T15:38:40.000000Z",
6+
"updated_at": "2023-02-19T15:49:13.000000Z",
7+
"system_name": "",
8+
"external_auth_id": "",
9+
"mfa_enforced": false,
10+
"permissions": [
11+
"book-delete-all",
12+
"book-update-all",
13+
"book-view-all",
14+
"bookshelf-delete-all",
15+
"bookshelf-update-all",
16+
"bookshelf-view-all",
17+
"restrictions-manage-all"
18+
],
19+
"users": [
20+
{
21+
"id": 11,
22+
"name": "Barry Scott",
23+
"slug": "barry-scott"
24+
}
25+
]
26+
}

routes/api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
Route::get('pages/{id}/export/html', [PageExportApiController::class, 'exportHtml']);
6161
Route::get('pages/{id}/export/pdf', [PageExportApiController::class, 'exportPdf']);
6262
Route::get('pages/{id}/export/plaintext', [PageExportApiController::class, 'exportPlainText']);
63-
Route::get('pages/{id}/export/markdown', [PageExportApiController::class, 'exportMarkDown']);
63+
Route::get('pages/{id}/export/markdown', [PageExportApiController::class, 'exportMarkdown']);
6464

6565
Route::get('search', [SearchApiController::class, 'all']);
6666

0 commit comments

Comments
 (0)