Skip to content

Commit

Permalink
Merge pull request #11757 from nanaya/team-leave
Browse files Browse the repository at this point in the history
Add leave team button
  • Loading branch information
notbakaneko authored Dec 20, 2024
2 parents 4ac7d36 + d63acb9 commit 3a3ab74
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 4 deletions.
17 changes: 17 additions & 0 deletions app/Http/Controllers/TeamsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

class TeamsController extends Controller
{
public function __construct()
{
parent::__construct();
$this->middleware('auth', ['only' => ['part']]);
}

public function edit(string $id): Response
{
$team = Team::findOrFail($id);
Expand All @@ -21,6 +27,17 @@ public function edit(string $id): Response
return ext_view('teams.edit', compact('team'));
}

public function part(string $id): Response
{
$team = Team::findOrFail($id);
priv_check('TeamPart', $team)->ensureCan();

$team->members()->findOrFail(\Auth::user()->getKey())->delete();
\Session::flash('popup', osu_trans('teams.part.ok'));

return ujs_redirect(route('teams.show', ['team' => $team]));
}

public function show(string $id): Response
{
$team = Team
Expand Down
19 changes: 18 additions & 1 deletion app/Singletons/OsuAuthorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ public static function alwaysCheck($ability)

$set ??= new Ds\Set([
'ContestJudge',
'IsOwnClient',
'IsNotOAuth',
'IsOwnClient',
'IsSpecialScope',
'TeamPart',
'UserUpdateEmail',
]);

Expand Down Expand Up @@ -1904,6 +1905,22 @@ public function checkScorePin(?User $user, ScoreBest|Solo\Score $score): string
return 'ok';
}

public function checkTeamPart(?User $user, Team $team): ?string
{
$this->ensureLoggedIn($user);

$prefix = 'team.part.';

if ($team->leader_id === $user->getKey()) {
return $prefix.'is_leader';
}
if ($team->getKey() !== $user?->team?->getKey()) {
return $prefix.'not_member';
}

return 'ok';
}

public function checkTeamUpdate(?User $user, Team $team): ?string
{
$this->ensureLoggedIn($user);
Expand Down
1 change: 1 addition & 0 deletions resources/css/bem-index.less
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 4 additions & 0 deletions resources/css/bem/profile-detail-bar.less
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
--padding: @gutter-v2-desktop;
}

&--team {
justify-content: end;
}

&__level {
margin-left: auto;
display: flex;
Expand Down
31 changes: 31 additions & 0 deletions resources/css/bem/team-action-button.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. 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));
}
}
7 changes: 7 additions & 0 deletions resources/lang/en/authorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@
],
],

'team' => [
'part' => [
'is_leader' => "Team leader can't leave the team.",
'not_member' => 'Not a member of the team.',
],
],

'user' => [
'page' => [
'edit' => [
Expand Down
7 changes: 6 additions & 1 deletion resources/lang/en/teams.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,14 @@
],
],
],

'part' => [
'ok' => 'Left the team ;_;',
],

'show' => [
'bar' => [
'settings' => 'Settings',
'part' => 'Leave Team',
],

'info' => [
Expand Down
20 changes: 20 additions & 0 deletions resources/views/teams/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
$teamMembers['member'] ??= [];
$teamMembers['leader'] ??= $toJson([$team->members()->make(['user_id' => $team->leader_id])->userOrDeleted()]);
$headerUrl = $team->header()->url();
$buttons = new Ds\Set();
if (priv_check('TeamPart', $team)->can()) {
$buttons->add('part');
}
@endphp

@extends('master', [
Expand Down Expand Up @@ -69,6 +74,21 @@ class="btn-circle btn-circle--page-toggle"
</div>
</div>
</div>
@if (!$buttons->isEmpty())
<div class="profile-detail-bar profile-detail-bar--team">
@if ($buttons->contains('part'))
<form
action="{{ route('teams.part', ['team' => $team]) }}"
data-turbo-confirm="{{ osu_trans('common.confirmation') }}"
method="POST"
>
<button class="team-action-button team-action-button--part">
{{ osu_trans('teams.show.bar.part') }}
</button>
</form>
@endif
</div>
@endif
<div class="user-profile-pages user-profile-pages--no-tabs">
<div class="page-extra u-fancy-scrollbar">
<div class="team-summary">
Expand Down
5 changes: 3 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,9 @@
Route::post('user-cover-presets/batch-activate', 'UserCoverPresetsController@batchActivate')->name('user-cover-presets.batch-activate');
Route::resource('user-cover-presets', 'UserCoverPresetsController', ['only' => ['index', 'store', 'update']]);

Route::group(['as' => 'teams.', 'prefix' => 'teams/{team}', 'namespace' => 'Teams'], function () {
Route::resource('members', 'MembersController', ['only' => ['destroy', 'index']]);
Route::group(['as' => 'teams.', 'prefix' => 'teams/{team}'], function () {
Route::post('part', 'TeamsController@part')->name('part');
Route::resource('members', 'Teams\MembersController', ['only' => ['destroy', 'index']]);
});
Route::resource('teams', 'TeamsController', ['only' => ['edit', 'show', 'update']]);

Expand Down

0 comments on commit 3a3ab74

Please sign in to comment.