diff --git a/app/Http/Controllers/TeamsController.php b/app/Http/Controllers/TeamsController.php index 0792c39db0b..92b6de5f8f8 100644 --- a/app/Http/Controllers/TeamsController.php +++ b/app/Http/Controllers/TeamsController.php @@ -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); diff --git a/app/Models/Team.php b/app/Models/Team.php index a4a324052a3..7db9acd9690 100644 --- a/app/Models/Team.php +++ b/app/Models/Team.php @@ -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( diff --git a/resources/lang/en/teams.php b/resources/lang/en/teams.php index ae637b63d52..a3984e14dff 100644 --- a/resources/lang/en/teams.php +++ b/resources/lang/en/teams.php @@ -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', @@ -66,6 +70,7 @@ 'show' => [ 'bar' => [ + 'destroy' => 'Disband Team', 'part' => 'Leave Team', ], diff --git a/resources/views/teams/show.blade.php b/resources/views/teams/show.blade.php index ed4c2d6e2ce..ae9e5927d8e 100644 --- a/resources/views/teams/show.blade.php +++ b/resources/views/teams/show.blade.php @@ -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', [ @@ -76,6 +79,18 @@ class="btn-circle btn-circle--page-toggle" @if (!$buttons->isEmpty())
+ @if ($buttons->contains('destroy')) +
+ + +
+ @endif @if ($buttons->contains('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');