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

[API] PUT and PATCH methods added to Candidates visit/instruments/flags #6780

Merged

Conversation

spell00
Copy link
Contributor

@spell00 spell00 commented Jun 29, 2020

Brief summary of changes

The methods handlePUT and handlePATCH were added to the endpoint /candidates/<candid>/<visit>/instruments/<instrument>.

Testing instructions

Testing the PUT handle method

  1. Go to https://<hostname>/api/v0.0.3/candidates/300002/V1/instruments/aosi/flags in a browser.

  2. The fields Data_entry, Administration and Validity field should be NULL

  3. In a terminal, login by sending the POST request below:
    ~$ curl https://<hostname>/api/v0.0.3/login -d '{"username": "<username>", "password": "<password>"}'

  4. The expected response is: {"token": ""}. Store the token in a variable token='<a-really-long-string>'.

  5. 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"}}'

  6. 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" and Validity should be "Valid".

  7. 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"}}'

  8. The field Administration should be changed to null and Validity should be "Questionable"

Testing the PATCH handle method

  1. Go to https://<hostname>/api/v0.0.3/candidates/300002/V1/instruments/aosi/flags in a browser.

  2. The fields Data_entry field should be NULL , Administration should be "Partial" and Validity should be "Questionable"

  3. 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"}}'

  4. 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 null ,Validity is still "Questionable" and see that Administration is All in the json string

Link(s) to related issue(s)

@spell00 spell00 requested a review from xlecours June 30, 2020 19:30
@xlecours
Copy link
Contributor

xlecours commented Jul 2, 2020

This is exactly how it should be done.
I still need to test it though.

Wait, this is for the flags but the code updates the instrument's data.

@spell00 spell00 changed the base branch from master to main July 23, 2020 14:22
@spell00 spell00 force-pushed the 2020-06-29-AddInstrumentsFlagsPutPatchHandles branch from 9309a91 to 814ec13 Compare August 21, 2020 00:28
@spell00
Copy link
Contributor Author

spell00 commented Aug 21, 2020

I corrected the mistakes in the testing instructions to actually test the PUT and PATCH requests for the flags endpoint instead of instrument , plus it is now actually working

@spell00 spell00 changed the title [API] PUT and POST methods added to Candidates visit/instruments/flags [API] PUT and PATCH methods added to Candidates visit/instruments/flags Aug 24, 2020
@spell00
Copy link
Contributor Author

spell00 commented Aug 24, 2020

Thanks @xlecours for your suggestion, using NDB_BVL_InstrumentStatus.class.inc makes much more sense! The PUT and PATCH functions work for me now with this branch using the testing instructions in the PR description.

@christinerogers christinerogers requested review from xlecours and removed request for xlecours August 24, 2020 21:19
@christinerogers
Copy link
Contributor

@spell00 the ball is in your court on this one i believe.

@spell00 spell00 force-pushed the 2020-06-29-AddInstrumentsFlagsPutPatchHandles branch from e0fa515 to db5a7c9 Compare September 14, 2020 20:45
@spell00 spell00 added the API PR or issue introducing/requiring modifications to the API code label Sep 17, 2020
@spell00 spell00 force-pushed the 2020-06-29-AddInstrumentsFlagsPutPatchHandles branch from 163e8ad to 831e1f1 Compare September 28, 2020 19:46
@christinerogers christinerogers added the Blocking PR should be prioritized because it is blocking the progress of another task label Oct 23, 2020
@spell00 spell00 force-pushed the 2020-06-29-AddInstrumentsFlagsPutPatchHandles branch from 831e1f1 to 5eb83b5 Compare October 29, 2020 16:02
@spell00
Copy link
Contributor Author

spell00 commented Oct 29, 2020

@driusan This PR is approaved and is is ready for your review

@spell00 spell00 force-pushed the 2020-06-29-AddInstrumentsFlagsPutPatchHandles branch from d179d73 to 863e5d7 Compare November 4, 2020 18:41
@spell00
Copy link
Contributor Author

spell00 commented Nov 5, 2020

@xlecours @driusan It is now passing Travis and ready for final review

@spell00 spell00 removed the Blocked PR awaiting the merge, resolution or rejection of an other Pull Request label Nov 5, 2020
@driusan
Copy link
Collaborator

driusan commented Nov 5, 2020

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??
Copy link
Collaborator

Choose a reason for hiding this comment

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

See comment on #7088

Copy link
Contributor Author

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.

Copy link
Contributor Author

@spell00 spell00 Nov 5, 2020

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.


if ($this->_instrument->_hasAccess($user)) {
return new \LORIS\Http\Response\JSON\Forbidden(
'Can not update instruments for user' . $user
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

@spell00 spell00 Nov 5, 2020

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@spell00 spell00 requested a review from xlecours November 5, 2020 20:10
@spell00
Copy link
Contributor Author

spell00 commented Nov 5, 2020

See my comments on #7088.. I think the lines I commented on there were just in that PR because it builds on this one.

Maybe you mean #7075? it is the PR that builds on this one. I checked the User is permitted to update instruments in modules/api/php/endpoints/candidate/visit/instrument/instrument.class.inc line 97, where I use

if ($this->_instrument->_hasAccess($user)) { ...

@spell00 spell00 requested a review from driusan November 6, 2020 06:33
@spell00
Copy link
Contributor Author

spell00 commented Nov 6, 2020

@xlecours @driusan I did the corrections, this is ready for re-review

Copy link
Collaborator

@driusan driusan left a 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.

Copy link
Collaborator

@driusan driusan left a 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?

@driusan driusan merged commit 920fd4e into aces:main Nov 9, 2020
@ridz1208 ridz1208 added this to the 24.0.0 milestone Nov 27, 2020
AlexandraLivadas pushed a commit to AlexandraLivadas/Loris that referenced this pull request Jun 29, 2021
…gs (aces#6780)

The methods handlePUT and handlePATCH were added to the endpoint /candidates/<candid>/<visit>/instruments/<instrument>.

    Resolves aces#6777
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API PR or issue introducing/requiring modifications to the API code Blocking PR should be prioritized because it is blocking the progress of another task
Projects
None yet
5 participants