Skip to content

Commit

Permalink
Use REDCap's values for User Rights
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewPoppe committed Dec 18, 2023
1 parent fa86c8b commit b1a9ee2
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 49 deletions.
9 changes: 9 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,19 @@ The file used to import SAGs must be a CSV file with the following columns:
.^|`user_rights`
.^|User Rights
.^a|
Prior to REDCap v14.1.0:

* `0` - Not allowed
* `1` - Allowed

As of REDCap v14.1.0:

* `0` - No access
* `2` - Read only
* `1` - View & Edit

_**Note**: The counterintuitive values here break with the general pattern of this module (in which higher values correspond with more permissions) in order to aid in maintaining backwards compatibility and prevent errors with this very important permission._

.^|`data_access_groups`
.^|Data Access Groups
.^a|
Expand Down
26 changes: 24 additions & 2 deletions README.html
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,10 @@ <h4 id="sag_import_file_format"><a class="link" href="#sag_import_file_format">S
<tr>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>user_rights</code></p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">User Rights</p></td>
<td class="tableblock halign-left valign-middle"><div class="content"><div class="ulist">
<td class="tableblock halign-left valign-middle"><div class="content"><div class="paragraph">
<p>Prior to REDCap v14.1.0:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>0</code> - Not allowed</p>
Expand All @@ -998,6 +1001,25 @@ <h4 id="sag_import_file_format"><a class="link" href="#sag_import_file_format">S
<p><code>1</code> - Allowed</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>As of REDCap v14.1.0:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>0</code> - No access</p>
</li>
<li>
<p><code>2</code> - Read only</p>
</li>
<li>
<p><code>1</code> - View &amp; Edit</p>
</li>
</ul>
</div>
<div class="paragraph">
<p><em><strong>Note</strong>: The counterintuitive values here break with the general pattern of this module (in which higher values correspond with more permissions) in order to aid in maintaining backwards compatibility and prevent errors with this very important permission.</em></p>
</div></div></td>
</tr>
<tr>
Expand Down Expand Up @@ -2233,7 +2255,7 @@ <h2 id="_changelog"><a class="link" href="#_changelog">Changelog</a></h2>
</div>
<div id="footer">
<div id="footer-text">
Last updated 2023-12-12 14:13:31 -0500
Last updated 2023-12-18 13:55:46 -0500
</div>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion SecurityAccessGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SecurityAccessGroups extends AbstractExternalModule
public function redcap_every_page_before_render() : void
{
// Only run on the pages we're interested in
if (!defined('PAGE') || !isset($_SERVER)) {
if ( !defined('PAGE') || !isset($_SERVER) ) {
return;
}
$method = $_SERVER['REQUEST_METHOD'] ?? '';
Expand Down
2 changes: 1 addition & 1 deletion classes/RightsChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ private function checkUserRightsRight($right, $value)
if ( $value == '1' && $userRights != 1 ) {
$rightName = $mainRight . ($newVersion ? ' - ' . RightsUtilities::getDisplayTextForRight('viewAndEdit') : '');
$this->badRights[] = $rightName;
} elseif ( $value == '2' && $userRights != 2 ) {
} elseif ( $value == '2' && $userRights == 0 ) {
$rightName = $mainRight . ($newVersion ? ' - ' . RightsUtilities::getDisplayTextForRight('readOnly') : '');
$this->badRights[] = $rightName;
}
Expand Down
39 changes: 0 additions & 39 deletions classes/RightsUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,44 +70,6 @@ public static function convertDataEntryRightsStringToArray($fullRightsString)
return $result;
}

/**
* Converts the User Rights permission values from the SAG user-facing format to the interal format that is also used by REDCap.
*
* This function can be used to convert in either direction.
*
* Prior to REDCap 14.1.0, the user_rights field was:
* 0: No access
* 1: View and edit
*
* Starting with REDCap 14.1.0, the user_rights field is:
* 0: No access
* 2: View only
* 1: View and edit
*
* For user-facing purposes (e.g., CSV Import), we want higher values to always mean more permission, so if REDCap 14.1.0 or later, we need to swap 1 and 2.
* This results in:
*
* 0: No access
* 1: View only
* 2: View and edit
*
* @param array $rights
* @return array $rights
*/
public static function convertUserRights($rights)
{
$redcapVersion = defined('REDCAP_VERSION') ? REDCAP_VERSION : '99.99.99';
if ( \REDCap::versionCompare($redcapVersion, '14.1.0') >= 0 ) {
if ( $rights['user_rights'] == 1 ) {
$rights['user_rights'] = 2;
} else if ( $rights['user_rights'] == 2 ) {
$rights['user_rights'] = 1;
}
}
return $rights;
}


private static function convertDoubleData($rights)
{
// 0: Reviewer
Expand Down Expand Up @@ -146,7 +108,6 @@ public static function convertPermissions(string $permissions)
$rights = json_decode($permissions, true);
$rights = self::convertDataQualityResolution($rights);
$rights = self::convertDoubleData($rights);
$rights = self::convertUserRights($rights);
foreach ( $rights as $key => $value ) {
if ( $value === 'on' ) {
$rights[$key] = 1;
Expand Down
12 changes: 6 additions & 6 deletions classes/SAGEditForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,16 @@ private function getUserRights()
for='user_rights_0'>$label2</label>
</div>
<div class='form-check'>
<input class='form-check-input' type='radio' id='user_rights_1'
name='user_rights' $readChecked value='1'>
<input class='form-check-input' type='radio' id='user_rights_2'
name='user_rights' $readChecked value='2'>
<label class='form-check-label'
for='user_rights_1'>$label3</label>
for='user_rights_2'>$label3</label>
</div>
<div class='form-check'>
<input class='form-check-input' type='radio' id='user_rights_2'
name='user_rights' $viewAndEditChecked value='2'>
<input class='form-check-input' type='radio' id='user_rights_1'
name='user_rights' $viewAndEditChecked value='1'>
<label class='form-check-label'
for='user_rights_2'>$label4</label>
for='user_rights_1'>$label4</label>
</div>
</div>
</div>
Expand Down

0 comments on commit b1a9ee2

Please sign in to comment.