|
18 | 18 | * @link https://www.github.com/Jkat/Loris-Trunk/ |
19 | 19 | */ |
20 | 20 |
|
21 | | -if (!\User::singleton()->hasPermission('imaging_uploader')) { |
| 21 | +// Base access check - user must have either of these permissions |
| 22 | +// more access validation after request validation |
| 23 | +if (!$user->hasAnyPermission( |
| 24 | + [ |
| 25 | + 'imaging_uploader_allsites', |
| 26 | + 'imaging_uploader_ownsites', |
| 27 | + ] |
| 28 | +) |
| 29 | +) { |
22 | 30 | http_response_code(403); |
23 | 31 | return; |
24 | 32 | } |
| 33 | +$config = \NDB_Factory::singleton()->config(); |
| 34 | +$advancedperms = $config->getSetting('useAdvancedPermissions'); |
| 35 | +$user = \NDB_Factory::singleton()->user(); |
| 36 | +$centerString = implode("','", $user->getCenterIDs()); |
| 37 | +$projectString = implode("','", $user->getProjectIDs()); |
| 38 | +$username = $user->getUsername(); |
| 39 | + |
25 | 40 | if (!validRequest()) { |
26 | 41 | http_response_code(400); |
27 | 42 | return; |
28 | 43 | } |
29 | 44 |
|
30 | 45 | $uploadId = $_POST['uploadId']; |
31 | 46 | $summary = $_POST['summary'] === 'true'; |
| 47 | +$DB = \NDB_Factory::singleton()->database(); |
| 48 | + |
| 49 | +// Access Control - mimic menu filter behaviour |
| 50 | +// MySQL order of operations dictates that ANDs get computed before ORs which |
| 51 | +// means this where clause can take the follwoing forms |
| 52 | +// 1. WHERE mu.UploadedBy='$username' OR 1=1 |
| 53 | +// -> returns all records |
| 54 | +// 2. WHERE mu.UploadedBy='$username' OR (1=1 AND s.CenterID IN ...) |
| 55 | +// -> returns records for user's sites |
| 56 | +// 3. WHERE mu.UploadedBy='$username' OR (1=1 AND s.ProjectID IN ...) |
| 57 | +// -> returns records for user's projects |
| 58 | +// 4. WHERE mu.UploadedBy='$username' |
| 59 | +// OR (1=1 AND s.CenterID IN ... AND s.ProjectID IN ...) |
| 60 | +// -> returns records for user's sites and projects |
| 61 | +// 5. WHERE mu.UploadedBy='$username' |
| 62 | +// OR (1=1 AND s.CenterID IN ... AND s.ProjectID IN ...) |
| 63 | +// OR mu.SessionID IS NULL |
| 64 | +// -> returns records for user's sites and projects and null session data |
| 65 | +// Other combinations are possible but order of operations still applies |
| 66 | +$accessQuery = "SELECT * |
| 67 | + FROM mri_upload mu |
| 68 | + LEFT JOIN session s ON (s.ID = mu.SessionID) |
| 69 | + "; |
| 70 | +$accessWhere = " WHERE (mu.UploadedBy='$username' OR 1=1 "; |
| 71 | +if (!$user->hasPermission('imaging_uploader_allsites')) { |
| 72 | + // Create where clause for sites |
| 73 | + $accessWhere = $accessWhere . " AND s.CenterID IN ('$centerString') "; |
| 74 | +} |
| 75 | + |
| 76 | +if ($advancedperms === 'true') { |
| 77 | + // If config setting is enabled, check the user's sites and projects |
| 78 | + // site/project match + user's own uploads |
| 79 | + $accessWhere = $accessWhere . " AND s.ProjectID IN ('$projectString')"; |
| 80 | +} |
| 81 | + |
| 82 | +if ($user->hasPermission('imaging_uploader_nosessionid')) { |
| 83 | + // clause for accessing null session data |
| 84 | + $accessWhere = $accessWhere . " OR mu.SessionID IS NULL "; |
| 85 | +} |
| 86 | + |
| 87 | +// Wrap entire access logic in parentheses and add AND clause for specific upload ID |
| 88 | +$accessWhere = $accessWhere . ") AND UploadId =:uploadId"; |
| 89 | + |
| 90 | +$accessData = $DB->pselectRow( |
| 91 | + $accessQuery.$accessWhere, |
| 92 | + ['uploadId' => $uploadId] |
| 93 | +); |
| 94 | + |
| 95 | + |
| 96 | +if (empty($accessData)) { |
| 97 | + http_response_code(403); |
| 98 | + return; |
| 99 | +} |
| 100 | + |
32 | 101 |
|
33 | 102 | /* Fetch columns Inserting and InsertionComplete from table mri_upload |
34 | 103 | * create Database object |
35 | 104 | */ |
36 | | -$DB = \NDB_Factory::singleton()->database(); |
37 | 105 | $query = "SELECT Inserting, InsertionComplete |
38 | 106 | FROM mri_upload |
39 | 107 | WHERE UploadId =:uploadId"; |
|
0 commit comments