Skip to content

Commit 7c5810a

Browse files
authored
[dataquery/dictionary] Remove instruments and visits that the user doesnt have access to (#9903)
- Created a function in the User class to getVisits that the user can access based on the Projects they have access to * Resolves #9894
1 parent 36a34b3 commit 7c5810a

File tree

17 files changed

+81
-72
lines changed

17 files changed

+81
-72
lines changed

modules/behavioural_qc/php/behavioural.class.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class Behavioural extends \NDB_Page implements ETagCalculator
9292
ServerRequestInterface $request
9393
) : array {
9494
$user = $request->getAttribute('user');
95-
$visit_array = \Utility::getVisitList();
95+
$visit_array = $user->getVisits();
9696
$userProjects = $user->getProjects();
9797
$projects = [];
9898
foreach ($userProjects as $project) {

modules/candidate_list/php/candidate_list.class.inc

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -70,58 +70,9 @@ class Candidate_List extends \DataFrameworkMenu
7070
*/
7171
function getFieldOptions() : array
7272
{
73-
$this->loris->getModule('candidate_parameters')->registerAutoloader();
74-
75-
// create user object
76-
$factory = \NDB_Factory::singleton();
77-
$user = $factory->user();
78-
$config = $factory->config();
79-
80-
// get the list of visit labels
81-
$visit_label_options = \Utility::getVisitList();
82-
83-
// get the list of sites available for the user
84-
if ($user->hasPermission('access_all_profiles')) {
85-
$list_of_sites = \Utility::getSiteList();
86-
} else {
87-
$list_of_sites = $user->getStudySites();
88-
}
89-
$site_options = [];
90-
foreach (array_values($list_of_sites) as $name) {
91-
$site_options[$name] = $name;
92-
}
93-
94-
// get the list of projects
95-
$list_of_projects = \Utility::getProjectList();
96-
$project_options = [];
97-
foreach (array_values($list_of_projects) as $name) {
98-
$project_options[$name] = $name;
99-
}
100-
101-
// get the list of cohorts
102-
$list_of_cohorts = \Utility::getCohortList();
103-
$cohort_options = [];
104-
foreach (array_values($list_of_cohorts) as $name) {
105-
$cohort_options[$name] = $name;
106-
}
107-
108-
// get the list participant status options
109-
$list_of_participant_status
110-
= \Candidate::getParticipantStatusOptions();
111-
$participant_status_options = [];
112-
foreach (array_values($list_of_participant_status) as $name) {
113-
$participant_status_options[$name] = $name;
114-
}
115-
116-
return [
117-
'visitlabel' => $visit_label_options,
118-
'site' => $site_options,
119-
'project' => $project_options,
120-
'cohort' => $cohort_options,
121-
'participantstatus' => $participant_status_options,
122-
'useedc' => $config->getSetting("useEDC"),
123-
'Sex' => \Utility::getSexList(),
124-
];
73+
// To modify the field options,
74+
// you must edit getFieldOptions in options.class.inc
75+
return [];
12576
}
12677

12778
/**

modules/candidate_list/php/options.class.inc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ class Options extends \LORIS\Http\Endpoint
4747
$user = $factory->user();
4848
$config = $factory->config();
4949

50-
// get the list of visit labels
51-
$visit_label_options = \Utility::getVisitList();
50+
// get the list of visit labels that the user has access to
51+
$visit_label_options = $user->getVisits();
5252

5353
// get the list of sites available for the user
5454
if ($user->hasPermission('access_all_profiles')) {
@@ -62,7 +62,8 @@ class Options extends \LORIS\Http\Endpoint
6262
}
6363

6464
// get the list of projects
65-
$list_of_projects = \Utility::getProjectList();
65+
// $list_of_projects = \Utility::getProjectList();
66+
$list_of_projects = $user->getProjectNames();
6667
$project_options = [];
6768
foreach (array_values($list_of_projects) as $name) {
6869
$project_options[$name] = $name;

modules/candidate_parameters/php/candidatequeryengine.class.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,10 @@ class CandidateQueryEngine extends \LORIS\Data\Query\SQLQueryEngine
250250
if ($item->getScope()->__toString() !== 'session') {
251251
return [];
252252
}
253+
$user = \NDB_Factory::singleton()->user();
253254

254255
// Session scoped variables: VisitLabel, project, site, cohort
255-
return array_keys(\Utility::getVisitList());
256+
return array_keys($user->getVisits());
256257
}
257258

258259
/**

modules/dataquery/php/visitlist.class.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class VisitList extends \NDB_Page
1616
protected $itemmodule;
1717
protected $itemcategory;
1818
protected $dictionaryitem;
19+
protected $user;
1920

2021
/**
2122
* {@inheritDoc}
@@ -28,9 +29,7 @@ class VisitList extends \NDB_Page
2829
{
2930
if ($this->dictionaryitem === null) {
3031
return new \LORIS\Http\Response\JSON\OK(
31-
[
32-
'Visits' => array_values(\Utility::getVisitList()),
33-
],
32+
['Visits' => array_values($this->user->getVisits())],
3433
);
3534
}
3635

@@ -62,6 +61,7 @@ class VisitList extends \NDB_Page
6261
\User $user,
6362
ServerRequestInterface $request,
6463
) : void {
64+
$this->user = $user;
6565
$queryparams = $request->getQueryParams();
6666
if (!isset($queryparams['module']) || !isset($queryparams['item'])) {
6767
return;

modules/dictionary/php/dictionary.class.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Dictionary extends \DataFrameworkMenu
6363
$cohort_options[$name] = $name;
6464
}
6565
$visit_options = [];
66-
foreach (\Utility::getVisitList() as $visit) {
66+
foreach ($user->getVisits() as $visit) {
6767
$visit_options[$visit] = $visit;
6868
}
6969
return [

modules/dictionary/php/module.class.inc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ class Module extends \Module
8888
$categories = [];
8989

9090
$categoryitems = [];
91+
92+
// Get the instruments that the user has access to based on their Projects
93+
$userVisits = $user->getVisits();
94+
$instruments = [];
95+
foreach ($userVisits as $visitLabel => $_) {
96+
$visitInstruments = \Utility::getVisitInstruments($visitLabel);
97+
foreach ($visitInstruments as $testName => $fullName) {
98+
if (!isset($instruments[$testName])) {
99+
$instruments[$testName] = $fullName;
100+
}
101+
}
102+
}
91103
foreach ($modules as $module) {
92104
if ($formodule !== null && $module->getName() !== $formodule) {
93105
continue;
@@ -104,6 +116,11 @@ class Module extends \Module
104116
$categories[$mname] = [];
105117

106118
foreach ($mdict as $cat) {
119+
if ($mname === 'instruments'
120+
&& !isset($instruments[$cat->getName()])
121+
) {
122+
continue;
123+
}
107124
$categories[$mname][$cat->getName()] = $cat->getDescription();
108125
$categoryitems[] = [
109126
'Module' => $module,

modules/electrophysiology_uploader/php/electrophysiology_uploader.class.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Electrophysiology_Uploader extends \DataFrameworkMenu
7777

7878
return [
7979
'sites' => $site_options,
80-
'visitLabel' => \Utility::getVisitList(),
80+
'visitLabel' => $user->getVisits(),
8181
];
8282
}
8383

modules/imaging_browser/php/queryengine.class.inc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,11 @@ class QueryEngine extends \LORIS\Data\Query\SQLQueryEngine
357357
return $visits;
358358
}
359359

360-
// Fall back on all visits if something ends up getting
360+
$user = \NDB_Factory::singleton()->user();
361+
362+
// Fall back on user visits if something ends up getting
361363
// added that we can't derive the modality of.
362-
return array_keys(\Utility::getVisitList());
364+
return array_keys($user->getVisits());
363365
}
364366

365367
/**

modules/imaging_uploader/php/imaging_uploader.class.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ class Imaging_Uploader extends \NDB_Menu_Filter_Form
160160
'N' => 'No',
161161
'Y' => 'Yes',
162162
];
163-
$visitlabels = \Utility::getVisitList();
163+
$user = \NDB_Factory::singleton()->user();
164+
$visitlabels = $user->getVisits();
164165
// Fields used for selection filter and upload form
165166
$this->addSelect('IsPhantom', 'Phantom Scans', $phantomOtions);
166167
$this->addBasicText('candID', 'CandID');

0 commit comments

Comments
 (0)