Skip to content

Commit

Permalink
Merge branch 'master' into contest-judging
Browse files Browse the repository at this point in the history
  • Loading branch information
venix12 authored Jan 2, 2024
2 parents 6bb71a9 + bbbdf20 commit ae9fc31
Show file tree
Hide file tree
Showing 468 changed files with 3,838 additions and 3,485 deletions.
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ DB_USERNAME=osuweb

OSU_API_KEY=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
# BROADCAST_DRIVER=redis
# CACHE_DRIVER=redis
# SESSION_DRIVER=redis
# SESSION_DOMAIN=
# SESSION_SECURE_COOKIE=false

Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ env:
APP_ENV: testing
APP_KEY: base64:q7U5qyAkedR1F6UhN0SQlUxBpAMDyfHy3NNFkqmiMqA=
APP_URL: http://localhost:8000
CACHE_DRIVER: redis
DB_HOST: 127.0.0.1
ES_SOLO_SCORES_HOST: http://localhost:9200
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -87,7 +86,6 @@ env:
HQZdh/ScL40oDGb6HRdKan0CAwEAAQ==
-----END PUBLIC KEY-----
REDIS_HOST: 127.0.0.1
SESSION_DRIVER: redis
SHOPIFY_DOMAIN: notarealdomainortld
SHOPIFY_STOREFRONT_TOKEN: notreal
SLACK_ENDPOINT: https://myconan.net/null/
Expand Down
41 changes: 41 additions & 0 deletions app/Casts/LegacyFilename.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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 Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Database\Eloquent\Model;

class LegacyFilename implements CastsAttributes
{
public static function makeFromAttributes(?array $attributes): ?string
{
if (!isset($attributes['hash'])) {
return null;
}

$filename = $attributes['hash'];
if (isset($attributes['ext'])) {
$filename .= ".{$attributes['ext']}";
}

return $filename;
}

public function get(Model $model, string $key, mixed $value, array $attributes)
{
return static::makeFromAttributes($attributes);
}

public function set(Model $model, string $key, mixed $value, array $attributes)
{
return [
'ext' => null,
'hash' => $value,
];
}
}
2 changes: 1 addition & 1 deletion app/Console/Commands/BuildsUpdatePropagationHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function handle()
$date = Carbon::now();

$builds = Build::propagationHistory()
->whereIn('stream_id', config('osu.changelog.update_streams'))
->whereIn('stream_id', $GLOBALS['cfg']['osu']['changelog']['update_streams'])
->get();

foreach ($builds as $build) {
Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/DbCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ class DbCreate extends Command

public function handle()
{
$defaultConnection = config('database.connections.mysql');
$defaultConnection = $GLOBALS['cfg']['database']['connections']['mysql'];

$dsn = isset($defaultConnection['unix_socket'])
? "mysql:unix_socket={$defaultConnection['unix_socket']}"
: "mysql:host={$defaultConnection['host']};port={$defaultConnection['port']}";

$pdo = new PDO($dsn, $defaultConnection['username'], $defaultConnection['password']);

foreach (config('database.connections') as $connection) {
foreach ($GLOBALS['cfg']['database']['connections'] as $connection) {
$db = $connection['database'];

$this->info("Creating database '{$db}'");
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/EsCreateSearchBlacklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class EsCreateSearchBlacklist extends Command
*/
public function handle()
{
$alias = config('osu.elasticsearch.prefix').'blacklist';
$alias = $GLOBALS['cfg']['osu']['elasticsearch']['prefix'].'blacklist';
$client = Es::getClient();

/** @var array $response The type-hint in the doc is wrong. */
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/ForumTopicCoversCleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function handle()

$deleted++;
$progress->advance();
$cover->deleteWithFile();
$cover->delete();
}
});

Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/MigrateFreshAllCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function handle()
return 1;
}

$connections = config('database.connections');
$connections = $GLOBALS['cfg']['database']['connections'];

$this->warn('This will drop tables in the following databases:');

Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/ModdingRankCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function getStats(Ruleset $ruleset)
->count();

return [
'availableQuota' => config('osu.beatmapset.rank_per_day') - $rankedTodayCount,
'availableQuota' => $GLOBALS['cfg']['osu']['beatmapset']['rank_per_day'] - $rankedTodayCount,
'inQueue' => Beatmapset::toBeRanked($ruleset)->count(),
'rankedToday' => $rankedTodayCount,
];
Expand Down Expand Up @@ -92,7 +92,7 @@ private function rankAll(Ruleset $ruleset)
return;
}

$toRankLimit = min(config('osu.beatmapset.rank_per_run'), $stats['availableQuota']);
$toRankLimit = min($GLOBALS['cfg']['osu']['beatmapset']['rank_per_run'], $stats['availableQuota']);

$toBeRanked = Beatmapset::tobeRanked($ruleset)
->orderBy('queued_at', 'ASC')
Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/NotificationsCleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class NotificationsCleanup extends Command

public function handle()
{
$total = config('osu.notification.cleanup.max_delete_per_run');
$total = $GLOBALS['cfg']['osu']['notification']['cleanup']['max_delete_per_run'];

if ($total === 0) {
return;
Expand All @@ -46,7 +46,7 @@ public function handle()

for ($i = 0; $i < $loops; $i++) {
$deleted = Notification::where('id', '<', $maxNotificationId)->limit($perLoop)->delete();
Datadog::increment(config('datadog-helper.prefix_web').'.notifications_cleanup.notifications', 1, null, $deleted);
Datadog::increment($GLOBALS['cfg']['datadog-helper']['prefix_web'].'.notifications_cleanup.notifications', 1, null, $deleted);

$deletedTotal += $deleted;
}
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/OAuthDeleteExpiredTokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class OAuthDeleteExpiredTokens extends Command

public function handle()
{
$this->expiredBefore = now()->subDays(config('osu.oauth.retain_expired_tokens_days'));
$this->expiredBefore = now()->subDays($GLOBALS['cfg']['osu']['oauth']['retain_expired_tokens_days']);
$this->line("Deleting before {$this->expiredBefore}");

$this->deleteAuthCodes();
Expand Down
6 changes: 3 additions & 3 deletions app/Console/Commands/UserNotificationsCleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class UserNotificationsCleanup extends Command

public function handle()
{
$total = config('osu.notification.cleanup.max_delete_per_run');
$total = $GLOBALS['cfg']['osu']['notification']['cleanup']['max_delete_per_run'];

if ($total === 0) {
return;
Expand All @@ -27,7 +27,7 @@ public function handle()
$perLoop = min($total, 10000);
$loops = $total / $perLoop;

$createdBefore = now()->subDays(config('osu.notification.cleanup.keep_days'));
$createdBefore = now()->subDays($GLOBALS['cfg']['osu']['notification']['cleanup']['keep_days']);
$this->line("Deleting user notifications before {$createdBefore}");

$progress = $this->output->createProgressBar($total);
Expand Down Expand Up @@ -59,7 +59,7 @@ public function handle()
);
$deleted = count($notificationIds);
$deletedTotal += $deleted;
Datadog::increment(config('datadog-helper.prefix_web').'.notifications_cleanup.user_notifications', 1, null, $deleted);
Datadog::increment($GLOBALS['cfg']['datadog-helper']['prefix_web'].'.notifications_cleanup.user_notifications', 1, null, $deleted);
$progress->advance($deleted);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Events/NotificationEventBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public static function generateChannelName($notifiable, $subtype)

public function __construct()
{
$this->broadcastQueue = config('osu.notification.queue_name');
$this->broadcastQueue = $GLOBALS['cfg']['osu']['notification']['queue_name'];
}
}
21 changes: 4 additions & 17 deletions app/Events/UserSessionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

class UserSessionEvent extends NotificationEventBase
{
public $action;
public $data;
public $userId;
private function __construct(public $action, public $userId, public $data)
{
parent::__construct();
}

public static function newLogout($userId, $keys)
{
Expand All @@ -30,20 +31,6 @@ public static function newVerified($userId, $key)
return new static('verified', $userId, compact('key'));
}

/**
* Create a new event instance.
*
* @return void
*/
private function __construct($action, $userId, $data)
{
parent::__construct();

$this->action = $action;
$this->userId = $userId;
$this->data = $data;
}

public function broadcastAs()
{
return $this->action;
Expand Down
14 changes: 5 additions & 9 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace App\Exceptions;

use App\Libraries\UserVerification;
use App\Libraries\SessionVerification;
use Auth;
use Illuminate\Auth\Access\AuthorizationException as LaravelAuthorizationException;
use Illuminate\Auth\AuthenticationException;
Expand Down Expand Up @@ -99,7 +99,8 @@ public function report(Throwable $e)
return;
}

if (config('sentry.dsn')) {
// Fallback in case error happening before config is initialised
if ($GLOBALS['cfg']['sentry']['dsn'] ?? false) {
$this->reportWithSentry($e);
}

Expand All @@ -121,7 +122,7 @@ public function render($request, Throwable $e)
}

if ($e instanceof VerificationRequiredException) {
return $this->unverified();
return SessionVerification\Controller::initiate();
}

if ($e instanceof AuthenticationException) {
Expand All @@ -134,7 +135,7 @@ public function render($request, Throwable $e)

$isJsonRequest = is_json_request();

if (config('app.debug') || ($isJsonRequest && static::isOAuthServerException($e))) {
if ($GLOBALS['cfg']['app']['debug'] || ($isJsonRequest && static::isOAuthServerException($e))) {
$response = parent::render($request, $e);
} else {
$message = static::exceptionMessage($e);
Expand Down Expand Up @@ -166,11 +167,6 @@ protected function unauthenticated($request, AuthenticationException $exception)
return ext_view('users.login', null, null, 401);
}

protected function unverified()
{
return UserVerification::fromCurrentRequest()->initiate();
}

private function reportWithSentry($e)
{
if (Auth::check()) {
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Account/GithubUsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public function destroy()
private function makeGithubOAuthProvider(): GithubProvider
{
return new GithubProvider([
'clientId' => config('osu.github.client_id'),
'clientSecret' => config('osu.github.client_secret'),
'clientId' => $GLOBALS['cfg']['osu']['github']['client_id'],
'clientSecret' => $GLOBALS['cfg']['osu']['github']['client_secret'],
]);
}
}
16 changes: 8 additions & 8 deletions app/Http/Controllers/Account/SessionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
namespace App\Http\Controllers\Account;

use App\Http\Controllers\Controller;
use Auth;
use Request;
use App\Libraries\Session\Store as SessionStore;

class SessionsController extends Controller
{
Expand All @@ -21,15 +20,16 @@ public function __construct()

public function destroy($id)
{
if (!Auth::check()) {
abort(403);
}

if (Request::session()->isCurrentSession($id)) {
if (\Session::getId() === $id) {
// current session
logout();
} else {
Request::session()->destroyUserSession($id);
$session = SessionStore::findOrNew($id);
if ($session->userId() === \Auth::user()->getKey()) {
$session->delete();
} else {
abort(404);
}
}

return response([], 204);
Expand Down
Loading

0 comments on commit ae9fc31

Please sign in to comment.