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] Fix PUT request for Candidates \visit endpoint and integration test #7088

Merged
merged 32 commits into from
Nov 9, 2020

Conversation

spell00
Copy link
Contributor

@spell00 spell00 commented Oct 8, 2020

Brief summary of changes

The PUT request should never allow to edit a candidate from a Site where the User has no affiliation with. In this case, the test User has only affiliation with Data Coordinating Center (DCC). It is however possible to do so if the new Site is DCC.

For example, in raisinbread, candidate 300001 (https://<hostname>.loris.ca/api/v0.0.4-dev/candidates/300001) is from site Montreal. The test user should not be able to modify this candidate, because the candidate is from Montreal, but is able to.

Also adds automatic the integration tests to test the changes suggested.

Testing instructions

The testing is made automatic.

To test manually:

  1. Before the test, make sure the User that will be used don't have affiliation with Montreal.

  2. First get the API token using: curl https://<hostname>/api/v0.0.3/login -d '{"username": "<username>", "password": "<password>"}'

  3. In the terminal, enter curl -X PUT -H "Authorization: Bearer $token" https://<hostname>/api/v0.0.4-dev/candidates/300001/V3 -d '{"CandID":"300001","Visit":"V3","Site":"Montreal","Battery":"Low Yeast","Project":"Pumpernickel"}'

Link(s) to related issue(s)

@spell00 spell00 marked this pull request as ready for review October 8, 2020 18:56
@spell00 spell00 added Area: API PR or issue related to the API Category: Bug PR or issue that aims to report or fix a bug Testing PR contains test plan or automated test code (or config files for Travis) labels Oct 9, 2020
@spell00 spell00 added "Help! I don't understand Travis!" PR is having a beef with TRAVIS. Someone needs to help and removed "Help! I don't understand Travis!" PR is having a beef with TRAVIS. Someone needs to help labels Oct 19, 2020
@spell00 spell00 force-pushed the 2020-10-07-FixPutVisitEndpoint branch from 77970fe to 9c9d96f Compare October 29, 2020 17:22
@spell00 spell00 requested a review from xlecours October 29, 2020 20:02
@spell00 spell00 requested a review from xlecours October 30, 2020 14:26
@spell00 spell00 requested a review from driusan October 30, 2020 14:55
@christinerogers
Copy link
Contributor

@driusan requesting final review - this is our last stretch in which @spell00 can readily make changes. thank you!

@spell00 spell00 added the State: Blocked PR or issue awaiting an external event such as the merge or another PR to proceed label Nov 2, 2020
@spell00
Copy link
Contributor Author

spell00 commented Nov 2, 2020

blocked by #7101

@spell00 spell00 force-pushed the 2020-10-07-FixPutVisitEndpoint branch from 7ba7074 to ed0baf7 Compare November 4, 2020 18:36
@spell00 spell00 removed the State: Blocked PR or issue awaiting an external event such as the merge or another PR to proceed label Nov 5, 2020
@spell00
Copy link
Contributor Author

spell00 commented Nov 5, 2020

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

@@ -215,11 +215,19 @@ class Visit extends Endpoint implements \LORIS\Middleware\ETagCalculator
$this->_candidate->getListOfVisitLabels()
);

if (!in_array($this->_candidate->getCenterID(), $user->getCenterIDs())) {
Copy link
Collaborator

@driusan driusan Nov 5, 2020

Choose a reason for hiding this comment

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

The Candidate class implements the AccessibleResource interface. I think this should just be using$this->_candidate->isAccessibleBy($user) instead of duplicating the logic in slightly different ways in the API. (That would also handle Project permissions, which this is currently not doing.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is now using $this->_candidate->isAccessibleBy($user)

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

spell00 commented Nov 6, 2020

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

@@ -215,11 +215,18 @@ class Visit extends Endpoint implements \LORIS\Middleware\ETagCalculator
$this->_candidate->getListOfVisitLabels()
);

if (!$this->_candidate->isAccessibleBy($user)) {
return new \LORIS\Http\Response\JSON\Forbidden(
'You can`t create or modify that candidate'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
'You can`t create or modify that candidate'
"You can't create or modify that candidate"

"can't" doesn't have a backtick in it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it

$centerid = array_search($visitinfo['Site'], \Utility::getSiteList());

if (!in_array($centerid, $user->getCenterIDs())) {
return new \LORIS\Http\Response\JSON\Forbidden(
'You can`t create candidates visit for that site'
'You can`t create or modify candidates visit for the site ' .
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
'You can`t create or modify candidates visit for the site ' .
"You can't create or modify candidates visit for the site " .

@spell00
Copy link
Contributor Author

spell00 commented Nov 6, 2020

@driusan I did all the corrections

@spell00 spell00 requested a review from driusan November 6, 2020 20:25
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.

pending Travis

@spell00
Copy link
Contributor Author

spell00 commented Nov 6, 2020

@driusan It passed Travis

@spell00 spell00 requested a review from driusan November 6, 2020 22:22
@driusan driusan merged commit df29ed8 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
…test (aces#7088)

The PUT request should never allow to edit a candidate from a Site where the User has no affiliation with. In this case, the test User has only affiliation with Data Coordinating Center (DCC). It is however possible to do so if the new Site is DCC.

For example, in raisinbread, candidate 300001 (https://<hostname>.loris.ca/api/v0.0.4-dev/candidates/300001) is from site Montreal. The test user should not be able to modify this candidate, because the candidate is from Montreal, but is able to.

Also adds automatic the integration tests to test the changes suggested.


    Resolves aces#7106
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: API PR or issue related to the API Category: Bug PR or issue that aims to report or fix a bug Testing PR contains test plan or automated test code (or config files for Travis)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The PUT request allows to edit a candidate from a Site where the User has no affiliation with (but should not)
5 participants