diff options
Diffstat (limited to 'main/app/sprinkles/admin/src/Sprunje/UserPermissionSprunje.php')
-rwxr-xr-x | main/app/sprinkles/admin/src/Sprunje/UserPermissionSprunje.php | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/main/app/sprinkles/admin/src/Sprunje/UserPermissionSprunje.php b/main/app/sprinkles/admin/src/Sprunje/UserPermissionSprunje.php new file mode 100755 index 0000000..6142e74 --- /dev/null +++ b/main/app/sprinkles/admin/src/Sprunje/UserPermissionSprunje.php @@ -0,0 +1,48 @@ +<?php +/** + * UserFrosting (http://www.userfrosting.com) + * + * @link https://github.com/userfrosting/UserFrosting + * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) + */ +namespace UserFrosting\Sprinkle\Admin\Sprunje; + +use Illuminate\Database\Capsule\Manager as Capsule; +use UserFrosting\Sprinkle\Core\Facades\Debug; +use UserFrosting\Support\Exception\BadRequestException; +use UserFrosting\Support\Exception\NotFoundException; + +/** + * UserPermissionSprunje + * + * Implements Sprunje for retrieving a list of permissions for a specified user. + * + * @author Alex Weissman (https://alexanderweissman.com) + */ +class UserPermissionSprunje extends PermissionSprunje +{ + protected $name = 'user_permissions'; + + /** + * {@inheritDoc} + */ + protected function baseQuery() + { + // Requires a user id + if (!isset($this->options['user_id'])) { + throw new BadRequestException(); + } + + $user = $this->classMapper->staticMethod('user', 'find', $this->options['user_id']); + + // If the user doesn't exist, return 404 + if (!$user) { + throw new NotFoundException; + } + + // Get user permissions + $query = $user->permissions()->withVia('roles_via'); + + return $query; + } +} |