Skip to content

Commit

Permalink
perf: only load user state when showing full user data
Browse files Browse the repository at this point in the history
  • Loading branch information
SychO9 committed Mar 8, 2024
1 parent 0ada6d0 commit 27c4f08
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Extenders/UserPoliciesRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace FoF\Terms\Extenders;

use Flarum\Api\Serializer\BasicUserSerializer;
use Flarum\Api\Serializer\CurrentUserSerializer;
use Flarum\User\User;
use FoF\Terms\Repositories\PolicyRepository;

Expand All @@ -33,6 +34,9 @@ public function __invoke(BasicUserSerializer $serializer, User $user, array $att

if ($request->getAttribute('routeName') === 'users.show' && $serializer->getActor()->can('seeFoFTermsPoliciesState', $user)) {
$attributes['fofTermsPoliciesState'] = $this->policies->state($user);
}

if ($serializer instanceof CurrentUserSerializer) {
$attributes['fofTermsPoliciesHasUpdate'] = $this->policies->hasPoliciesUpdate($user);
$attributes['fofTermsPoliciesMustAccept'] = $this->policies->mustAcceptNewPolicies($user);
}
Expand Down

0 comments on commit 27c4f08

Please sign in to comment.