Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude bot and no profile special groups from being set as guest mappers #11764

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/Http/Controllers/Users/LookupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public function index()
}

$users = User::where(fn ($q) => $q->whereIn('user_id', $numericIds)->orWhereIn('username', $stringIds))
->where('group_id', '<>', app('groups')->byIdentifier('no_profile')->getKey())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should stay regardless of exclude bots option? See #6736

->default()
->defaultForLookup()
Copy link
Collaborator

@nanaya nanaya Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also affects user card which we probably want to keep showing for bots?

edit: it's actually even worse with the card saying the user doesn't exist...

->with(UserCompactTransformer::CARD_INCLUDES_PRELOAD)
->get();

Expand Down
2 changes: 1 addition & 1 deletion app/Libraries/Beatmapset/ChangeBeatmapOwners.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function handle(): void

$newUserIds = $this->userIds->diff($currentOwners);

if (User::whereIn('user_id', $newUserIds->toArray())->default()->count() !== $newUserIds->count()) {
if (User::whereIn('user_id', $newUserIds->toArray())->defaultForLookup()->count() !== $newUserIds->count()) {
throw new InvariantException('invalid user_id');
}

Expand Down
9 changes: 9 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2032,6 +2032,15 @@ public function scopeDefault($query)
]);
}

public function scopeDefaultForLookup(Builder $query): Builder
{
$groups = app('groups');

return $query
->whereNotIn('group_id', [$groups->byIdentifier('no_profile')->getKey(), $groups->byIdentifier('bot')->getKey()])
->default();
}

public function scopeOnline($query)
{
return $query
Expand Down
35 changes: 35 additions & 0 deletions tests/Libraries/Beatmapset/ChangeBeatmapOwnersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@

class ChangeBeatmapOwnersTest extends TestCase
{
public static function dataProviderForInvalidUser(): array
{
return [
['bot'],
['no_profile'],
];
}

public static function dataProviderForUpdateOwner(): array
{
return [
Expand Down Expand Up @@ -68,6 +76,33 @@ public function testMissingUser(): void
Bus::assertDispatched(BeatmapOwnerChange::class);
}

/**
* @dataProvider dataProviderForInvalidUser
*/
public function testInvalidUser(string $group): void
{
$moderator = User::factory()->withGroup('nat')->create();
$owner = User::factory()->create();
$invalidUser = User::factory()->withGroup($group)->create();

$beatmap = Beatmap::factory()
->for(Beatmapset::factory()->pending()->owner($owner))
->owner($owner)
->create();

$this->expectCountChange(fn () => BeatmapsetEvent::count(), 0);

$this->expectExceptionCallable(
fn () => (new ChangeBeatmapOwners($beatmap, [$invalidUser->getKey()], $moderator))->handle(),
InvariantException::class,
);

$beatmap = $beatmap->fresh();
$this->assertEqualsCanonicalizing([$owner->getKey()], $beatmap->getOwners()->pluck('user_id')->toArray());

Bus::assertNotDispatched(BeatmapOwnerChange::class);
}

/**
* @dataProvider dataProviderForUpdateOwner
*/
Expand Down
Loading