Skip to content

Commit 0e706c9

Browse files
authored
Merge branch 'master' into score-pin-id
2 parents f3017ab + 28bfe59 commit 0e706c9

File tree

121 files changed

+1448
-713
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+1448
-713
lines changed

Diff for: .env.example

+13-10
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ CLIENT_CHECK_VERSION=false
265265
# NOTIFICATION_CLEANUP_MAX_DELETE=50000
266266

267267
# The open source bounty info page/form url
268-
#OS_BOUNTY_URL=http://example.com/bounty_form
268+
# OS_BOUNTY_URL=http://example.com/bounty_form
269269

270270
# OAUTH_MAX_USER_CLIENTS=1
271271

@@ -292,16 +292,16 @@ CLIENT_CHECK_VERSION=false
292292
# PAGINATION_MAX_COUNT=10000
293293

294294
## Limits for the allowed number of simultaneous beatmapset uploads (displayed on the support page: /home/support)
295-
#BEATMAPSET_UPLOAD_ALLOWED=4
296-
#BEATMAPSET_UPLOAD_BONUS_PER_RANKED=1
297-
#BEATMAPSET_UPLOAD_BONUS_PER_RANKED_MAX=2
298-
#BEATMAPSET_UPLOAD_ALLOWED_SUPPORTER=8
299-
#BEATMAPSET_UPLOAD_BONUS_PER_RANKED_SUPPORTER=1
300-
#BEATMAPSET_UPLOAD_BONUS_PER_RANKED_MAX_SUPPORTER=12
295+
# BEATMAPSET_UPLOAD_ALLOWED=4
296+
# BEATMAPSET_UPLOAD_BONUS_PER_RANKED=1
297+
# BEATMAPSET_UPLOAD_BONUS_PER_RANKED_MAX=2
298+
# BEATMAPSET_UPLOAD_ALLOWED_SUPPORTER=8
299+
# BEATMAPSET_UPLOAD_BONUS_PER_RANKED_SUPPORTER=1
300+
# BEATMAPSET_UPLOAD_BONUS_PER_RANKED_MAX_SUPPORTER=12
301301

302-
#RECAPTCHA_SECRET=
303-
#RECAPTCHA_SITEKEY=
304-
#RECAPTCHA_THRESHOLD=
302+
# RECAPTCHA_SECRET=
303+
# RECAPTCHA_SITEKEY=
304+
# RECAPTCHA_THRESHOLD=
305305

306306
# TWITCH_CLIENT_ID=
307307
# TWITCH_CLIENT_SECRET=
@@ -336,3 +336,6 @@ CLIENT_CHECK_VERSION=false
336336

337337
# USER_COUNTRY_CHANGE_MAX_MIXED_MONTHS=2
338338
# USER_COUNTRY_CHANGE_MIN_MONTHS=6
339+
340+
# USER_INACTIVE_DAYS_VERIFICATION=180
341+
# USER_INACTIVE_FORCE_PASSWORD_RESET=false

Diff for: app/Http/Controllers/ScoresController.php

+26-16
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
use App\Models\Score\Best\Model as ScoreBest;
99
use App\Models\Solo\Score as SoloScore;
10-
use App\Models\UserCountryHistory;
1110
use App\Transformers\ScoreTransformer;
1211
use App\Transformers\UserCompactTransformer;
13-
use Carbon\CarbonImmutable;
1412

1513
class ScoresController extends Controller
1614
{
15+
const REPLAY_DOWNLOAD_COUNT_INTERVAL = 86400; // 1 day
16+
1717
public function __construct()
1818
{
1919
parent::__construct();
@@ -52,20 +52,30 @@ public function download($rulesetOrSoloId, $id = null)
5252
abort(404);
5353
}
5454

55-
if (\Auth::user()->getKey() !== $score->user_id) {
56-
$score->user->statistics($score->getMode(), true)->increment('replay_popularity');
57-
58-
$month = CarbonImmutable::now();
59-
$currentMonth = UserCountryHistory::formatDate($month);
60-
61-
$score->user->replaysWatchedCounts()
62-
->firstOrCreate(['year_month' => $currentMonth], ['count' => 0])
63-
->incrementInstance('count');
64-
65-
if ($score instanceof ScoreBest) {
66-
$score->replayViewCount()
67-
->firstOrCreate([], ['play_count' => 0])
68-
->incrementInstance('play_count');
55+
$currentUser = \Auth::user();
56+
if (
57+
!$currentUser->isRestricted()
58+
&& $currentUser->getKey() !== $score->user_id
59+
&& ($currentUser->token()?->client->password_client ?? false)
60+
) {
61+
$countLock = \Cache::lock(
62+
"view:score_replay:{$score->getKey()}:{$currentUser->getKey()}",
63+
static::REPLAY_DOWNLOAD_COUNT_INTERVAL,
64+
);
65+
66+
if ($countLock->get()) {
67+
$score->user->statistics($score->getMode(), true)->increment('replay_popularity');
68+
69+
$currentMonth = format_month_column(new \DateTime());
70+
$score->user->replaysWatchedCounts()
71+
->firstOrCreate(['year_month' => $currentMonth], ['count' => 0])
72+
->incrementInstance('count');
73+
74+
if ($score instanceof ScoreBest) {
75+
$score->replayViewCount()
76+
->firstOrCreate([], ['play_count' => 0])
77+
->incrementInstance('play_count');
78+
}
6979
}
7080
}
7181

Diff for: app/Http/Controllers/SessionsController.php

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public function store()
7777
$forceReactivation = new ForceReactivation($user, $request);
7878

7979
if ($forceReactivation->isRequired()) {
80+
DatadogLoginAttempt::log('password_reset');
8081
$forceReactivation->run();
8182

8283
\Session::flash('password_reset_start', [
@@ -87,6 +88,7 @@ public function store()
8788
return ujs_redirect(route('password-reset'));
8889
}
8990

91+
DatadogLoginAttempt::log(null);
9092
$this->login($user, $remember);
9193

9294
return [

Diff for: app/Http/Controllers/UserCoverPresetsController.php

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4+
// See the LICENCE file in the repository root for full licence text.
5+
6+
namespace App\Http\Controllers;
7+
8+
use App\Models\UserCoverPreset;
9+
use Symfony\Component\HttpFoundation\Response;
10+
11+
class UserCoverPresetsController extends Controller
12+
{
13+
public function __construct()
14+
{
15+
$this->middleware('auth');
16+
17+
parent::__construct();
18+
}
19+
20+
public function batchActivate(): Response
21+
{
22+
$params = get_params(\Request::all(), null, [
23+
'ids:int[]',
24+
'active:bool',
25+
]);
26+
if (!isset($params['active'])) {
27+
abort(422, 'parameter "active" is missing');
28+
}
29+
UserCoverPreset::whereKey($params['ids'] ?? [])->update(['active' => $params['active']]);
30+
31+
return response(null, 204);
32+
}
33+
34+
public function index(): Response
35+
{
36+
priv_check('UserCoverPresetManage')->ensureCan();
37+
38+
return ext_view('user_cover_presets.index', [
39+
'items' => UserCoverPreset::orderBy('id', 'ASC')->get(),
40+
]);
41+
}
42+
43+
public function store(): Response
44+
{
45+
priv_check('UserCoverPresetManage')->ensureCan();
46+
47+
try {
48+
$files = \Request::file('files') ?? [];
49+
foreach ($files as $file) {
50+
$item = \DB::transaction(function () use ($file) {
51+
$item = UserCoverPreset::create();
52+
$item->file()->store($file->getRealPath());
53+
$item->saveOrExplode();
54+
55+
return $item;
56+
});
57+
$hash ??= "#cover-{$item->getKey()}";
58+
}
59+
\Session::flash('popup', osu_trans('user_cover_presets.store.ok'));
60+
} catch (\Throwable $e) {
61+
\Session::flash('popup', osu_trans('user_cover_presets.store.failed', ['error' => $e->getMessage()]));
62+
}
63+
64+
return ujs_redirect(route('user-cover-presets.index').($hash ?? ''));
65+
}
66+
67+
public function update(string $id): Response
68+
{
69+
priv_check('UserCoverPresetManage')->ensureCan();
70+
71+
$item = UserCoverPreset::findOrFail($id);
72+
$params = get_params(\Request::all(), null, [
73+
'file:file',
74+
'active:bool',
75+
], ['null_missing' => true]);
76+
77+
if ($params['file'] !== null) {
78+
$item->file()->store($params['file']);
79+
$item->save();
80+
}
81+
if ($params['active'] !== null) {
82+
$item->update(['active' => $params['active']]);
83+
}
84+
85+
return ujs_redirect(route('user-cover-presets.index').'#cover-'.$item->getKey());
86+
}
87+
}

Diff for: app/Http/Controllers/UsersController.php

-2
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,6 @@ public function show($id, $mode = null)
665665
} else {
666666
$achievements = json_collection(app('medals')->all(), 'Achievement');
667667

668-
$extras = [];
669-
670668
$initialData = [
671669
'achievements' => $achievements,
672670
'current_mode' => $currentMode,

Diff for: app/Jobs/Notifications/BeatmapsetDiscussionQualifiedProblem.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ public function getListeningUserIds(): array
2929

3030
$ids = [];
3131

32-
$notificationOptions = UserNotificationOption
32+
UserNotificationOption
3333
::where(['name' => Notification::BEATMAPSET_DISCUSSION_QUALIFIED_PROBLEM])
3434
->whereNotNull('details')
35-
->get();
36-
37-
foreach ($notificationOptions as $notificationOption) {
38-
if (count(array_intersect($notificationOption->details['modes'] ?? [], $modes)) > 0) {
39-
$ids[] = $notificationOption->user_id;
40-
}
41-
}
35+
->chunkById(1000, function ($options) use (&$ids, $modes) {
36+
foreach ($options as $option) {
37+
if (count(array_intersect($option->details['modes'] ?? [], $modes)) > 0) {
38+
$ids[] = $option->user_id;
39+
}
40+
}
41+
});
4242

4343
return $ids;
4444
}

Diff for: app/Libraries/Search/BeatmapsetSearch.php

+10-4
Original file line numberDiff line numberDiff line change
@@ -425,17 +425,17 @@ private function addTextFilter(BoolQuery $query, string $paramField, array $fiel
425425
private function getPlayedBeatmapIds(?array $rank = null)
426426
{
427427
$query = Solo\Score
428-
::where('user_id', $this->params->user->getKey())
428+
::indexable()
429+
->where('user_id', $this->params->user->getKey())
429430
->whereIn('ruleset_id', $this->getSelectedModes());
430431

431432
if ($rank === null) {
432433
return $query->distinct('beatmap_id')->pluck('beatmap_id');
433434
}
434435

435436
$topScores = [];
436-
$scoreField = ScoreSearchParams::showLegacyForUser($this->params->user)
437-
? 'legacy_total_score'
438-
: 'total_score';
437+
$showLegacyOnly = ScoreSearchParams::showLegacyForUser($this->params->user) ?? false;
438+
$scoreField = $showLegacyOnly ? 'legacy_total_score' : 'total_score';
439439
foreach ($query->get() as $score) {
440440
$prevScore = $topScores[$score->beatmap_id] ?? null;
441441

@@ -445,6 +445,12 @@ private function getPlayedBeatmapIds(?array $rank = null)
445445
}
446446
}
447447

448+
if ($showLegacyOnly) {
449+
foreach ($topScores as $beatmapId => $score) {
450+
$topScores[$beatmapId] = $score->makeLegacyEntry();
451+
}
452+
}
453+
448454
$ret = [];
449455
$rankSet = new Set($rank);
450456
foreach ($topScores as $beatmapId => $score) {

Diff for: app/Libraries/Search/ScoreSearch.php

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public function getQuery(): BoolQuery
5656
$query->mustNot(['term' => ['mods' => $excludedMod]]);
5757
}
5858
}
59+
if ($this->params->excludeWithoutPp === true) {
60+
$query->filter(['exists' => ['field' => 'pp']]);
61+
}
5962

6063
$this->addModsFilter($query);
6164

Diff for: app/Libraries/Search/ScoreSearchParams.php

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class ScoreSearchParams extends SearchParams
2424
public bool $excludeConverts = false;
2525
public ?array $excludeMods = null;
2626
public ?bool $isLegacy = null;
27+
public bool $excludeWithoutPp = false;
2728
public ?array $mods = null;
2829
public ?int $rulesetId = null;
2930
public $size = 50;
@@ -39,6 +40,7 @@ public static function fromArray(array $rawParams): static
3940
$params->beatmapIds = $rawParams['beatmap_ids'] ?? null;
4041
$params->excludeConverts = $rawParams['exclude_converts'] ?? $params->excludeConverts;
4142
$params->excludeMods = $rawParams['exclude_mods'] ?? null;
43+
$params->excludeWithoutPp = $rawParams['exclude_without_pp'] ?? $params->excludeWithoutPp;
4244
$params->isLegacy = $rawParams['is_legacy'] ?? null;
4345
$params->mods = $rawParams['mods'] ?? null;
4446
$params->rulesetId = $rawParams['ruleset_id'] ?? null;

Diff for: app/Libraries/User/CountryChangeTarget.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use App\Models\Tournament;
1111
use App\Models\TournamentRegistration;
1212
use App\Models\User;
13-
use App\Models\UserCountryHistory;
1413
use Carbon\CarbonImmutable;
1514

1615
class CountryChangeTarget
@@ -38,8 +37,8 @@ public static function get(User $user): ?string
3837
->userCountryHistory()
3938
->whereBetween('year_month', [
4039
// one year maximum range. Offset by 1 because the range is inclusive
41-
UserCountryHistory::formatDate($until->subMonths(11)),
42-
UserCountryHistory::formatDate($until),
40+
format_month_column($until->subMonths(11)),
41+
format_month_column($until),
4342
])->distinct()
4443
->orderBy('year_month', 'DESC')
4544
->limit($minMonths)

Diff for: app/Libraries/User/Cover.php

+9-16
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ class Cover
1515

1616
private const AVAILABLE_PRESET_IDS = ['1', '2', '3', '4', '5', '6', '7', '8'];
1717

18-
private ?array $json;
19-
2018
public function __construct(private User $user)
2119
{
2220
}
@@ -32,23 +30,18 @@ public function customUrl(): ?string
3230
return $this->user->customCover()->url();
3331
}
3432

35-
public function presetId(): ?string
33+
public function defaultPresetId(): string
3634
{
37-
if ($this->hasCustomCover()) {
38-
return null;
39-
}
40-
41-
$id = $this->user->getKey();
42-
43-
if ($id === null || $id < 1) {
44-
return null;
45-
}
35+
$id = max(0, $this->user->getKey() ?? 0);
4636

47-
$presetId = (string) $this->user->cover_preset_id;
37+
return static::AVAILABLE_PRESET_IDS[$id % count(static::AVAILABLE_PRESET_IDS)];
38+
}
4839

49-
return static::isValidPresetId($presetId)
50-
? $presetId
51-
: static::AVAILABLE_PRESET_IDS[$id % count(static::AVAILABLE_PRESET_IDS)];
40+
public function presetId(): ?string
41+
{
42+
return $this->hasCustomCover()
43+
? null
44+
: (string) ($this->user->cover_preset_id ?? $this->defaultPresetId());
5245
}
5346

5447
public function set(?string $presetId, ?string $filePath): void

0 commit comments

Comments
 (0)