Skip to content

Commit

Permalink
Merge pull request #7 from FoskyM/bugfix/6-user-group
Browse files Browse the repository at this point in the history
fix: permission
  • Loading branch information
FoskyM committed Dec 7, 2023
2 parents 9db7eec + 6b4c5ef commit bd4402f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions less/forum/oauth.less
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ img.oauth-scope-object {
font-weight: 800;
color: #382e2e;
margin-block-end: 0;
font-size: 12px;
}

.oauth-scope-body small {
Expand Down
11 changes: 10 additions & 1 deletion src/Api/Controller/ListScopeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,23 @@
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
{
public $serializer = ScopeSerializer::class;
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();
}
Expand Down
31 changes: 31 additions & 0 deletions src/Api/Serializer/ScopeUserSerializer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace FoskyM\OAuthCenter\Api\Serializer;

use Flarum\Api\Serializer\AbstractSerializer;
use FoskyM\OAuthCenter\Models\Scope;
use InvalidArgumentException;

class ScopeUserSerializer extends AbstractSerializer
{
protected $type = 'oauth-scopes';

protected function getDefaultAttributes($model)
{
if (!($model instanceof Scope)) {
throw new InvalidArgumentException(
get_class($this) . ' can only serialize instances of ' . Scope::class
);
}

// See https://docs.flarum.org/extend/api.html#serializers for more information.

return [
"scope" => $model->scope,
"is_default" => $model->is_default,
"scope_name" => $model->scope_name,
"scope_icon" => $model->scope_icon,
"scope_desc" => $model->scope_desc,
];
}
}

0 comments on commit bd4402f

Please sign in to comment.