Working …
This value you provided is not a number. Please try again.
This value you provided is not an integer. Please try again.
The value entered is not a valid Vanderbilt Medical Record Number (i.e. 4- to 9-digit number, excluding leading zeros). Please try again.
The value you provided must be within the suggested range
The value you provided is outside the suggested range
This value is admissible, but you may wish to double check it.
The value entered must be a time value in the following format HH:MM within the range 00:00-23:59 (e.g., 04:32 or 23:19).
This field must be a 5 or 9 digit U.S. ZIP Code (like 94043). Please re-enter it now.
This field must be a 10 digit U.S. phone number (like 415 555 1212). Please re-enter it now.
This field must be a valid email address (like joe@user.com). Please re-enter it now.
The value you provided could not be validated because it does not follow the expected format. Please try again.
Required format:
REDCap Logo
Plugins, Hooks, & External Modules
Developer methods for
Plugins, Hooks, & External Modules
Hook functions

REDCap Developer Tools:
Documentation for Plugins, Hooks, & External Modules

REDCap Version 14.9.1
REDCap::getUserRights
(REDCap >= 5.5.0)
REDCap::getUserRights — Returns a list of the user privileges for all users for the current project
Description
array REDCap::getUserRights ( [ string $username = NULL ] )
Returns a list of the user privileges for all users for the current project. If $username is specified as a single user's username, it will only return the user rights of that user. If a user is assigned to a role, then their user rights returned will reflect the role's rights.
Parameters
username
Username of an individual user. If provided, it will only return the user rights of that user only. By default, NULL is used, in which it will return the user rights of all users for the current project.
Return Values
Returns array of user privileges with usernames as 1st-level array keys and the rights attribute name as the 2nd-level array keys (the rights attribute names the column names come from the redcap_user_rights database table). NOTE: The usernames will *always* be returned in lowercase format as the array keys.
Restrictions
This method can ONLY be used in a project context (i.e. when "pid" parameter is in the query string of the plugin URL) or else a fatal error is produced.
Examples
Example #1:
This example shows how one can loop through the rights of all users in a project to see which users' rights have expired. This examples uses the REDCap constant TODAY, which represents today's date in YMD format (e.g., 2013-07-18).
// Get array of user privileges of all users in project
$rights = REDCap::getUserRights();

// For all users whose rights have expired, place their username into an array
$expired_users = array();
foreach ($rights as $this_username=>$these_rights) {
    // If user's expiration occurs before TODAY, then add to array
    if ($these_rights['expiration'] != "" && $these_rights['expiration'] < TODAY) {
        // Add to array
        $expired_users[] = $this_username;
    }
}

// Display expired users
var_dump($expired_users);
Example #2:
This example illustrates how one can check particular user privileges of a single user, specifically if the user has been granted the ability to create new records and if they are assigned to a data access group.
// Manually set username of single user in project
$this_user = 'jon_williams';

// Get array of user privileges for a single user in project (will have username as array key)
$rights = REDCap::getUserRights($this_user);

// If $rights returns NULL, then user does not have access to this project
if (empty($rights)) exit("User $this_user does NOT have access to this project.");

// Check if user can create new records
if ($rights[$this_user]['record_create']) {
    print "User $this_user CAN create records.\n";
} else {
    print "User $this_user CANNOT create records.\n";
}

// Check if the user is in a data access group (DAG)
$group_id = $rights[$this_user]['group_id'];
// If $group_id is blank, then user is not in a DAG
if ($group_id == '') {
    print "User $this_user is NOT assigned to a data access group.";
} else {
    // User is in a DAG, so get the DAG's name to display
    print "User $this_user is assigned to the DAG named \"" . REDCap::getGroupNames(false, $group_id)
        . "\", whose unique group name is \"" . REDCap::getGroupNames(true, $group_id) . "\".";
}

REDCap 14.9.1 - © 2024 Vanderbilt University