Skip to content

Commit

Permalink
[API] Adding checkign user permission
Browse files Browse the repository at this point in the history
  • Loading branch information
spell00 committed Nov 4, 2020
1 parent 3cd3a66 commit 40afcfc
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions modules/api/php/endpoints/project/dicoms.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ class Dicoms extends Endpoint implements \LORIS\Middleware\ETagCalculator
*/
private $_project;

/**
* Permission checks
*
* @param \User $user The requesting user
*
* @return boolean true if access is permitted
*/
private function _hasAccess(\User $user)
{
return (
$user->hasPermission('dicom_archive_view_allsites') ||
(
$user->hasStudySite()
&& $user->hasPermission('dicom_archive_view_allsites')
)
);
}

/**
* Contructor
*
Expand Down Expand Up @@ -78,6 +96,15 @@ class Dicoms extends Endpoint implements \LORIS\Middleware\ETagCalculator
*/
public function handle(ServerRequestInterface $request) : ResponseInterface
{
$user = $request->getAttribute('user');
if ($user instanceof \LORIS\AnonymousUser) {
return new \LORIS\Http\Response\JSON\Unauthorized();
}

if (!$this->_hasAccess($user)) {
return new \LORIS\Http\Response\JSON\Forbidden();
}

$pathparts = $request->getAttribute('pathparts');
if (count($pathparts) !== 0) {
return new \LORIS\Http\Response\JSON\NotFound();
Expand Down Expand Up @@ -125,12 +152,7 @@ class Dicoms extends Endpoint implements \LORIS\Middleware\ETagCalculator
'\LORIS\api\Models\ProjectDicomsObject'
);

$all = $provisioner->getAllInstances();

$dicoms = [];
foreach ($all as $value) {
array_push($dicoms, $value);
}
$dicoms = iterator_to_array($provisioner->getAllInstances());

$this->_cache = new \LORIS\Http\Response\JsonResponse(
['Dicoms' => $dicoms]
Expand Down

0 comments on commit 40afcfc

Please sign in to comment.