Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Instrument] Remove exception from NDB_BVL_Instrument::factory #8290

Merged
merged 3 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion htdocs/survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,16 @@ function initialize()
throw new Exception("Data has already been submitted.", 403);
}

$instrumentObj = \NDB_BVL_Instrument::factory(
$instrumentObj = \NDB_BVL_Instrument::factory(
$this->loris,
$this->TestName,
);

$user = \User::singleton();
if ($instrumentObj->_hasAccess($user) !== true) {
throw new \Exception("Permission denied", 403);
}

$subtests = $instrumentObj->getSubtestList();
$this->NumPages = count($subtests) + 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ class Instruments extends Endpoint implements \LORIS\Middleware\ETagCalculator
'',
true
);

$user = $request->getAttribute('user');
if ($instrument->_hasAccess($user) == false) {
return new \LORIS\Http\Response\JSON\Forbidden();
};
} catch (\Exception $e) {
return new \LORIS\Http\Response\JSON\NotFound();
}
Expand Down
5 changes: 5 additions & 0 deletions modules/api/php/endpoints/project/instruments.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ class Instruments extends Endpoint implements \LORIS\Middleware\ETagCalculator
'',
true
);

$user = $request->getAttribute("user");
if ($instrument->_hasAccess($user) == false) {
return new \LORIS\Http\Response\JSON\Forbidden();
}
} catch (\Exception $e) {
return new \LORIS\Http\Response\JSON\NotFound();
}
Expand Down
5 changes: 5 additions & 0 deletions modules/conflict_resolver/php/endpoints/unresolved.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ class Unresolved extends Endpoint implements ETagCalculator
'',
true
);
if ($instrument->_hasAccess($user) == false) {
return new \LORIS\Http\Response\JSON\Forbidden(
'Permission denied for ' . $conflict['TableName']
);
}
$instrument->_saveValues(
[$conflict['FieldName'] => $conflict['CorrectAnswer']]
);
Expand Down
8 changes: 8 additions & 0 deletions modules/datadict/php/datadict.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Datadict extends \DataFrameworkMenu
{
$instruments = \Utility::getAllInstruments();
$dictInstruments = [];

foreach ($instruments as $instrument => $name) {
// Since the testname does not always match the table name in the
// database we need to instantiate the object to get the table name
Expand All @@ -70,6 +71,13 @@ class Datadict extends \DataFrameworkMenu
'',
''
);
if ($iObj->_hasAccess($user)) {
$this->logger->debug(
"Skipping $instrument in field options"
. " because user does not have permission"
);
continue;
}
} catch (\Exception $e) {
error_log(
"There was a problem instantiating the instrument ".
Expand Down
8 changes: 7 additions & 1 deletion modules/instruments/php/module.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ class Module extends \Module
$page
);

$user = $request->getAttribute("user");
if ($instrument->_hasAccess($user) == false) {
return (new \Laminas\Diactoros\Response())
->withStatus(403)
->withBody(new \LORIS\Http\StringStream("Permission denied"));
}

$request = $request->withAttribute('pageclass', $instrument);

return $instrument->process($request, $instrument);
Expand Down Expand Up @@ -151,4 +158,3 @@ class Module extends \Module
return [];
}
}

13 changes: 11 additions & 2 deletions modules/instruments/php/visitsummary.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class VisitSummary extends \NDB_Page
return $this->_handleGET(
new CandID($params['CandID']),
$params['VisitLabel'],
$user,
);
default:
return new \LORIS\Http\Response\JSON\MethodNotAllowed(
Expand All @@ -61,15 +62,16 @@ class VisitSummary extends \NDB_Page
}

/**
* Helper to specifically handle PATCH HTTP methods to the endpoint.
* Helper to specifically handle GET HTTP methods to the endpoint.
*
* @param CandID $candid The CandID for the visit.
* @param string $visitLabel The visit label string.
* @param \User $user The user accessing the endpoint
*
* @return ResponseInterface
*/
private function _handleGET(
CandID $candid, string $visitLabel
CandID $candid, string $visitLabel, \User $user
) : ResponseInterface {
$DB = \NDB_Factory::singleton()->database();

Expand Down Expand Up @@ -111,6 +113,13 @@ class VisitSummary extends \NDB_Page
'',
false
);
if ($instrument->_hasAccess($user) == false) {
ridz1208 marked this conversation as resolved.
Show resolved Hide resolved
$this->logger->debug(
"Skipping $testName"
. " because user does not have permission"
);
continue;
}
if ($instrument === null) {
$bvl_result[$key]['Completion'] = 0;
} else {
Expand Down
15 changes: 1 addition & 14 deletions php/libraries/NDB_BVL_Instrument.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -308,17 +308,6 @@ abstract class NDB_BVL_Instrument extends NDB_Page
$base . "project/instruments/$instrument.rules"
);

$user = \User::singleton();
$access = $obj->_hasAccess($user);

// check that user has access
if ($access == false) {
throw new Exception(
"You do not have access to this page.",
403
);
}

return $obj;
}

Expand Down Expand Up @@ -380,9 +369,7 @@ abstract class NDB_BVL_Instrument extends NDB_Page
return true;
}
}

//no user permissions match required instrument permissions
throw new Exception("You do not have access to this page.", 403);
return false;
ridz1208 marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down