-
Notifications
You must be signed in to change notification settings - Fork 276
Fix user add and update api endpoints #3040
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
base: main
Are you sure you want to change the base?
Conversation
Can you explain which problem you encountered? |
Updated the description |
Let's discuss in Slack how to fix this one, I assume you posted something which is larger than 512M? Did you raise the
I can see that you did this, but I'm not sure yet why it wants a form but I suspect this is legacy.
So we're working on a major release so now would be the time to make such choices but let's see if we can prevent it still. |
@LuukBlankenstijn can you provide the files you were using which hit this error? |
I've not looked into the changes in detail (and I guess @nickygerritsen might be a better reviewer), but from the description it's not clear to me what these changes are fixing and why/how. Because this seems to have nothing to do with a maximum post size of a request. Can you clarify that? |
I updated the description again, I'm sorry for lack initial lack of explanation |
I think we can do something smart to still have both update and create in one action, will think about it. Although that is not very REST, so maybe we shouldn't? As form json vs formdata, ideally it'd accept both, so I will investigate if we can get that to work. |
I have a, imo, nice idea for this, I can implement it tommorrow if you want. |
Sounds good |
Some general comments:
|
088c538
to
7873dfa
Compare
fixed. - Server did not accept the data in the format of the api spec. fixed by changing to json. - Updating using required username and name always to be set, even if when not changing one of them. - When updating a user (with the mandatory username), the server would return a 404 saying this username is already in use.
7873dfa
to
7d5bcfe
Compare
Sorry for the delay, but I finally found some time to work on it. I cannot seem to figure out how to run the tests and how to fix code-style, any help on that would be appreciated. |
<?php | ||
|
||
declare(strict_types=1); |
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.
Any reason you wanted to change this? I don't think we want the newlines there.
($jsonFile && ($result = $this->importExportService->importJson('groups', $jsonFile, $message)))) && | ||
$result >= 0) { | ||
return "$result new group(s) successfully added."; | ||
($jsonFile && ($result = $this->importExportService->importJson('groups', $jsonFile, $message)))) && |
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 don't think you change anything here. Can either first run your linter on the file and commit or remove the changes your linter made (my preference)?
if ($user === null) { | ||
throw new NotFoundHttpException(sprintf("User with id %s not found", $id)); | ||
} | ||
return $this->addOrUpdateUser($mutateUser, $user, $request); |
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 name addOrUpdate
is now misleading. You only allow for update here.
I dropped you a message in the DOMjudge slack to help. The tests will only run when we press the button as you haven't merged anything yet. |
Found some bugs while using the API, and since I need the endpoints, fixed them.
Problem I encountered:
Endpoint /api/v4/users/{id} PUT request returned{ 400, Body data exceeded php.ini's 'post_max_size' directive (currently set to 512M)}.
Could not get it to work whatever I tried. When looking at the code I also discovered some other issues in the case of updating the user with App\Controller\API\UserController.php addOrUpdateUser().
What I did is changing the content type of the api-doc attribute to application/json, and separated the add and update method in to dedicated methods. I realize this is a breaking change in the api spec and not ideal.
I got the errors on both the DOMjudge instance running on the GEHACK server in Eindhoven, and my own local instance.
This exception is generated in App\EventListener\BodyToBigListener.php. This happens because the amount of parameters on the request is 0. (I get this even when using /api/doc on a running domjudge instance). I first tried fixing the request, but could not get it to work. Because it made more sense to me for a request like this to accept json instead of formdata I decided to change it to that. After I did this the request now worked, but i found some flaws in the update logic for user.
For example: name, username and id are required to even make an update by the documentation. I would have expected to just need an id and being able to update any field. Then, on line 150 in App\Controller\Api\Usercontroler:
So if the user already exists we get a BadRequestException. This effectively means that for every update we want to do to a user, the username has to be changed.
Then also we cannot do partial update by leaving fields in the request null, since all properties of the UpdateUser dto are assigned to the existing user, even when null.