Skip to content

Commit

Permalink
[Statistics/Behavioural] Detailed View and Double Data Entry - Site p…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
racostas authored and spell00 committed Aug 13, 2020
1 parent ab9b95f commit 47f5e18
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions modules/statistics/php/statistics_site.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Statistics_Site extends \NDB_Menu
*/
function _hasAccess(\User $user) : bool
{
<<<<<<< ff9cfba5feee88a24470e463aef0117915aff1a4
//TODO: Create a permission specific to statistics
$hasAccessToAllProfiles = $user->hasAllPermissions(
[
Expand Down Expand Up @@ -86,6 +87,15 @@ class Statistics_Site extends \NDB_Menu
}

return $hasAccessToAllProfiles || $hasCenterPermission;
<<<<<<< ab9b95f084e392fe6cfca355aeeddf073af79caf
=======

=======
//TODO: To create a permission specific to statistics
return( $user->hasPermission('access_all_profiles')
|| $user->hasPermission('data_entry'));
>>>>>>> [Statistics/Behavioural] Detailed View and Double Data Entry - Site permission fix (#6861)
>>>>>>> [Statistics/Behavioural] Detailed View and Double Data Entry - Site permission fix (#6861)
}

/**
Expand All @@ -100,25 +110,54 @@ class Statistics_Site extends \NDB_Menu
{

//SITES
<<<<<<< ab9b95f084e392fe6cfca355aeeddf073af79caf

$factory = \NDB_Factory::singleton();
$user = $factory->user();

=======

$factory = \NDB_Factory::singleton();
$user = $factory->user();

>>>>>>> [Statistics/Behavioural] Detailed View and Double Data Entry - Site permission fix (#6861)
if (!empty($centerID) && $user->hasCenter($centerID)) {
$this->query_criteria .= " AND s.CenterID =:cid ";
$this->query_vars['cid'] = $centerID;
} else {
<<<<<<< ab9b95f084e392fe6cfca355aeeddf073af79caf
$list_of_permitted_sites = [];
=======
<<<<<<< ff9cfba5feee88a24470e463aef0117915aff1a4
$list_of_permitted_sites = (array) null;
$currentUser = \NDB_Factory::singleton()->user();
=======
$list_of_permitted_sites = array();
>>>>>>> [Statistics/Behavioural] Detailed View and Double Data Entry - Site permission fix (#6861)
>>>>>>> [Statistics/Behavioural] Detailed View and Double Data Entry - Site permission fix (#6861)

if ($user->hasPermission('access_all_profiles')) {
$list_of_permitted_sites = array_keys(\Utility::getSiteList());
} else {
$list_of_permitted_sites = array_keys($user->getStudySites());
}

<<<<<<< ab9b95f084e392fe6cfca355aeeddf073af79caf
if (!empty($list_of_permitted_sites)) {
$paramCenters = [];
$centerIDs = [];
=======
<<<<<<< ff9cfba5feee88a24470e463aef0117915aff1a4
$params = [];
$centerIDs = [];
foreach ($list_of_permitted_sites as $key => $siteID) {
$params[] = ":id$key";
$centerIDs["id$key"] = $siteID;
=======
if (!empty($list_of_permitted_sites)) {
$paramCenters = array();
$centerIDs = array();
>>>>>>> [Statistics/Behavioural] Detailed View and Double Data Entry - Site permission fix (#6861)
foreach ($list_of_permitted_sites as $key => $siteID) {
$paramCenters[] = ":paramSiteID$key";
$centerIDs["paramSiteID$key"] = $siteID;
Expand All @@ -130,6 +169,10 @@ class Statistics_Site extends \NDB_Menu
$this->query_vars += $centerIDs;
} else {
$this->query_criteria .= "AND (s.CenterID IS NULL)";
<<<<<<< ab9b95f084e392fe6cfca355aeeddf073af79caf
=======
>>>>>>> [Statistics/Behavioural] Detailed View and Double Data Entry - Site permission fix (#6861)
>>>>>>> [Statistics/Behavioural] Detailed View and Double Data Entry - Site permission fix (#6861)
}
}

Expand All @@ -141,8 +184,13 @@ class Statistics_Site extends \NDB_Menu
} else {
$userProjectsIDs = $user->getData('ProjectIDs');
if (!empty($userProjectsIDs)) {
<<<<<<< ab9b95f084e392fe6cfca355aeeddf073af79caf
$paramProjects = [];
$projectsIDs = [];
=======
$paramProjects = array();
$projectsIDs = array();
>>>>>>> [Statistics/Behavioural] Detailed View and Double Data Entry - Site permission fix (#6861)
foreach ($userProjectsIDs as $key => $projectID) {
$paramProjects[] = ":paramProjectID$key";
$projectsIDs["paramProjectID$key"] = $projectID;
Expand Down

0 comments on commit 47f5e18

Please # to comment.