From c67c6cea39a9b047d7ae8919a412ffcd46ccf983 Mon Sep 17 00:00:00 2001 From: nanaya Date: Fri, 13 Dec 2024 20:07:55 +0900 Subject: [PATCH 1/9] Require multiplayer api to join multiplayer room --- app/Singletons/OsuAuthorize.php | 10 +++------- tests/Controllers/Chat/ChannelsControllerTest.php | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/app/Singletons/OsuAuthorize.php b/app/Singletons/OsuAuthorize.php index 92143f27e22..27c14d000e0 100644 --- a/app/Singletons/OsuAuthorize.php +++ b/app/Singletons/OsuAuthorize.php @@ -1027,7 +1027,7 @@ public function checkChatChannelRead(?User $user, Channel $channel): string * @return string * @throws AuthorizationCheckException */ - public function checkChatChannelJoin(?User $user, Channel $channel): string + public function checkChatChannelJoin(?User $user, Channel $channel): ?string { $prefix = 'chat.'; @@ -1039,13 +1039,9 @@ public function checkChatChannelJoin(?User $user, Channel $channel): string $this->ensureCleanRecord($user, $prefix); - // This check is only for when joining the channel directly; joining via the Room - // will always add the user to the channel. + // joining multiplayer room is done through room endpoint if ($channel->isMultiplayer()) { - $room = Room::hasParticipated($user)->find($channel->room_id); - if ($room !== null) { - return 'ok'; - } + return null; } // allow joining of 'tournament' matches (for lazer/tournament client) diff --git a/tests/Controllers/Chat/ChannelsControllerTest.php b/tests/Controllers/Chat/ChannelsControllerTest.php index dac9bbc3b51..6b097bcc1cf 100644 --- a/tests/Controllers/Chat/ChannelsControllerTest.php +++ b/tests/Controllers/Chat/ChannelsControllerTest.php @@ -205,7 +205,7 @@ public function testChannelJoinMultiplayerWhenParticipated() 'user' => $this->user->getKey(), ])); - $request->assertStatus(200)->assertJsonFragment(['channel_id' => $scoreLink->playlistItem->room->channel_id, 'type' => Channel::TYPES['multiplayer']]); + $request->assertStatus(403); } //endregion From 27717a11f28f405690524daa08bdf1d0559abbf5 Mon Sep 17 00:00:00 2001 From: nanaya Date: Wed, 18 Dec 2024 21:50:51 +0900 Subject: [PATCH 2/9] Add leave team button --- app/Http/Controllers/TeamsController.php | 23 +++++++++++++++++ resources/css/bem-index.less | 1 + resources/css/bem/profile-detail-bar.less | 4 +++ resources/css/bem/team-action-button.less | 31 +++++++++++++++++++++++ resources/lang/en/teams.php | 8 +++++- resources/views/teams/show.blade.php | 21 +++++++++++++++ routes/web.php | 1 + 7 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 resources/css/bem/team-action-button.less diff --git a/app/Http/Controllers/TeamsController.php b/app/Http/Controllers/TeamsController.php index ee853c5b74c..0fea6b6937b 100644 --- a/app/Http/Controllers/TeamsController.php +++ b/app/Http/Controllers/TeamsController.php @@ -8,11 +8,18 @@ namespace App\Http\Controllers; use App\Models\Team; +use App\Models\TeamMember; use App\Transformers\UserCompactTransformer; use Symfony\Component\HttpFoundation\Response; class TeamsController extends Controller { + public function __construct() + { + parent::__construct(); + $this->middleware('auth', ['only' => ['part']]); + } + public function edit(string $id): Response { $team = Team::findOrFail($id); @@ -21,6 +28,22 @@ public function edit(string $id): Response return ext_view('teams.edit', compact('team')); } + public function part(): Response + { + $member = TeamMember::findOrFail(\Auth::user()->getKey()); + + if ($member === null) { + \Session::flash('popup', osu_trans('teams.part.no_team')); + + return ujs_redirect(route('home')); + } + + $member->delete(); + \Session::flash('popup', osu_trans('teams.part.ok')); + + return ujs_redirect(route('teams.show', ['team' => $member->team_id])); + } + public function show(string $id): Response { $team = Team diff --git a/resources/css/bem-index.less b/resources/css/bem-index.less index 20a241d8000..c54c04ab27b 100644 --- a/resources/css/bem-index.less +++ b/resources/css/bem-index.less @@ -383,6 +383,7 @@ @import "bem/supporter-promo"; @import "bem/supporter-quote"; @import "bem/supporter-status"; +@import "bem/team-action-button"; @import "bem/team-info-entries"; @import "bem/team-info-entry"; @import "bem/team-members"; diff --git a/resources/css/bem/profile-detail-bar.less b/resources/css/bem/profile-detail-bar.less index 8524856f16d..49a0cd83b63 100644 --- a/resources/css/bem/profile-detail-bar.less +++ b/resources/css/bem/profile-detail-bar.less @@ -19,6 +19,10 @@ --padding: @gutter-v2-desktop; } + &--team { + justify-content: end; + } + &__level { margin-left: auto; display: flex; diff --git a/resources/css/bem/team-action-button.less b/resources/css/bem/team-action-button.less new file mode 100644 index 00000000000..bb0712b5cc3 --- /dev/null +++ b/resources/css/bem/team-action-button.less @@ -0,0 +1,31 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the GNU Affero General Public License v3.0. +// See the LICENCE file in the repository root for full licence text. + +.team-action-button { + .reset-input(); + .link-plain(); + .link-white(); + .center-content(); + .default-text-shadow(); + display: flex; + width: auto; + height: 100%; + padding: 10px 30px; + border-radius: 10000px; + text-align: center; + font-weight: bold; + font-size: @font-size--title-small; + background: var(--bg); + + --bg: hsl(var(--hsl-b5)); + --bg-hover: hsl(var(--hsl-b6)); + + &:hover { + background: var(--bg-hover); + } + + &--part { + --bg: hsl(var(--hsl-red-3)); + --bg-hover: hsl(var(--hsl-red-2)); + } +} diff --git a/resources/lang/en/teams.php b/resources/lang/en/teams.php index 463c321fd04..722773b06d9 100644 --- a/resources/lang/en/teams.php +++ b/resources/lang/en/teams.php @@ -59,9 +59,15 @@ ], ], ], + + 'part' => [ + 'no_team' => 'Not part of any team', + 'ok' => 'Left the team ;_;', + ], + 'show' => [ 'bar' => [ - 'settings' => 'Settings', + 'part' => 'Leave Team', ], 'info' => [ diff --git a/resources/views/teams/show.blade.php b/resources/views/teams/show.blade.php index 7e8bd0e786c..318464e0df3 100644 --- a/resources/views/teams/show.blade.php +++ b/resources/views/teams/show.blade.php @@ -13,6 +13,12 @@ $teamMembers['member'] ??= []; $teamMembers['leader'] ??= $toJson([$team->members()->make(['user_id' => $team->leader_id])->userOrDeleted()]); $headerUrl = $team->header()->url(); + + $currentUser = Auth::user(); + $buttons = new Ds\Set(); + if ($currentUser !== null && $currentUser->team?->getKey() === $team->getKey() && $currentUser->getKey() !== $team->leader_id) { + $buttons->add('part'); + } @endphp @extends('master', [ @@ -69,6 +75,21 @@ class="btn-circle btn-circle--page-toggle" + @if (!$buttons->isEmpty()) +
+ @if ($buttons->contains('part')) +
+ +
+ @endif +
+ @endif