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

[Statistics] Behavioural Statistics > Double Data Entry - Site permission fix #6659

Closed

Conversation

laemtl
Copy link
Contributor

@laemtl laemtl commented Jun 2, 2020

Description of the issue

In Statistics / Behavioural Statistics / Double Data Entry Statistics, users were allowed to see the double data entry breakdown per participant from sites they don't have access to.

Brief summary of changes

The _hasAccess function was incorpoerate to this class (same functionality that the one in #5591)

The function _checkCriteria was modified for only retrieve data from the sites(centers) the user have access to.

Note: In future developments the capacity of setting permissions per site per user could be desirable. A note in rapport was included in the codeset. In this case the proposed function _hasAccess should be updated accordingly .

Testing instructions (if applicable)

A user with permission 'data_entry' should be now able to access the 'breakdown per participant' for the double data entry page only for the sites it have access to.

Links to related PRs

#5950
#5591
Duplicates of #5966 (rebased on 23.0)

@laemtl
Copy link
Contributor Author

laemtl commented Jun 2, 2020

@ridz1208 I retested this rebase and it works as expected.

@laemtl laemtl force-pushed the 2020-06-02-statistics-permission-fix branch from 977bc1a to 689b824 Compare June 2, 2020 15:31
@laemtl laemtl requested a review from christinerogers June 3, 2020 17:36
if (!empty($centerID)) {
$this->query_criteria .= " AND s.CenterID =:cid ";
$this->query_vars['cid'] = $centerID;
} else {
$list_of_permitted_sites = (array) null;
Copy link
Member

Choose a reason for hiding this comment

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

Interesting way to make an empty array. I've never seen this way until today. 🙂

@maltheism
Copy link
Member

I'm going to manually test. The code looks good!

@ridz1208 ridz1208 added this to the 23.0.0 milestone Jun 8, 2020
@maltheism
Copy link
Member

Hi @laemtl here are my results from what my test user could see visible. The General Demographics Statistics seems to be correct with only showing the two projects the user has access. The other statistics tabs in the module show all the projects for the select field.

1

2

3

User test permissions:
0

@laemtl
Copy link
Contributor Author

laemtl commented Jun 8, 2020

Thank you @maltheism. I will apply the same fix to the other sections as well!

@laemtl laemtl self-assigned this Jun 8, 2020
@laemtl laemtl removed the Passed manual tests PR has been successfully tested by at least one peer label Jun 8, 2020
@maltheism
Copy link
Member

I think this PR will fix #6675 @kongtiaowang

@kongtiaowang
Copy link
Contributor

kongtiaowang commented Jun 8, 2020

@maltheism This PR will fix Behavioural Statistics. But Imaging Statistics has the same issue.

@laemtl laemtl changed the title [Statistics] Behavioural Statistics > Double Data Entry permission fix [Statistics] Behavioural Statistics > Double Data Entry Site permission fix Jun 9, 2020
@laemtl laemtl changed the title [Statistics] Behavioural Statistics > Double Data Entry Site permission fix [Statistics] Behavioural Statistics > Double Data Entry - Site permission fix Jun 9, 2020
driusan pushed a commit that referenced this pull request Jun 9, 2020
Only display projects to which a user has access in the projects dropdown in statistics. 

    Resolves #6675
    Resolves comments made in #6659
@ridz1208 ridz1208 removed this from the 23.0.0 milestone Jun 9, 2020
@christinerogers
Copy link
Contributor

@laemtl What's the status? Is this ready for @maltheism's re-review? If so, please also ask Karim and/or Alex to help you test and review this today.

@laemtl laemtl requested a review from maltheism June 11, 2020 18:04
@laemtl
Copy link
Contributor Author

laemtl commented Jun 11, 2020

@christinerogers All the comments were addressed and merged with #6706

@laemtl
Copy link
Contributor Author

laemtl commented Jun 11, 2020

@AlexandraLivadas @h-karim Does any of you have time to test this as well?

@spell00 spell00 self-requested a review June 11, 2020 20:48
Copy link
Contributor

@spell00 spell00 left a comment

Choose a reason for hiding this comment

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

I manually tested and the fix works as expected!

@laemtl laemtl requested a review from driusan June 12, 2020 15:59
@christinerogers christinerogers added the Passed manual tests PR has been successfully tested by at least one peer label Jun 12, 2020
@laemtl laemtl force-pushed the 2020-06-02-statistics-permission-fix branch 2 times, most recently from 0c6793b to d8fad7f Compare June 17, 2020 16:59
@ridz1208
Copy link
Collaborator

ridz1208 commented Jul 2, 2020

@pierre-p-s please review and test

@pierre-p-s
Copy link
Contributor

The behavioural statistics tab seems to be working for all sites except for 'Data Coordinating Center' (DCC). When you have the permission to access only DCC data, nothing appears in the behavioural statistics tab (see screenshot below). I am not getting any error in the console or error log. Is this intended?

Screen Shot 2020-07-03 at 12 23 31 PM

When clicking on breakdown per participant with only DCC permission this is what I am getting:

Screen Shot 2020-07-03 at 12 26 40 PM

@ridz1208
Copy link
Collaborator

ridz1208 commented Jul 7, 2020

@pierre-p-s DCC is not included in stats by design

Copy link
Contributor

@christinerogers christinerogers left a comment

Choose a reason for hiding this comment

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

Glad you linked new issues to this.
I highlighted the typos and polished it in the suggestions.
Not sure how i feel about issue #s appearing in the text but can't think of a better way to do it right now.

modules/statistics/php/statistics_dd_site.class.inc Outdated Show resolved Hide resolved
modules/statistics/php/statistics_dd_site.class.inc Outdated Show resolved Hide resolved
modules/statistics/php/statistics_dd_site.class.inc Outdated Show resolved Hide resolved
// in near versions when the permission framework allow it
// The filter _checkCriteria() takes care of restricting
// the user access only to the sites it belongs to.
// TODO (#6743): _checkCriteria takes care of restricting access
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// TODO (#6743): _checkCriteria takes care of restricting access
// TODO (#6743): _checkCriteria takes care of restricting data access

clarifying that it's data access not e.g. page-loading access

modules/statistics/php/statistics_dd_site.class.inc Outdated Show resolved Hide resolved
modules/statistics/php/statistics_dd_site.class.inc Outdated Show resolved Hide resolved
@laemtl laemtl force-pushed the 2020-06-02-statistics-permission-fix branch from d8fad7f to 1342585 Compare July 8, 2020 21:04
@laemtl laemtl requested a review from christinerogers July 8, 2020 21:04
Copy link
Contributor

@pierre-p-s pierre-p-s left a comment

Choose a reason for hiding this comment

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

Travis failed for the PR.

I tested, the breakdown per participant, it only outputs data for sites that the user has access to as intended.

I am also linking another issue here that I encountered when testing the behavioural statistics tab: #6573

*/
function _hasAccess(\User $user) : bool
{
// TODO (#6742): Create a permission specific to statistics
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this should not be in the code but rather should be documented in the PR. Same thing for all the other mentions of issues.

@laemtl
Copy link
Contributor Author

laemtl commented Jul 9, 2020

@pierre-p-s Restarted the build and it succeeded.

@laemtl laemtl requested a review from pierre-p-s July 9, 2020 21:30
Copy link
Contributor

@christinerogers christinerogers left a comment

Choose a reason for hiding this comment

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

LGTM

$hasAccessToAllProfiles = $user->hasAllPermissions(
array(
'access_all_profiles',
'data_entry',
Copy link
Collaborator

Choose a reason for hiding this comment

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

access_all_profiles should be sufficient. There's no reason to check for both that and data_entry. And you can just immediately return true if the user has it, there's no reason to check for center permissions once you've already determine that they should have access.

if (!empty($centerID)) {
$this->query_criteria .= " AND s.CenterID =:cid ";
$this->query_vars['cid'] = $centerID;
} else {
$list_of_permitted_sites = (array) null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree with @maltheism that this is weird. Why not just set it to []?

if (!empty($centerID)) {
$this->query_criteria .= " AND s.CenterID =:cid ";
$this->query_vars['cid'] = $centerID;
} else {
$list_of_permitted_sites = (array) null;
$currentUser = \User::singleton();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should come from the factory

$list_of_permitted_sites = array_keys(\Utility::getSiteList());
} else {
foreach ($currentUser->getCenterIDs() as $centerID) {
if ($currentUser->hasCenterPermission(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand this check.. under what situations would the user have the centerID returned from getCenterIDs but not have permission to the centerID?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All the suggestions make sense. I can't comment on the code as I didn't write it. Maybe @racostas can comment.

@laemtl laemtl requested a review from driusan July 15, 2020 22:39
@laemtl laemtl force-pushed the 2020-06-02-statistics-permission-fix branch from 1b616c3 to 3426070 Compare July 15, 2020 23:47
} else {
// FIXME (#6742): For the short term the user will be granted access
// if they have permission for a minimum of one of the centers
foreach ($user->getCenterIDs() as $centerID) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Comment from 6 days ago.. not sure why GitHub removed it:

I don't understand this check.. under what situations would the user have the centerID returned from getCenterIDs but not have permission to the centerID?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@racostas can you comment on @driusan 's question ?

Copy link
Contributor Author

@laemtl laemtl Jul 21, 2020

Choose a reason for hiding this comment

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

@driusan @ridz1208 Additional information can be found here: #6742.
Part of the comment has been migrated to an issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi, thanks for bring this back. This code is a bit old now I think. I will take a look but sure there are lot of things could be refactored/fixed.

@racostas
Copy link
Contributor

#6861 refactors the code in this PR. Also includes permission restrictions by project . Please refer to this new version.

@racostas
Copy link
Contributor

closed by #6861

@racostas racostas closed this Jul 29, 2020
driusan pushed a commit that referenced this pull request Aug 3, 2020
…ermission fix (#6861)

Code refactorization of the functions _hasAccess and _checkCriteria.
Adds per projects permissions restrictions.

A user with permission data_entry should be now able to access the 'breakdown per participant' only for the sites and projects it have access to.

    Resolves #6659
spell00 pushed a commit to spell00/Loris that referenced this pull request Aug 13, 2020
…ermission fix (aces#6861)

Code refactorization of the functions _hasAccess and _checkCriteria.
Adds per projects permissions restrictions.

A user with permission data_entry should be now able to access the 'breakdown per participant' only for the sites and projects it have access to.

    Resolves aces#6659
spell00 pushed a commit to spell00/Loris that referenced this pull request Aug 13, 2020
…ermission fix (aces#6861)

Code refactorization of the functions _hasAccess and _checkCriteria.
Adds per projects permissions restrictions.

A user with permission data_entry should be now able to access the 'breakdown per participant' only for the sites and projects it have access to.

    Resolves aces#6659
AlexandraLivadas pushed a commit to AlexandraLivadas/Loris that referenced this pull request Jun 15, 2021
…ermission fix (aces#6861)

Code refactorization of the functions _hasAccess and _checkCriteria.
Adds per projects permissions restrictions.

A user with permission data_entry should be now able to access the 'breakdown per participant' only for the sites and projects it have access to.

    Resolves aces#6659
AlexandraLivadas pushed a commit to AlexandraLivadas/Loris that referenced this pull request Jun 15, 2021
…ermission fix (aces#6861)

Code refactorization of the functions _hasAccess and _checkCriteria.
Adds per projects permissions restrictions.

A user with permission data_entry should be now able to access the 'breakdown per participant' only for the sites and projects it have access to.

    Resolves aces#6659
AlexandraLivadas pushed a commit to AlexandraLivadas/Loris that referenced this pull request Sep 2, 2021
…ermission fix (aces#6861)

Code refactorization of the functions _hasAccess and _checkCriteria.
Adds per projects permissions restrictions.

A user with permission data_entry should be now able to access the 'breakdown per participant' only for the sites and projects it have access to.

    Resolves aces#6659
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Bug PR or issue that aims to report or fix a bug Category: Security PR or issue that aims to improve security
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants