25  Users and User Roles

REDCap allows strict control of user rights for each project. These rights include a user’s ability to edit, export and view data, add or edit reports, import data, create records, etc. Privileges to view and export data are specified for each instrument.

User roles can be set with predefined privileges and users can then be assigned to these user role groups.

25.1 Users

Cannot be imported with REDCapR. See Section 27.1 for more information.

import_users()

In this example, we will export the project’s users and re-import it so that no changes are made to the project.

users = project.export_users(format_type='df')
users
username email firstname lastname expiration data_access_group data_access_group_id design alerts user_rights ... mobile_app mobile_app_download_data record_create record_rename record_delete lock_records_all_forms lock_records lock_records_customization forms forms_export
0 alexey.gilman@doh.wa.gov Alexey.Gilman@doh.wa.gov Alexey Gilman NaN NaN NaN 1 1 1 ... 1 0 1 1 1 0 0 1 demographics:3,symptoms:1,test_information:1,c... demographics:1,symptoms:1,test_information:1,c...
1 caitlin.drover@doh.wa.gov Caitlin.Drover@doh.wa.gov Caitlin Drover NaN NaN NaN 1 1 1 ... 1 0 1 1 1 0 0 1 demographics:3,symptoms:1,test_information:1,c... demographics:1,symptoms:1,test_information:1,c...
2 emily.pearman@doh.wa.gov emily.pearman@doh.wa.gov Emily Pearman NaN NaN NaN 1 1 1 ... 1 1 1 1 1 0 0 0 demographics:1,symptoms:1,test_information:1,c... demographics:1,symptoms:1,test_information:1,c...

3 rows × 34 columns

project.import_users(users, import_format='df')
3

Note: attemping to import a user already assigned to a user role will result in an error.

25.2 User Roles

Cannot be imported with REDCapR. See Section 27.1 for more information.

Roles can be imported using import_user_roles() and assigned to a project user using import_user_role_assignment().

Importing User Roles

user_roles = project.export_user_roles(format_type='df')
user_roles
unique_role_name role_label design alerts user_rights data_access_groups reports stats_and_charts manage_survey_participants calendar ... mobile_app mobile_app_download_data record_create record_rename record_delete lock_records_customization lock_records lock_records_all_forms forms forms_export
0 U-1564393FT9 Limited Role 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 demographics:0,symptoms:0,test_information:0,c... demographics:0,symptoms:0,test_information:0,c...
1 U-5354FA3HYL Admin 1 1 1 1 1 1 1 1 ... 1 0 1 1 1 1 0 0 demographics:3,symptoms:1,test_information:1,c... demographics:3,symptoms:1,test_information:1,c...

2 rows × 29 columns

Note: the unique_role_name is automatically generated by REDCap.

project.import_user_roles(user_roles, import_format='df')
3

Importing User Role Assignments

user_role_assign = project.export_user_role_assignment(format_type='df')
user_role_assign
username unique_role_name data_access_group
0 alexey.gilman@doh.wa.gov NaN NaN
1 caitlin.drover@doh.wa.gov NaN NaN
2 emily.pearman@doh.wa.gov NaN NaN
user_role_assign['unique_role_name'].astype(str).replace('nan', np.NaN)
user_role_assign.loc[0,'unique_role_name'] = 'U-5354FA3HYL'
user_role_assign
username unique_role_name data_access_group
0 alexey.gilman@doh.wa.gov U-5354FA3HYL NaN
1 caitlin.drover@doh.wa.gov NaN NaN
2 emily.pearman@doh.wa.gov NaN NaN
project.import_user_role_assignment(user_role_assign, import_format='df')
3