Skip to content

Commit 599635b

Browse files
committed
Add missing getInfo methods for GroupController and RoleController (#837)
1 parent 4905fda commit 599635b

3 files changed

Lines changed: 79 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## v4.1.17-alpha
99
- Lock `gulp-uf-bundle-assets` at v2.28.0 until Silic0nS0ldier/gulp-uf-bundle-assets#5 is resolved (see #859)
10+
- Add missing getInfo methods for GroupController and RoleController (#837)
1011

1112
## v4.1.16-alpha
1213
- Fix for `merge` bundling rule (#660)

app/sprinkles/admin/src/Controller/GroupController.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,45 @@ public function delete($request, $response, $args)
200200
return $response->withStatus(200);
201201
}
202202

203+
/**
204+
* Returns info for a single group.
205+
*
206+
* This page requires authentication.
207+
* Request type: GET
208+
*/
209+
public function getInfo($request, $response, $args)
210+
{
211+
/** @var UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager */
212+
$authorizer = $this->ci->authorizer;
213+
214+
/** @var UserFrosting\Sprinkle\Account\Database\Models\User $currentUser */
215+
$currentUser = $this->ci->currentUser;
216+
217+
// Access-controlled page
218+
if (!$authorizer->checkAccess($currentUser, 'uri_groups')) {
219+
throw new ForbiddenException();
220+
}
221+
222+
$slug = $args['slug'];
223+
224+
/** @var UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
225+
$classMapper = $this->ci->classMapper;
226+
227+
$group = $classMapper->staticMethod('group', 'where', 'slug', $slug)->first();
228+
229+
// If the group doesn't exist, return 404
230+
if (!$group) {
231+
throw new NotFoundException($request, $response);
232+
}
233+
234+
// Get group
235+
$result = $group->toArray();
236+
237+
// Be careful how you consume this data - it has not been escaped and contains untrusted user-supplied content.
238+
// For example, if you plan to insert it into an HTML DOM, you must escape it on the client side (or use client-side templating).
239+
return $response->withJson($result, 200, JSON_PRETTY_PRINT);
240+
}
241+
203242
/**
204243
* Returns a list of Groups
205244
*

app/sprinkles/admin/src/Controller/RoleController.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,45 @@ public function delete($request, $response, $args)
199199
return $response->withStatus(200);
200200
}
201201

202+
/**
203+
* Returns info for a single role, along with associated permissions.
204+
*
205+
* This page requires authentication.
206+
* Request type: GET
207+
*/
208+
public function getInfo($request, $response, $args)
209+
{
210+
/** @var UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager */
211+
$authorizer = $this->ci->authorizer;
212+
213+
/** @var UserFrosting\Sprinkle\Account\Database\Models\User $currentUser */
214+
$currentUser = $this->ci->currentUser;
215+
216+
// Access-controlled page
217+
if (!$authorizer->checkAccess($currentUser, 'uri_roles')) {
218+
throw new ForbiddenException();
219+
}
220+
221+
$slug = $args['slug'];
222+
223+
/** @var UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
224+
$classMapper = $this->ci->classMapper;
225+
226+
$role = $classMapper->staticMethod('role', 'where', 'slug', $slug)->first();
227+
228+
// If the role doesn't exist, return 404
229+
if (!$role) {
230+
throw new NotFoundException($request, $response);
231+
}
232+
233+
// Get role
234+
$result = $role->load('permissions')->toArray();
235+
236+
// Be careful how you consume this data - it has not been escaped and contains untrusted user-supplied content.
237+
// For example, if you plan to insert it into an HTML DOM, you must escape it on the client side (or use client-side templating).
238+
return $response->withJson($result, 200, JSON_PRETTY_PRINT);
239+
}
240+
202241
/**
203242
* Returns a list of Roles
204243
*

0 commit comments

Comments
 (0)