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

Add endpoint for closing playlists within grace period of creation #11667

Merged
merged 9 commits into from
Nov 20, 2024

Conversation

bdach
Copy link
Contributor

@bdach bdach commented Nov 19, 2024

Intended for use in ppy/osu#30401

Comment on lines 238 to 240
} catch (InvariantException $e) {
return error_popup($e->getMessage(), $e->getStatusCode());
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is now done in the global exception handler and thus redundant

return error_popup($e->getMessage(), $e->getStatusCode());
}

return response([], 204);
Copy link
Collaborator

Choose a reason for hiding this comment

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

as it turned out the first parameter should be null

$room = Room::findOrFail($id);

try {
$room->endGame(auth()->user());
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 we're leaning towards using \Auth::user() now

}

$gracePeriodMinutes = $GLOBALS['cfg']['osu']['multiplayer']['room_close_grace_period_minutes'];
if ($this->starts_at->addMinutes($gracePeriodMinutes) < now()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

there's an ->isPast()

Comment on lines 435 to 436
$start = now();
$end = $start->addMinutes(60);
Copy link
Collaborator

Choose a reason for hiding this comment

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

the object created by now() mutates itself so the start and end are both the same. Either clone() it first or use Carbon\CarbonImmutable

@@ -429,6 +429,100 @@ public function testJoinWithPassword()
$this->assertSame($initialUserChannelCount + 1, UserChannel::count());
}

public function testDestroy()
{
$token = Token::factory()->create(['scopes' => ['*']]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

there's $this->actAsScopedUser($room->user)

Copy link
Contributor Author

@bdach bdach Nov 19, 2024

Choose a reason for hiding this comment

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

I'm not sure how to use that. I assumed it'd be something like

diff --git a/tests/Controllers/Multiplayer/RoomsControllerTest.php b/tests/Controllers/Multiplayer/RoomsControllerTest.php
index 7cd7096c82..ae457dcb9d 100644
--- a/tests/Controllers/Multiplayer/RoomsControllerTest.php
+++ b/tests/Controllers/Multiplayer/RoomsControllerTest.php
@@ -431,11 +431,9 @@ class RoomsControllerTest extends TestCase
 
     public function testDestroy()
     {
-        $token = Token::factory()->create(['scopes' => ['*']]);
         $start = now();
         $end = $start->clone()->addMinutes(60);
         $room = Room::factory()->create([
-            'user_id' => $token->user,
             'starts_at' => $start,
             'ends_at' => $end,
             'type' => Room::PLAYLIST_TYPE,
@@ -443,8 +441,8 @@ class RoomsControllerTest extends TestCase
         $end = $room->ends_at; // creation truncates fractional second part, so refetch here
         $url = route('api.rooms.destroy', ['room' => $room]);
 
+        $this->actAsScopedUser($room->user);
         $this
-            ->actingWithToken($token)
             ->delete($url)
             ->assertSuccessful();
 

but trying that, it barfs at me with App\Exceptions\InvalidScopeException: * is not allowed with Client Credentials.

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh wow the model doesn't have user relation defined (and thus it passes null for the user) o_O

adding it is probably a good idea...

Copy link
Contributor Author

@bdach bdach Nov 19, 2024

Choose a reason for hiding this comment

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

I think it might be ->host actually. Seems to work locally at least.

public function host()
{
return $this->belongsTo(User::class, 'user_id');
}

$this->setRelation('host', $host);

'ends_at' => $end,
'type' => Room::PLAYLIST_TYPE,
]);
$end = $room->ends_at; // creation truncates fractional second part, so refetch here
Copy link
Collaborator

Choose a reason for hiding this comment

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

technically the truncation happens during assignment

@@ -228,4 +228,17 @@ public function store()
return error_popup($e->getMessage(), $e->getStatusCode());
}
}

public function destroy($id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

the functions are sorted alphabetically

@nanaya
Copy link
Collaborator

nanaya commented Nov 19, 2024

oh and here's a protip for the routing json thing #11629 (comment)

@tsunyoku
Copy link
Member

oh and here's a protip for the routing json thing #11629 (comment)

at this point I feel like this should be placed somewhere as it seems to be referenced every time someone makes a PR which adds/changes a route 😆

could this not be automated via CI or something?

- Move in alphabetical order
- Remove redundant try-catch
- Fix response call to use `null` rather than `[]`
- Use different syntax or whatever to reference user
@nanaya
Copy link
Collaborator

nanaya commented Nov 19, 2024

at this point I feel like this should be placed somewhere as it seems to be referenced every time someone makes a PR which adds/changes a route 😆

could this not be automated via CI or something?

I think the point is to make us aware about api changes but yeah it can be better documented at least.

public function destroy($id)
{
$room = Room::findOrFail($id);
$room->endGame(\Auth()->user());
Copy link
Collaborator

Choose a reason for hiding this comment

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

it's a different thing 😔 ::user()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

1732026037

i don't even wanna know

Copy link
Contributor Author

@bdach bdach Nov 19, 2024

Choose a reason for hiding this comment

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

oh apparently i had the braces in there too which i should not have? i give up

Copy link
Collaborator

Choose a reason for hiding this comment

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

it's a different way to access the same thing but slightly faster because the other method (auth()) does additional processing for some unknown reason

@bdach bdach self-assigned this Nov 20, 2024
@nanaya nanaya enabled auto-merge November 20, 2024 08:06
@nanaya nanaya merged commit 65ca10d into ppy:master Nov 20, 2024
3 checks passed
@bdach bdach deleted the destroy-rooms branch November 20, 2024 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants