-
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] Fix PUT request for Candidates \visit endpoint and integration test #7088
Conversation
77970fe
to
9c9d96f
Compare
blocked by #7101 |
7ba7074
to
ed0baf7
Compare
@@ -215,11 +215,19 @@ class Visit extends Endpoint implements \LORIS\Middleware\ETagCalculator | |||
$this->_candidate->getListOfVisitLabels() | |||
); | |||
|
|||
if (!in_array($this->_candidate->getCenterID(), $user->getCenterIDs())) { |
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 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.)
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 is now using $this->_candidate->isAccessibleBy($user)
@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' |
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.
'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.
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 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 ' . |
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.
'You can`t create or modify candidates visit for the site ' . | |
"You can't create or modify candidates visit for the site " . |
@driusan I did all the corrections |
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.
pending Travis
@driusan It passed Travis |
…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
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 newSite
is DCC.For example, in raisinbread, candidate 300001 (
https://<hostname>.loris.ca/api/v0.0.4-dev/candidates/300001
) is from siteMontreal
. 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:
Before the test, make sure the User that will be used don't have affiliation with Montreal.
First get the API token using:
curl https://<hostname>/api/v0.0.3/login -d '{"username": "<username>", "password": "<password>"}'
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)