Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: permission #7

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
];
}
}