Skip to content

Commit

Permalink
Merge branch 'master' into team-logo-size
Browse files Browse the repository at this point in the history
  • Loading branch information
notbakaneko authored Dec 20, 2024
2 parents d8ac0a6 + 79a6ee3 commit ee668b1
Show file tree
Hide file tree
Showing 514 changed files with 5,808 additions and 986 deletions.
27 changes: 27 additions & 0 deletions app/Casts/TimestampOrZero.php
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\Casts;

use Carbon\Carbon;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;

/**
* For columns which use unix timestamp as its value and repurpose 0 as null.
*/
class TimestampOrZero implements CastsAttributes
{
public function get($model, string $key, $value, array $attributes)
{
return $value === null || $value === 0 ? null : Carbon::createFromTimestamp($value);
}

public function set($model, string $key, $value, array $attributes)
{
return $value === null ? 0 : $value->getTimestamp();
}
}
4 changes: 2 additions & 2 deletions app/Http/Controllers/BeatmapsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class BeatmapsController extends Controller
{
const DEFAULT_API_INCLUDES = ['beatmapset.ratings', 'failtimes', 'max_combo'];
const DEFAULT_SCORE_INCLUDES = ['user', 'user.country', 'user.cover'];
const DEFAULT_SCORE_INCLUDES = ['user', 'user.country', 'user.cover', 'user.team'];

public function __construct()
{
Expand Down Expand Up @@ -74,7 +74,7 @@ private static function beatmapScores(string $id, ?string $scoreTransformerType,
'type' => $type,
'user' => $currentUser,
]);
$scores = $esFetch->all()->loadMissing(['beatmap', 'user.country', 'processHistory']);
$scores = $esFetch->all()->loadMissing(['beatmap', 'user.country', 'user.team', 'processHistory']);
$userScore = $esFetch->userBest();
$scoreTransformer = new ScoreTransformer($scoreTransformerType);

Expand Down
47 changes: 26 additions & 21 deletions app/Http/Controllers/Chat/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,39 +89,44 @@ public function ack()
* @bodyParam uuid string client-side message identifier which will be sent back in response and websocket json. Example: some-uuid-string
*
* @response {
* "channel": [
* {
* "channel_id": 1234,
* "current_user_attributes": {
* "can_message": true,
* "can_message_error": null,
* "last_read_id": 9150005005
* },
* "name": "peppy",
* "description": "",
* "type": "PM",
* "last_read_id": 9150005005,
* "last_message_id": 9150005005
* }
* ],
* "channel": {
* "channel_id": 1234,
* "description": "",
* "icon": "https://a.ppy.sh/102?1500537068"
* "message_length_limit": 450,
* "moderated": false,
* "name": "peppy",
* "type": "PM",
* "uuid": null,
* "last_message_id": 9150005005,
* "users": [
* 101,
* 102
* ]
* },
* "message": {
* "message_id": 9150005005,
* "sender_id": 102,
* "channel_id": 1234,
* "timestamp": "2018-07-06T06:33:42+00:00",
* "content": "i can haz featured artist plz?",
* "is_action": false,
* "message_id": 9150005005,
* "sender_id": 102,
* "timestamp": "2024-12-23T01:23:45+00:00",
* "type": "plain",
* "uuid": "some-uuid-string",
* "sender": {
* "id": 102,
* "username": "nekodex",
* "profile_colour": "#333333",
* "avatar_url": "https://a.ppy.sh/102?1500537068",
* "country_code": "AU",
* "default_group": "default",
* "id": 102,
* "is_active": true,
* "is_bot": false,
* "is_deleted": false,
* "is_online": true,
* "is_supporter": true
* "last_visit": "2024-12-23T01:23:45+00:00",
* "pm_friends_only": false,
* "profile_colour": "#333333",
* "username": "nekodex",
* }
* },
* "new_channel_id": 1234,
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Forum/TopicsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ public function show($id)
'user.country',
'user.rank',
'user.supporterTagPurchases',
'user.team',
'user.userGroups',
]);

Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/RankingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function index($mode, $type)
$table = (new $class())->getTable();
$ppColumn = $class::ppColumn();
$stats = $class
::with(['user', 'user.country'])
::with(['user', 'user.country', 'user.team'])
->where($ppColumn, '>', 0)
->whereHas('user', function ($userQuery) {
$userQuery->default();
Expand Down Expand Up @@ -307,6 +307,7 @@ public function kudosu()
$page = min(get_int(request('page')) ?? 1, $maxPage);

$scores = User::default()
->with('team')
->orderBy('osu_kudostotal', 'desc')
->paginate(static::PAGE_SIZE, ['*'], 'page', $page, $maxResults);

Expand Down
53 changes: 53 additions & 0 deletions app/Http/Controllers/Teams/MembersController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?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\TeamMember;
use Symfony\Component\HttpFoundation\Response;

class MembersController extends Controller
{
public function __construct()
{
parent::__construct();

$this->middleware('auth');
}

public function destroy(string $teamId, string $userId): Response
{
$teamMember = TeamMember::where([
'team_id' => $teamId,
'user_id' => $userId,
])->firstOrFail();

if ($teamMember->user_id === \Auth::user()->getKey()) {
abort(422, 'can not remove self from team');
}

priv_check('TeamUpdate', $teamMember->team)->ensureCan();

$teamMember->delete();
\Session::flash('popup', osu_trans('teams.members.destroy.success'));

return response(null, 204);
}

public function index(string $teamId): Response
{
$team = Team::findOrFail($teamId);

priv_check('TeamUpdate', $team)->ensureCan();

$team->load('members.user');

return ext_view('teams.members.index', compact('team'));
}
}
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
1 change: 1 addition & 0 deletions app/Http/Controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,7 @@ private function showUserIncludes()
'statistics.country_rank',
'statistics.rank',
'statistics.variants',
'team',
'user_achievements',
];

Expand Down
4 changes: 1 addition & 3 deletions app/Jobs/Notifications/BeatmapOwnerChange.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class BeatmapOwnerChange extends BroadcastNotificationBase

protected $beatmap;
protected $beatmapset;
protected $user;

public static function getMailLink(Notification $notification): string
{
Expand All @@ -32,7 +31,6 @@ public function __construct(Beatmap $beatmap, User $source)

$this->beatmap = $beatmap;
$this->beatmapset = $beatmap->beatmapset;
$this->user = $beatmap->user;
}

public function getDetails(): array
Expand All @@ -48,7 +46,7 @@ public function getDetails(): array

public function getListeningUserIds(): array
{
return [$this->user->getKey()];
return $this->beatmap->beatmapOwners()->pluck('user_id')->all();
}

public function getNotifiable()
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/Notifications/BroadcastNotificationBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function handle()

$pushReceiverIds = [];
$notification->getConnection()->transaction(function () use ($deliverySettings, $notification, &$pushReceiverIds) {
$timestamp = (string) $this->getTimestamp();
$timestamp = $this->getTimestamp()->format('Y-m-d H:i:s');
$notificationId = $notification->getKey();
$tempUserNotification = new UserNotification();

Expand Down
1 change: 1 addition & 0 deletions app/Models/DeletedUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

class DeletedUser extends User
{
public null $team = null;
public $user_avatar = null;
public $username = '[deleted user]';

Expand Down
16 changes: 3 additions & 13 deletions app/Models/Forum/Forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace App\Models\Forum;

use App\Casts\TimestampOrZero;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
Expand All @@ -26,7 +27,7 @@
* @property string $forum_image
* @property int $forum_last_post_id
* @property string $forum_last_post_subject
* @property int $forum_last_post_time
* @property \Carbon\Carbon|null $forum_last_post_time
* @property string $forum_last_poster_colour
* @property int $forum_last_poster_id
* @property string $forum_last_poster_name
Expand Down Expand Up @@ -67,10 +68,9 @@ class Forum extends Model
'allow_topic_covers' => 'boolean',
'enable_indexing' => 'boolean',
'enable_sigs' => 'boolean',
'forum_last_post_time' => 'datetime',
'forum_last_post_time' => TimestampOrZero::class,
'moderator_groups' => 'array',
];
protected $dateFormat = 'U';
protected $primaryKey = 'forum_id';
protected $table = 'phpbb_forums';

Expand Down Expand Up @@ -242,16 +242,6 @@ public function setForumLastPosterColourAttribute($value)
$this->attributes['forum_last_poster_colour'] = ltrim($value, '#');
}

public function getForumLastPostTimeAttribute($value)
{
return get_time_or_null($value);
}

public function setForumLastPostTimeAttribute($value)
{
$this->attributes['forum_last_post_time'] = get_timestamp_or_zero($value);
}

// feature forum shall have extra features like sorting and voting
public function isFeatureForum()
{
Expand Down
27 changes: 5 additions & 22 deletions app/Models/Forum/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace App\Models\Forum;

use App\Casts\TimestampOrZero;
use App\Exceptions\ModelNotSavedException;
use App\Jobs\EsDocument;
use App\Jobs\MarkNotificationsRead;
Expand Down Expand Up @@ -48,7 +49,7 @@
* @property int $post_reported
* @property string $post_subject
* @property mixed $post_text
* @property int $post_time
* @property \Carbon\Carbon|null $post_time
* @property string $post_username
* @property int $poster_id
* @property string $poster_ip
Expand Down Expand Up @@ -81,8 +82,10 @@ class Post extends Model implements AfterCommit, Indexable, Traits\ReportableInt
public $timestamps = false;

protected $casts = [
'post_edit_locked' => 'boolean',
'post_approved' => 'boolean',
'post_edit_locked' => 'boolean',
'post_edit_time' => TimestampOrZero::class,
'post_time' => TimestampOrZero::class,
];

private $normalizedUsers = [];
Expand Down Expand Up @@ -156,26 +159,6 @@ public function getPostEditUserAttribute($value)
}
}

public function setPostTimeAttribute($value)
{
$this->attributes['post_time'] = get_timestamp_or_zero($value);
}

public function getPostTimeAttribute($value)
{
return get_time_or_null($value);
}

public function setPostEditTimeAttribute($value)
{
$this->attributes['post_edit_time'] = get_timestamp_or_zero($value);
}

public function getPostEditTimeAttribute($value)
{
return get_time_or_null($value);
}

/**
* Gets a preview of the post_text by stripping anything that
* looks like bbcode or html.
Expand Down
Loading

0 comments on commit ee668b1

Please sign in to comment.