@@ -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