Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add disband team button #11758

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like the db stuff should be deleted together in a transaction, and the assets should be removed first so there's no dangling stuff if something somehow fails (can just try delete the team again)

}

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
Loading