From 6b4c5ef70356fd28855534264b59942be481cc78 Mon Sep 17 00:00:00 2001 From: FoskyM Date: Thu, 7 Dec 2023 10:58:24 +0800 Subject: [PATCH] fix: permission --- less/forum/oauth.less | 1 + src/Api/Controller/ListScopeController.php | 11 +++++++- src/Api/Serializer/ScopeUserSerializer.php | 31 ++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/Api/Serializer/ScopeUserSerializer.php diff --git a/less/forum/oauth.less b/less/forum/oauth.less index c85eea5..55c3d0e 100644 --- a/less/forum/oauth.less +++ b/less/forum/oauth.less @@ -217,6 +217,7 @@ img.oauth-scope-object { font-weight: 800; color: #382e2e; margin-block-end: 0; + font-size: 12px; } .oauth-scope-body small { diff --git a/src/Api/Controller/ListScopeController.php b/src/Api/Controller/ListScopeController.php index 44344ef..d9f38e3 100644 --- a/src/Api/Controller/ListScopeController.php +++ b/src/Api/Controller/ListScopeController.php @@ -9,6 +9,7 @@ use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; use FoskyM\OAuthCenter\Models\Scope; use FoskyM\OAuthCenter\Api\Serializer\ScopeSerializer; +use FoskyM\OAuthCenter\Api\Serializer\ScopeUserSerializer; class ListScopeController extends AbstractListController { @@ -16,7 +17,15 @@ class ListScopeController extends AbstractListController protected function data(ServerRequestInterface $request, Document $document) { $actor = RequestUtil::getActor($request); - $actor->assertAdmin(); + try { + $actor->assertAdmin(); + } catch (\Exception $e) { + $actor->assertRegistered(); + if (!$actor->hasPermission('foskym-oauth-center.use-oauth')) { + return []; + } + $this->serializer = ScopeUserSerializer::class; + } return Scope::all(); } diff --git a/src/Api/Serializer/ScopeUserSerializer.php b/src/Api/Serializer/ScopeUserSerializer.php new file mode 100644 index 0000000..17a1dff --- /dev/null +++ b/src/Api/Serializer/ScopeUserSerializer.php @@ -0,0 +1,31 @@ + $model->scope, + "is_default" => $model->is_default, + "scope_name" => $model->scope_name, + "scope_icon" => $model->scope_icon, + "scope_desc" => $model->scope_desc, + ]; + } +}