Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into score-legacy-toggle-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
nanaya committed Jan 29, 2024
2 parents 9457af8 + c696378 commit e7ed418
Show file tree
Hide file tree
Showing 318 changed files with 4,383 additions and 2,990 deletions.
4 changes: 2 additions & 2 deletions .env.dusk.local.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
APP_KEY=
APP_ENV=testing

APP_URL=http://localhost:8000
NOTIFICATION_ENDPOINT=ws://notification-server-dusk:2345
APP_URL=http://nginx:8008
NOTIFICATION_ENDPOINT=ws://nginx:8008/home/notifications/feed

DB_DATABASE=osu_test
DB_DATABASE_CHAT=osu_chat_test
Expand Down
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ CLIENT_CHECK_VERSION=false
# SCORES_ES_CACHE_DURATION=
# SCORES_EXPERIMENTAL_RANK_AS_DEFAULT=false
# SCORES_EXPERIMENTAL_RANK_AS_EXTRA=false
# SCORES_PROCESSING_QUEUE=osu-queue:score-statistics
# SCORES_RANK_CACHE_LOCAL_SERVER=0
# SCORES_RANK_CACHE_MIN_USERS=35000
# SCORES_RANK_CACHE_SERVER_URL=
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
- name: Install js dependencies
run: yarn --frozen-lockfile

- run: 'yarn lint --max-warnings 94 > /dev/null'
- run: 'yarn lint --max-warnings 89 > /dev/null'

- run: ./bin/update_licence.sh -nf

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ _ide_helper.php
/vendor
composer.phar

# docker related local files
/compose.override.yml

# OS-specific crud
.DS_Store
Thumbs.db
Expand Down
8 changes: 1 addition & 7 deletions SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ Start docker in background:

```
bin/docker_dev.sh -d
# alternatively
# docker compose up -d
```

Start single docker service:
Expand Down Expand Up @@ -188,13 +186,9 @@ docker compose run --rm php mysql
Docker images need to be occasionally updated to make sure they're running latest version of the packages.

```
docker compose down --rmi all
docker compose pull
docker compose build --pull
docker compose build --no-cache
```

(don't use `build --no-cache` as it'll end up rebuilding `php` image multiple times)

#### Faster php commands

When frequently running commands, doing `docker compose run` may feel a little bit slow. An alternative is by running the command in existing instance instead. For example to run `artisan tinker`:
Expand Down
19 changes: 19 additions & 0 deletions app/Enums/ScoreRank.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

namespace App\Enums;

enum ScoreRank: string
{
case A = 'A';
case B = 'B';
case C = 'C';
case D = 'D';
case F = 'F';
case S = 'S';
case SH = 'SH';
case X = 'X';
case XH = 'XH';
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/BeatmapsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public function soloScores($id)
'type' => $type,
'user' => $currentUser,
]);
$scores = $esFetch->all()->loadMissing(['beatmap', 'performance', 'user.country', 'user.userProfileCustomization']);
$scores = $esFetch->all()->loadMissing(['beatmap', 'user.country', 'user.userProfileCustomization']);
$userScore = $esFetch->userBest();
$scoreTransformer = new ScoreTransformer(ScoreTransformer::TYPE_SOLO);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,13 @@ public function update($roomId, $playlistItemId, $tokenId)
});

$score = $scoreLink->score;
$transformer = ScoreTransformer::newSolo();
if ($score->wasRecentlyCreated) {
$scoreJson = json_item($score, $transformer);
$score::queueForProcessing($scoreJson);
$score->queueForProcessing();
}

return json_item(
$scoreLink,
$transformer,
ScoreTransformer::newSolo(),
[
...ScoreTransformer::MULTIPLAYER_BASE_INCLUDES,
'position',
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/PasswordResetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use App\Libraries\User\PasswordResetData;
use App\Models\User;
use App\Models\UserAccountHistory;
use Carbon\CarbonImmutable;

class PasswordResetController extends Controller
{
Expand Down Expand Up @@ -124,6 +125,7 @@ public function update()
}

$user->validatePasswordConfirmation();
$params['user']['user_lastvisit'] = CarbonImmutable::now();
if ($user->update($params['user'])) {
$user->resetSessions();
$this->login($user);
Expand Down
5 changes: 5 additions & 0 deletions app/Http/Controllers/SessionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public function store()
if ($forceReactivation->isRequired()) {
$forceReactivation->run();

\Session::flash('password_reset_start', [
'reason' => $forceReactivation->getReason(),
'username' => $username,
]);

return ujs_redirect(route('password-reset'));
}

Expand Down
5 changes: 2 additions & 3 deletions app/Http/Controllers/Solo/ScoresController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ public function store($beatmapId, $tokenId)
return $score;
});

$scoreJson = json_item($score, new ScoreTransformer(ScoreTransformer::TYPE_SOLO));
if ($score->wasRecentlyCreated) {
$score::queueForProcessing($scoreJson);
$score->queueForProcessing();
}

return $scoreJson;
return json_item($score, new ScoreTransformer(ScoreTransformer::TYPE_SOLO));
}
}
4 changes: 3 additions & 1 deletion app/Http/Controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ public function scores($_userId, $type)
*
* See [Get User](#get-user).
*
* `session_verified` attribute is included.
* Additionally, `statistics_rulesets` is included, containing statistics for all rulesets.
*
* @urlParam mode string [Ruleset](#ruleset). User default mode will be used if not specified. Example: osu
Expand All @@ -548,7 +549,7 @@ public function scores($_userId, $type)
*/
public function me($mode = null)
{
$user = auth()->user();
$user = \Auth::user();
$currentMode = $mode ?? $user->playmode;

if (!Beatmap::isModeValid($currentMode)) {
Expand All @@ -561,6 +562,7 @@ public function me($mode = null)
$user,
(new UserTransformer())->setMode($currentMode),
[
'session_verified',
...$this->showUserIncludes(),
...array_map(
fn (string $ruleset) => "statistics_rulesets.{$ruleset}",
Expand Down
1 change: 1 addition & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Kernel extends HttpKernel
Middleware\SetLocaleApi::class,
Middleware\CheckUserBanStatus::class,
Middleware\UpdateUserLastvisit::class,
Middleware\VerifyUserAlways::class,
],
'web' => [
Middleware\StripCookies::class,
Expand Down
11 changes: 8 additions & 3 deletions app/Http/Middleware/AuthApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace App\Http\Middleware;

use App\Libraries\SessionVerification;
use Closure;
use Illuminate\Auth\AuthenticationException;
use Laravel\Passport\ClientRepository;
Expand Down Expand Up @@ -95,10 +96,14 @@ private function validTokenFromRequest($psr)
}

if ($user !== null) {
auth()->setUser($user);
\Auth::setUser($user);
$user->withAccessToken($token);
// this should match osu-notification-server OAuthVerifier
$user->markSessionVerified();

if ($token->isVerified()) {
$user->markSessionVerified();
} else {
SessionVerification\Helper::issue($token, $user, true);
}
}

return $token;
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Middleware/UpdateUserLastvisit.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace App\Http\Middleware;

use App\Libraries\SessionVerification;
use App\Models\Country;
use Carbon\Carbon;
use Closure;
Expand All @@ -30,7 +31,7 @@ public function handle($request, Closure $next)
if ($shouldUpdate) {
$isInactive = $user->isInactive();
if ($isInactive) {
$isVerified = $user->isSessionVerified();
$isVerified = SessionVerification\Helper::currentSession()->isVerified();
}

if (!$isInactive || $isVerified) {
Expand Down
1 change: 1 addition & 0 deletions app/Http/Middleware/VerifyUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class VerifyUser
'notifications_controller@endpoint' => true,
'sessions_controller@destroy' => true,
'sessions_controller@store' => true,
'users_controller@me' => true,
'wiki_controller@image' => true,
'wiki_controller@show' => true,
'wiki_controller@sitemap' => true,
Expand Down
2 changes: 0 additions & 2 deletions app/Jobs/RemoveBeatmapsetSoloScores.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use App\Models\Beatmap;
use App\Models\Beatmapset;
use App\Models\Solo\Score;
use App\Models\Solo\ScorePerformance;
use DB;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
Expand Down Expand Up @@ -68,7 +67,6 @@ private function deleteScores(Collection $scores): void
$scoresQuery->update(['preserve' => false]);
$this->scoreSearch->queueForIndex($this->schemas, $ids);
DB::transaction(function () use ($ids, $scoresQuery): void {
ScorePerformance::whereKey($ids)->delete();
$scoresQuery->delete();
});
}
Expand Down
45 changes: 45 additions & 0 deletions app/Libraries/OAuth/EncodeToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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\Libraries\OAuth;

use App\Models\OAuth\Token;
use Defuse\Crypto\Crypto;
use Firebase\JWT\JWT;
use Laravel\Passport\Passport;
use Laravel\Passport\RefreshToken;

class EncodeToken
{
public static function encodeAccessToken(Token $token): string
{
$privateKey = $GLOBALS['cfg']['passport']['private_key']
?? file_get_contents(Passport::keyPath('oauth-private.key'));

return JWT::encode([
'aud' => $token->client_id,
'exp' => $token->expires_at->timestamp,
'iat' => $token->created_at->timestamp, // issued at
'jti' => $token->getKey(),
'nbf' => $token->created_at->timestamp, // valid after
'sub' => $token->user_id,
'scopes' => $token->scopes,
], $privateKey, 'RS256');
}

public static function encodeRefreshToken(RefreshToken $refreshToken, Token $accessToken): string
{
return Crypto::encryptWithPassword(json_encode([
'client_id' => (string) $accessToken->client_id,
'refresh_token_id' => $refreshToken->getKey(),
'access_token_id' => $accessToken->getKey(),
'scopes' => $accessToken->scopes,
'user_id' => $accessToken->user_id,
'expire_time' => $refreshToken->expires_at->timestamp,
]), \Crypt::getKey());
}
}
40 changes: 40 additions & 0 deletions app/Libraries/OAuth/RefreshTokenGrant.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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\Libraries\OAuth;

use App\Models\OAuth\Token;
use League\OAuth2\Server\Grant\RefreshTokenGrant as BaseRefreshTokenGrant;
use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
use Psr\Http\Message\ServerRequestInterface;

class RefreshTokenGrant extends BaseRefreshTokenGrant
{
private ?array $oldRefreshToken = null;

public function respondToAccessTokenRequest(
ServerRequestInterface $request,
ResponseTypeInterface $responseType,
\DateInterval $accessTokenTTL
) {
$refreshTokenData = parent::respondToAccessTokenRequest($request, $responseType, $accessTokenTTL);

// Copy previous verification state
$accessToken = (new \ReflectionProperty($refreshTokenData, 'accessToken'))->getValue($refreshTokenData);
Token::where('id', $accessToken->getIdentifier())->update([
'verified' => Token::select('verified')->find($this->oldRefreshToken['access_token_id'])->verified,
]);
$this->oldRefreshToken = null;

return $refreshTokenData;
}

protected function validateOldRefreshToken(ServerRequestInterface $request, $clientId)
{
return $this->oldRefreshToken = parent::validateOldRefreshToken($request, $clientId);
}
}
16 changes: 0 additions & 16 deletions app/Libraries/ScoreRank.php

This file was deleted.

4 changes: 2 additions & 2 deletions app/Libraries/Search/ScoreSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public function getQuery(): BoolQuery
$beforeTotalScore = $this->params->beforeTotalScore;
if ($beforeTotalScore === null && $this->params->beforeScore !== null) {
$beforeTotalScore = $this->params->beforeScore->isLegacy()
? $this->params->beforeScore->data->legacyTotalScore
: $this->params->beforeScore->data->totalScore;
? $this->params->beforeScore->legacy_total_score
: $this->params->beforeScore->total_score;
}
if ($beforeTotalScore !== null) {
$scoreQuery = (new BoolQuery())->shouldMatch(1);
Expand Down
9 changes: 7 additions & 2 deletions app/Libraries/Search/ScoreSearchParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,14 @@ public static function fromArray(array $rawParams): static
return $params;
}

public static function showLegacyForUser(?User $user): bool
/**
* This returns value for isLegacy based on user preference
*/
public static function showLegacyForUser(?User $user): null | true
{
return $user?->userProfileCustomization?->legacy_score_only ?? UserProfileCustomization::DEFAULT_LEGACY_ONLY_ATTRIBUTE;
return $user?->userProfileCustomization?->legacy_score_only ?? UserProfileCustomization::DEFAULT_LEGACY_ONLY_ATTRIBUTE
? true
: null;
}

public function getCountryCode(): string
Expand Down
Loading

0 comments on commit e7ed418

Please sign in to comment.