-
Notifications
You must be signed in to change notification settings - Fork 390
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
Conversation
} catch (InvariantException $e) { | ||
return error_popup($e->getMessage(), $e->getStatusCode()); | ||
} |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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
app/Models/Multiplayer/Room.php
Outdated
} | ||
|
||
$gracePeriodMinutes = $GLOBALS['cfg']['osu']['multiplayer']['room_close_grace_period_minutes']; | ||
if ($this->starts_at->addMinutes($gracePeriodMinutes) < now()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's an ->isPast()
$start = now(); | ||
$end = $start->addMinutes(60); |
There was a problem hiding this comment.
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' => ['*']]); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
osu-web/app/Models/Multiplayer/Room.php
Lines 234 to 237 in 1fbc73b
public function host() | |
{ | |
return $this->belongsTo(User::class, 'user_id'); | |
} |
osu-web/app/Models/Multiplayer/Room.php
Line 557 in 1fbc73b
$this->setRelation('host', $host); |
'ends_at' => $end, | ||
'type' => Room::PLAYLIST_TYPE, | ||
]); | ||
$end = $room->ends_at; // creation truncates fractional second part, so refetch here |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
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
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()); |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Intended for use in ppy/osu#30401