Skip to content

Commit 8dc07f1

Browse files
committed
Handle form permissions both < and >= v15.7.0
1 parent ed94ff8 commit 8dc07f1

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

InstanceTable.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,15 +381,15 @@ protected function checkUserPermissions() {
381381
$repeatingFormDetails['permission_level'] = "read-only"; // always read only in survey view
382382
} else if ($repeatingFormDetails['hide_add_btn']) {
383383
$repeatingFormDetails['permission_level'] = "read-only"; // Hide "Add" button = "read only" (effectively!)
384-
} else if ($repeatingFormDetails['permission_level'] > -1) {
384+
} else {
385385
$permissionLevel = $this->user_rights['forms'][$repeatingFormDetails['form_name']];
386-
if (\UserRights::hasDataViewingRights($permissionLevel, "view-edit")) {
386+
if ($this->hasDataViewingRights($permissionLevel, "view-edit")) {
387387
$repeatingFormDetails['permission_level'] = "view-edit";
388388
}
389-
else if (\UserRights::hasDataViewingRights($permissionLevel, "read-only")) {
389+
else if ($this->hasDataViewingRights($permissionLevel, "read-only")) {
390390
$repeatingFormDetails['permission_level'] = "read-only";
391391
}
392-
else if (\UserRights::hasDataViewingRights($permissionLevel, "no-access")) {
392+
else if ($this->hasDataViewingRights($permissionLevel, "no-access")) {
393393
$repeatingFormDetails['permission_level'] = "no-access";
394394
}
395395
else {
@@ -400,6 +400,21 @@ protected function checkUserPermissions() {
400400
}
401401
}
402402

403+
protected function hasDataViewingRights($permissionLevel, $permission) {
404+
if (version_compare(REDCAP_VERSION, '15.7.0', '>=')) {
405+
return \UserRights::hasDataViewingRights($permissionLevel, $permission);
406+
} else {
407+
if ($permission=='view-edit' && ($permissionLevel==1 || $permissionLevel==3)) return true;
408+
if ($permission=='read-only' && ($permissionLevel==1 || $permissionLevel==3)) return true;
409+
switch ($permission) {
410+
case 'view-edit'; if ($permissionLevel==1 || $permissionLevel==3) return true; break;
411+
case 'read-only'; if ($permissionLevel==2) return true; break;
412+
case 'no-access'; if ($permissionLevel==0) return true; break;
413+
default : return 'error';
414+
}
415+
}
416+
}
417+
403418
protected function setMarkup() {
404419
foreach ($this->taggedFields as $key => $repeatingFormDetails) {
405420
switch ($repeatingFormDetails['permission_level']) {

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ The vast majority of this module's functionality is provided via the action tags
6060
* `@INSTANCETABLE-HIDECHOICEVALUES`: Suppress the display of choice field values and show only choice labels.
6161
* `@INSTANCETABLE-HIDEFORMSTATUS`: Suppress display of the form status field in data entry view. (The form status field is always suppressed in survey mode.)
6262
* `@INSTANCETABLE-HIDEFORMINMENU`: Hide the link to the repeating form in the Data Collection section of the project page menu.
63-
* `@INSTANCETABLE-SORTCOL=n[:direction]`: Specify the column index for the default table sort. The index number should be a positive integer, with <code>1</code> being the first column (i.e. instance number, which is always present even if hidden using `@INSTANCETABLE-HIDEINSTANCECOL`). Direction is optional and can be `asc` (default) or `desc` (case-insensitive) for ascending or descending respectively. The default sort in the absence of this tag is on the first column in ascending order, i.e. `@INSTANCETABLE-SORTCOL=1:asc]`. Note that your browser will remember any custom sorting that you apply, therefore this setting only applies a default sort when you first view an instance table.
63+
* `@INSTANCETABLE-SORTCOL=n[:direction]`: Specify the column index for the default table sort. The index number should be a positive integer, with <code>1</code> being the first column (i.e. instance number, which is always present even if hidden using `@INSTANCETABLE-HIDEINSTANCECOL`). Direction is optional and can be `asc` (default) or `desc` (case-insensitive) for ascending or descending respectively. The default sort in the absence of this tag is on the first column in ascending order, i.e. `@INSTANCETABLE-SORTCOL=1:asc`. Note that your browser will remember any custom sorting that you apply, therefore this setting only applies a default sort when you first view an instance table.
6464
* `@INSTANCETABLE-PREFILL=rptformvar=[pagevar]`: Have fields on new instances pre-filled with data from the current form (or elsewhere on the record) using `fieldname=value` pairs in the URL in a manner similar to survey form field pre-filling.
6565

6666
### Tags Used for Fields on a Repeating Form

0 commit comments

Comments
 (0)