-
Notifications
You must be signed in to change notification settings - Fork 175
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
[API] PUT and PATCH methods added to Candidates visit/instruments/flags #6780
[API] PUT and PATCH methods added to Candidates visit/instruments/flags #6780
Conversation
Wait, this is for the flags but the code updates the instrument's data. |
9309a91
to
814ec13
Compare
modules/api/php/endpoints/candidate/visit/instrument/flags.class.inc
Outdated
Show resolved
Hide resolved
I corrected the mistakes in the testing instructions to actually test the PUT and PATCH requests for the |
Thanks @xlecours for your suggestion, using |
modules/api/php/endpoints/candidate/visit/instrument/flags.class.inc
Outdated
Show resolved
Hide resolved
modules/api/php/endpoints/candidate/visit/instrument/flags.class.inc
Outdated
Show resolved
Hide resolved
modules/api/php/endpoints/candidate/visit/instrument/flags.class.inc
Outdated
Show resolved
Hide resolved
@spell00 the ball is in your court on this one i believe. |
e0fa515
to
db5a7c9
Compare
modules/api/php/endpoints/candidate/visit/instrument/flags.class.inc
Outdated
Show resolved
Hide resolved
modules/api/php/endpoints/candidate/visit/instrument/flags.class.inc
Outdated
Show resolved
Hide resolved
modules/api/php/endpoints/candidate/visit/instrument/flags.class.inc
Outdated
Show resolved
Hide resolved
163e8ad
to
831e1f1
Compare
831e1f1
to
5eb83b5
Compare
@driusan This PR is approaved and is is ready for your review |
…es isntruments flags
Co-authored-by: Xavier Lecours <xavier.lecours@mcin.ca>
d179d73
to
863e5d7
Compare
See my comments on #7088.. I think the lines I commented on there were just in that PR because it builds on this one. |
*/ | ||
private function _handlePUT(ServerRequestInterface $request) : ResponseInterface | ||
{ | ||
// TODO :: Check permissions. How?? |
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.
See comment on #7088
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.
are you sure you didn't mean your comment on #7075 ? I applied the change here, as it builds on this one.
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.
data_entry
is already checked. The second point is resolved in the parent endpoint modules/api/php/endpoints/candidate/visit/instrument/instrument.class.inc
(the part commented by Xavier below), so a user without permission can't reach this function.
modules/api/php/endpoints/candidate/visit/instrument/instrument.class.inc
Outdated
Show resolved
Hide resolved
|
||
if ($this->_instrument->_hasAccess($user)) { | ||
return new \LORIS\Http\Response\JSON\Forbidden( | ||
'Can not update instruments for user' . $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 don't think $user
is a string.
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.
_hasAccess
does not take a string
function _hasAccess(\User $user) : bool |
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.
nevermind I just got it, I'll remove the parameter $user
from the 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.
done
Maybe you mean #7075? it is the PR that builds on this one. I checked the User is permitted to update instruments in
|
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 looks like it's missing a check for the data_entry
permission. From what I can tell determineDataEntryAllowed isn't sufficient, it just checks the 'Complete' flag in the backend, not the permissions.
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.
lgtm.. @xlecours does it still look good to you?
Brief summary of changes
The methods
handlePUT
andhandlePATCH
were added to the endpoint/candidates/<candid>/<visit>/instruments/<instrument>
.Testing instructions
Testing the PUT handle method
Go to
https://<hostname>/api/v0.0.3/candidates/300002/V1/instruments/aosi/flags
in a browser.The fields
Data_entry
,Administration
andValidity
field should beNULL
In a terminal, login by sending the POST request below:
~$ curl https://<hostname>/api/v0.0.3/login -d '{"username": "<username>", "password": "<password>"}'
The expected response is: {"token": ""}. Store the token in a variable
token='<a-really-long-string>'
.In the terminal, enter
curl -X PUT -H "Authorization: Bearer $token" https://<hostname>/api/v0.0.3/candidates/300002/V1/instruments/aosi/flags -d '{"Flags": {"Data_entry": "In Progress", "Administration": "All", "Validity": "Valid"}}'
Go back to
https://<hostname>/api/v0.0.3/candidates/300002/V1/instruments/aosi/flags
in the same browser as in step 1.Data_entry
should be"In Progress"
,Administration
should be"all"
andValidity
should be "Valid".In the terminal, enter
curl -X PUT -H "Authorization: Bearer $token" https://<hostname>/api/v0.0.3/candidates/300002/V1/instruments/aosi -d '{"Flags": {"Data_entry": "In Progress", "Administration": null, "Validity": "Questionable"}}'
The field
Administration
should be changed tonull
andValidity
should be"Questionable"
Testing the PATCH handle method
Go to
https://<hostname>/api/v0.0.3/candidates/300002/V1/instruments/aosi/flags
in a browser.The fields
Data_entry
field should beNULL
,Administration
should be"Partial"
andValidity
should be"Questionable"
In the terminal, enter
curl -X PATCH -H "Authorization: Bearer $token" https://<hostname>/api/v0.0.3/candidates/300002/V1/instruments/aosi/flags -d '{"Flags": {"Data_entry": null, "Administration": "All"}}'
Go back to
,
https://<hostname>/api/v0.0.3/candidates/300002/V1/instruments/aosi/flags
in the same browser as in step 1. The Data_entry value should now be updated without changing anything else. You should now see"Data_entry" is
nullValidity
is still"Questionable"
and see thatAdministration
isAll
in thejson
stringLink(s) to related issue(s)
/candidates/{candid}/{visit}/instruments/{instrument}/flags
needs methods to handle PUT and PATCH requests #6777