Skip to content

Commit

Permalink
Merge branch 'master' into laravel-10-migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
nanaya authored Aug 16, 2023
2 parents 9feee59 + d81acd8 commit c19f0a4
Show file tree
Hide file tree
Showing 240 changed files with 1,847 additions and 1,671 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/BeatmapPacksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class BeatmapPacksController extends Controller

public function index()
{
$type = presence(Request::input('type')) ?? BeatmapPack::DEFAULT_TYPE;
$type = presence(get_string(Request::input('type'))) ?? BeatmapPack::DEFAULT_TYPE;
$packs = BeatmapPack::getPacks($type);
if ($packs === null) {
abort(404);
Expand Down
34 changes: 18 additions & 16 deletions app/Libraries/UsernameValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@

namespace App\Libraries;

use App\Models\Beatmap;
use App\Models\Beatmapset;
use App\Models\RankHighest;
use App\Models\User;
use App\Models\UserBadge;
use App\Models\UsernameChangeHistory;
use Carbon\Carbon;
use DB;
Expand Down Expand Up @@ -82,33 +85,32 @@ public static function validateUsername($username)
public static function validateUsersOfUsername(string $username): ValidationErrors
{
$errors = new ValidationErrors('user');
$userIds = static::usersOfUsername($username)->pluck('user_id');

$users = static::usersOfUsername($username);

// top 100
// Queried directly on model because User::rankHighests is disabled
// when experimental rank is set as default.
$highestRank = RankHighest::whereIn('user_id', $users->pluck('user_id'))->min('rank');
// Check if any of the users have been ranked in the top 100
$highestRank = RankHighest::whereIn('user_id', $userIds)->min('rank');
if ($highestRank !== null && $highestRank <= 100) {
return $errors->add('username', '.username_locked');
}

foreach ($users as $user) {
// has badges
if ($user->badges()->exists()) {
return $errors->add('username', '.username_locked');
}
// Check if any of the users have badges
if (UserBadge::whereIn('user_id', $userIds)->exists()) {
return $errors->add('username', '.username_locked');
}

// ranked beatmaps
if ($user->profileBeatmapsetsRanked()->exists()) {
return $errors->add('username', '.username_locked');
}
// Check if any of the users have beatmaps or beatmapsets with
// leaderboards enabled
if (
Beatmap::scoreable()->whereIn('user_id', $userIds)->exists() ||
Beatmapset::scoreable()->whereIn('user_id', $userIds)->exists()
) {
return $errors->add('username', '.username_locked');
}

return $errors;
}

public static function usersOfUsername(string $username): Collection
private static function usersOfUsername(string $username): Collection
{
$userIds = UsernameChangeHistory::where('username_last', $username)->pluck('user_id');
$users = User::whereIn('user_id', $userIds)->get();
Expand Down
5 changes: 5 additions & 0 deletions app/Models/Beatmapset.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ public function scopeHasMode($query, $modeInts)
});
}

public function scopeScoreable(Builder $query): void
{
$query->where('approved', '>', 0);
}

public function scopeWithModesForRanking($query, $modeInts)
{
if (!is_array($modeInts)) {
Expand Down
9 changes: 9 additions & 0 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Models\LoginAttempt;
use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Validation\NoRFCWarningsValidation;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Arr;
use Illuminate\Support\HtmlString;

Expand Down Expand Up @@ -1847,3 +1848,11 @@ function unmix(string $resource): HtmlString
{
return app('assets-manifest')->src($resource);
}

/**
* Get an instance of the named migration.
*/
function migration(string $name): Migration
{
return require database_path("migrations/{$name}.php");
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateOsuSlackUsersTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand All @@ -33,4 +33,4 @@ public function down()
{
Schema::drop('osu_slack_users');
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateBeatmapsetDiscussions extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down Expand Up @@ -38,4 +38,4 @@ public function down()
{
Schema::drop('beatmapset_discussions');
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use Illuminate\Database\Migrations\Migration;

class ChangePrimaryKeyOnSlackUsers extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand All @@ -32,4 +32,4 @@ public function down()
$table->primary('slack_id');
});
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use Illuminate\Database\Migrations\Migration;

class OsuSlackUserMakeSlackIdNullable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand All @@ -30,4 +30,4 @@ public function down()
$table->string('slack_id', 50)->change();
});
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use Illuminate\Database\Migrations\Migration;

class AddIndexOnSlackId extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand All @@ -30,4 +30,4 @@ public function down()
$table->dropIndex('osu_slack_users_slack_id_index');
});
}
}
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* This file is part of OAuth 2.0 Laravel.
*
* (c) Luca Degasperi <[email protected]>
Expand All @@ -18,7 +18,7 @@
*
* @author Luca Degasperi <[email protected]>
*/
class CreateOauthScopesTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand All @@ -44,4 +44,4 @@ public function down()
{
Schema::drop('oauth_scopes');
}
}
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* This file is part of OAuth 2.0 Laravel.
*
* (c) Luca Degasperi <[email protected]>
Expand All @@ -18,7 +18,7 @@
*
* @author Luca Degasperi <[email protected]>
*/
class CreateOauthGrantsTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand All @@ -42,4 +42,4 @@ public function down()
{
Schema::drop('oauth_grants');
}
}
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* This file is part of OAuth 2.0 Laravel.
*
* (c) Luca Degasperi <[email protected]>
Expand All @@ -18,7 +18,7 @@
*
* @author Luca Degasperi <[email protected]>
*/
class CreateOauthGrantScopesTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down Expand Up @@ -60,4 +60,4 @@ public function down()
});
Schema::drop('oauth_grant_scopes');
}
}
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* This file is part of OAuth 2.0 Laravel.
*
* (c) Luca Degasperi <[email protected]>
Expand All @@ -18,7 +18,7 @@
*
* @author Luca Degasperi <[email protected]>
*/
class CreateOauthClientsTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down Expand Up @@ -46,4 +46,4 @@ public function down()
{
Schema::drop('oauth_clients');
}
}
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* This file is part of OAuth 2.0 Laravel.
*
* (c) Luca Degasperi <[email protected]>
Expand All @@ -18,7 +18,7 @@
*
* @author Luca Degasperi <[email protected]>
*/
class CreateOauthClientEndpointsTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down Expand Up @@ -56,4 +56,4 @@ public function down()

Schema::drop('oauth_client_endpoints');
}
}
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* This file is part of OAuth 2.0 Laravel.
*
* (c) Luca Degasperi <[email protected]>
Expand All @@ -18,7 +18,7 @@
*
* @author Luca Degasperi <[email protected]>
*/
class CreateOauthClientScopesTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down Expand Up @@ -60,4 +60,4 @@ public function down()
});
Schema::drop('oauth_client_scopes');
}
}
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* This file is part of OAuth 2.0 Laravel.
*
* (c) Luca Degasperi <[email protected]>
Expand All @@ -18,7 +18,7 @@
*
* @author Luca Degasperi <[email protected]>
*/
class CreateOauthClientGrantsTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down Expand Up @@ -61,4 +61,4 @@ public function down()
});
Schema::drop('oauth_client_grants');
}
}
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* This file is part of OAuth 2.0 Laravel.
*
* (c) Luca Degasperi <[email protected]>
Expand All @@ -18,7 +18,7 @@
*
* @author Luca Degasperi <[email protected]>
*/
class CreateOauthSessionsTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down Expand Up @@ -56,4 +56,4 @@ public function down()
});
Schema::drop('oauth_sessions');
}
}
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* This file is part of OAuth 2.0 Laravel.
*
* (c) Luca Degasperi <[email protected]>
Expand All @@ -18,7 +18,7 @@
*
* @author Luca Degasperi <[email protected]>
*/
class CreateOauthSessionScopesTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down Expand Up @@ -60,4 +60,4 @@ public function down()
});
Schema::drop('oauth_session_scopes');
}
}
};
Loading

0 comments on commit c19f0a4

Please sign in to comment.