forked from ppy/osu-web
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
453 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
// 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. | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers\Teams; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\Team; | ||
use App\Models\TeamApplication; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class ApplicationsController extends Controller | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
|
||
$this->middleware('auth'); | ||
} | ||
|
||
public function accept(string $teamId, string $id): Response | ||
{ | ||
\DB::transaction(function () use ($id, $teamId) { | ||
$team = Team::findOrFail($teamId); | ||
$application = $team->applications()->findOrFail($id); | ||
|
||
priv_check('TeamApplicationAccept', $application)->ensureCan(); | ||
|
||
$application->delete(); | ||
$team->members()->create(['user_id' => $application->user_id]); | ||
}); | ||
|
||
\Session::flash('popup', osu_trans('teams.applications.accept.ok')); | ||
|
||
return response(null, 204); | ||
} | ||
|
||
public function destroy(string $teamId, string $id): Response | ||
{ | ||
$currentUser = \Auth::user(); | ||
TeamApplication::where('team_id', $teamId)->findOrFail($currentUser->getKey())->delete(); | ||
\Session::flash('popup', osu_trans('teams.applications.destroy.ok')); | ||
|
||
return response(null, 204); | ||
} | ||
|
||
public function reject(string $teamId, string $id): Response | ||
{ | ||
TeamApplication::where('team_id', $teamId)->findOrFail($id)->delete(); | ||
\Session::flash('popup', osu_trans('teams.applications.reject.ok')); | ||
|
||
return response(null, 204); | ||
} | ||
|
||
public function store(string $teamId): Response | ||
{ | ||
$team = Team::findOrFail($teamId); | ||
priv_check('TeamApplicationStore', $team)->ensureCan(); | ||
|
||
$team->applications()->createOrFirst(['user_id' => \Auth::id()]); | ||
\Session::flash('popup', osu_trans('teams.applications.store.ok')); | ||
|
||
return response(null, 204); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
// 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. | ||
|
||
namespace App\Jobs\Notifications; | ||
|
||
use App\Models\Notification; | ||
use App\Models\TeamMember; | ||
use App\Models\User; | ||
|
||
class TeamApplicationAccept extends BroadcastNotificationBase | ||
{ | ||
const DELIVERY_MODE_DEFAULTS = ['mail' => true, 'push' => true]; | ||
|
||
protected $achievement; | ||
|
||
public static function getMailGroupingKey(Notification $notification): string | ||
{ | ||
$base = parent::getMailGroupingKey($notification); | ||
|
||
return "{$base}-{$notification->details['achievement_id']}-{$notification->source_user_id}"; | ||
} | ||
|
||
public static function getMailLink(Notification $notification): string | ||
{ | ||
return route('teams.show', [ | ||
'mode' => $notification->notifiable_id, | ||
]).'#medals'; | ||
} | ||
|
||
public function __construct(private TeamMember $teamMember, User $source) | ||
{ | ||
parent::__construct($source); | ||
|
||
$this->achievement = $achievement; | ||
} | ||
|
||
public function getDetails(): array | ||
{ | ||
return [ | ||
'achievement_id' => $this->achievement->getKey(), | ||
'achievement_mode' => $this->achievement->mode, | ||
'cover_url' => $this->achievement->iconUrl(), | ||
'slug' => $this->achievement->slug, | ||
'title' => $this->achievement->name, | ||
'description' => $this->achievement->description, | ||
'user_id' => $this->source->getKey(), | ||
]; | ||
} | ||
|
||
public function getListeningUserIds(): array | ||
{ | ||
return [$this->source->getKey()]; | ||
} | ||
|
||
public function getNotifiable() | ||
{ | ||
return $this->teamMember; | ||
} | ||
|
||
public function getReceiverIds(): array | ||
{ | ||
return [$this->teamMember->getKey()]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
// 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. | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
|
||
class TeamApplication extends Model | ||
{ | ||
public $incrementing = false; | ||
|
||
protected $primaryKey = 'user_id'; | ||
|
||
public function team(): BelongsTo | ||
{ | ||
return $this->belongsTo(Team::class); | ||
} | ||
|
||
public function user(): BelongsTo | ||
{ | ||
return $this->belongsTo(User::class, 'user_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
// 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. | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Models\Team; | ||
use App\Models\TeamMember; | ||
use App\Models\User; | ||
|
||
class TeamMemberFactory extends Factory | ||
{ | ||
protected $model = TeamMember::class; | ||
|
||
public function definition(): array | ||
{ | ||
return [ | ||
'team_id' => Team::factory(), | ||
'user_id' => User::factory(), | ||
]; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
database/migrations/2025_01_15_000001_create_team_applications.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
// 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. | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
public function up(): void | ||
{ | ||
Schema::create('team_applications', function (Blueprint $table) { | ||
$table->unsignedBigInteger('user_id')->nullable(false); | ||
$table->unsignedBigInteger('team_id')->nullable(false); | ||
$table->timestampsTz(); | ||
|
||
$table->primary('user_id'); | ||
$table->index('team_id'); | ||
}); | ||
} | ||
|
||
public function down(): void | ||
{ | ||
Schema::dropIfExists('team_applications'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.