Skip to content

Commit

Permalink
Add disband team button
Browse files Browse the repository at this point in the history
  • Loading branch information
nanaya committed Dec 20, 2024
1 parent 59fc6c1 commit fc4b347
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
11 changes: 11 additions & 0 deletions app/Http/Controllers/TeamsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ public function __construct()
$this->middleware('auth', ['only' => ['part']]);
}

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

$team->delete();
\Session::flash('popup', osu_trans('teams.destroy.ok'));

return ujs_redirect(route('home'));
}

public function edit(string $id): Response
{
$team = Team::findOrFail($id);
Expand Down
13 changes: 13 additions & 0 deletions app/Models/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ public function descriptionHtml(): string
: bbcode((new BBCodeForDB($description))->generate());
}

public function delete()
{
$ret = parent::delete();

if ($ret) {
$this->header()->delete();
$this->logo()->delete();
$this->members()->delete();
}

return $ret;
}

public function header(): Uploader
{
return $this->header ??= new Uploader(
Expand Down
5 changes: 5 additions & 0 deletions resources/lang/en/teams.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
// See the LICENCE file in the repository root for full licence text.

return [
'destroy' => [
'ok' => 'Team removed',
],

'edit' => [
'saved' => 'Settings saved successfully',
'title' => 'Team Settings',
Expand Down Expand Up @@ -66,6 +70,7 @@

'show' => [
'bar' => [
'destroy' => 'Disband Team',
'part' => 'Leave Team',
],

Expand Down
15 changes: 15 additions & 0 deletions resources/views/teams/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
if (priv_check('TeamPart', $team)->can()) {
$buttons->add('part');
}
if (priv_check('TeamUpdate', $team)->can()) {
$buttons->add('destroy');
}
@endphp

@extends('master', [
Expand Down Expand Up @@ -76,6 +79,18 @@ class="btn-circle btn-circle--page-toggle"
</div>
@if (!$buttons->isEmpty())
<div class="profile-detail-bar profile-detail-bar--team">
@if ($buttons->contains('destroy'))
<form
action="{{ route('teams.destroy', $team) }}"
data-turbo-confirm="{{ osu_trans('common.confirmation') }}"
method="POST"
>
<input type="hidden" name="_method" value="DELETE">
<button class="team-action-button team-action-button--part">
{{ osu_trans('teams.show.bar.destroy') }}
</button>
</form>
@endif
@if ($buttons->contains('part'))
<form
action="{{ route('teams.part', ['team' => $team]) }}"
Expand Down
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@
Route::post('part', 'TeamsController@part')->name('part');
Route::resource('members', 'Teams\MembersController', ['only' => ['destroy', 'index']]);
});
Route::resource('teams', 'TeamsController', ['only' => ['edit', 'show', 'update']]);
Route::resource('teams', 'TeamsController', ['only' => ['destroy', 'edit', 'show', 'update']]);

Route::post('users/check-username-availability', 'UsersController@checkUsernameAvailability')->name('users.check-username-availability');
Route::get('users/lookup', 'Users\LookupController@index')->name('users.lookup');
Expand Down

0 comments on commit fc4b347

Please sign in to comment.