-
Notifications
You must be signed in to change notification settings - Fork 174
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
[electrophysiology_browser] Session page: Add Project Permissions check #6640
[electrophysiology_browser] Session page: Add Project Permissions check #6640
Conversation
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.
looks good to me. I will leave you and Karim to each pull and test it.
@ridz1208 or @johnsaigle and eventually dave can review
$candID = $this->timepoint->getCandID(); | ||
$candidate = \Candidate::singleton($candID); | ||
if (!$this->_hasAccess($user) | ||
|| !$user->hasProject($candidate->getProjectID()) |
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.
@AlexandraLivadas I think it's better to put the project access check inside the hasAccess function
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.
@ridz1208 This wouldn't work because the timepoint
variable is not properly defined when the _hasAccess method is first called. This is also what caused the issue #6557. The _hasAccess method is called first by the Module class here, and it is called before the handle
method is called where the timepoint
variable is properly defined. So, I couldn't include it in the method because it would give a null pointer error. Let me know if this explanation makes sense!
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.
@AlexandraLivadas it makes sense. I think I've seen this use case before
@HenriRabalais isn't that a similar problem to the one you had with issue tracker? do you remember what Dave suggested to add to the class in order to instantiate the object before getting to the has access function ?
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.
https://github.com/aces/Loris/pull/6471/files
this might be helpful. look at the comment of the process
function.
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 tried this approach and it did not work. I think it is because this class (Sessions) is of type NDB_Page
, while the one you linked is of type NDB_Form
. If you look at the Module class, the method process
is never called for the actual page. So, when I created the process
method and defined the timepoint variable in there and then moved the project permission line into the _hasAccess
method, it gave me a null pointer error again.
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.
@driusan I sugested that above. @AlexandraLivadas is saying it didnt work
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.
All page types should have the process
middleware called on it, there shouldn't be anything specific to forms in that regard. (Forms are special in that they have a _process
, but that's different than and unrelated to the PSR15 middleware process
)
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.
@driusan I tried again following a very similar format to modules/instrument_list/php/instrument_list.class.inc
and it still gives me the following error when I move the project permission to the _hasAccess method:
PHP Fatal error: Uncaught Error: Call to a member function getProjectID() on null in /var/www/loris2020/modules/electrophysiology_browser/php/sessions.class.inc:56\nStack trace:\n#0 /var/www/loris2020/php/libraries/Module.class.inc(351): LORIS\\electrophysiology_browser\\Sessions->_hasAccess(Object(User))\n#1 /var/www/loris2020/src/Middleware/ResponseGenerator.php(50): Module->handle(Object(Laminas\\Diactoros\\ServerRequest))\n#2 /var/www/loris2020/src/Middleware/AuthMiddleware.php(63): LORIS\\Middleware\\ResponseGenerator->process(Object(Laminas\\Diactoros\\ServerRequest), Object(LORIS\\electrophysiology_browser\\Module))\n#3 /var/www/loris2020/src/Router/ModuleRouter.php(75): LORIS\\Middleware\\AuthMiddleware->process(Object(Laminas\\Diactoros\\ServerRequest), Object(LORIS\\electrophysiology_browser\\Module))\n#4 /var/www/loris2020/src/Router/BaseRouter.php(105): LORIS\\Router\\ModuleRouter->handle(Object(Laminas\\Diactoros\\ServerRequest))\n#5 /var/www/loris2020/src/Middleware/ResponseGenerator.php(50): LORIS\\Router\\BaseRouter->handle(Object(Laminas in /var/www/loris2020/modules/electrophysiology_browser/php/sessions.class.inc on line 56, referer: https://alivadas-dev.loris.ca/electrophysiology_browser
I included the if-statements from the instrument_list.class.inc both in the _hasAccess and process methods to check if the timepoint and candidate variables are null. The \NotFound
error (from _hasAccess) appeared but the \LorisException
error (from process) did not.
[Added] I have found multiple cases of using this process
method this way, so I'm not sure why it's not working. I will continue to look into why this is.
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.
@AlexandraLivadas any news from you investigation ?
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.
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.
From a testing POV, it's behaving as intended.
pinging @ridz1208 for re-review, since @AlexandraLivadas should have addressed your changes already @driusan - should be ready for final review |
@driusan and I have discussed this issue at length yesterday. explanation : the reason @HenriRabalais 's fix on #6471 worked is because he added a null check for We want to change this behaviour because it's not efficient and slightly hacky. What to do: We decided that a short term stable fix would be the following. In the So in this PR what we would expect to see is the addition of the |
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, passes manual test, and also resolves #6557 .
c302982
to
9ed7db6
Compare
aea5614
to
628e247
Compare
} | ||
$session_id = intval($matches[1]); | ||
|
||
$this->timepoint = \NDB_Factory::singleton()->timepoint($session_id); |
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.
@driusan This section returns a 500 Internal Server Error if the session/timepoint does not exist. Is this okay or should it return some other type of exception?
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 think it should be converted to a 404 not found.
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.
approved pending travis..
Brief summary of changes
When a user tries to access the individual session page for a project they are not affiliated with (by altering the URL), a "permission denied" message should appear.
Testing instructions (if applicable)
View all-sites Electrophysiology Browser pages
permission.Links to related issues