Skip to content

Commit

Permalink
Merge pull request #11753 from nanaya/member-deleted
Browse files Browse the repository at this point in the history
Fix handling of deleted and restricted team members
  • Loading branch information
notbakaneko authored Dec 18, 2024
2 parents fc60d2d + fdd884c commit f8b6578
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
9 changes: 9 additions & 0 deletions app/Models/TeamMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@ public function user(): BelongsTo
{
return $this->belongsTo(User::class, 'user_id');
}

public function userOrDeleted(): User
{
$user = $this->user;

return $user === null || $user->isRestricted()
? new DeletedUser(['user_id' => $this->user_id])
: $user;
}
}
13 changes: 8 additions & 5 deletions resources/views/teams/members/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,26 @@
<span>{{ osu_trans('teams.members.index.table.joined_at') }}</span>
<span></span>
@foreach ($team->members as $member)
@php
$user = $member->userOrDeleted();
@endphp
<li class="team-members-manage__item">
<span class="team-members-manage__avatar">
<span
class="avatar avatar--full avatar--guest"
{!! background_image($member->user->user_avatar) !!}
{!! background_image($user->user_avatar) !!}
></span>
</span>
<span>
{!! link_to_user($member->user, null, '', []) !!}
{!! link_to_user($user, null, '', []) !!}
</span>
<span>
{{ osu_trans('teams.members.index.status.status_'.(int) $member->user->isActive()) }}
@if ($member->user->isOnline())
{{ osu_trans('teams.members.index.status.status_'.(int) $user->isActive()) }}
@if ($user->isOnline())
<small>
({!! osu_trans('users.show.lastvisit_online') !!})
</small>
@elseif (($lastvisit = $member->user->displayed_last_visit) !== null)
@elseif (($lastvisit = $user->displayed_last_visit) !== null)
<small>
({!! osu_trans('users.show.lastvisit', ['date' => timeago($lastvisit)]) !!})
</small>
Expand Down
5 changes: 2 additions & 3 deletions resources/views/teams/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
See the LICENCE file in the repository root for full licence text.
--}}
@php
use App\Models\DeletedUser;
use App\Transformers\UserCompactTransformer;
$userTransformer = new UserCompactTransformer();
$toJson = fn ($users) => json_collection($users, $userTransformer, UserCompactTransformer::CARD_INCLUDES);
$teamMembers = array_map($toJson, $team->members->mapToGroups(fn ($member) => [
$member->user_id === $team->leader_id ? 'leader' : 'member' => $member->user,
$member->user_id === $team->leader_id ? 'leader' : 'member' => $member->userOrDeleted(),
])->all());
$teamMembers['member'] ??= [];
$teamMembers['leader'] ??= $toJson([$team->leader ?? new DeletedUser(['user_id' => $team->leader_id])]);
$teamMembers['leader'] ??= $toJson([$team->members()->make(['user_id' => $team->leader_id])->userOrDeleted()]);
$headerUrl = $team->header()->url();
@endphp

Expand Down

0 comments on commit f8b6578

Please sign in to comment.