@@ -80,29 +80,27 @@ prepUserImportData <- function(data,
8080
8181 checkmate :: reportAssertions(coll )
8282
83- primary_fields <- names(data )
84- primary_fields <- primary_fields [! grepl(" (_export_access|_form_access)$" ,
85- primary_fields )]
86-
83+ all_fields <- names(data )
84+ form_access_field <- grep(' _form_access$' , all_fields , value = TRUE )
85+ export_access_field <- grep(' _export_access$' , all_fields , value = TRUE )
86+ primary_fields <- setdiff(all_fields , c(form_access_field , export_access_field ))
87+
8788 checkmate :: assert_subset(x = primary_fields ,
8889 choices = c(if (user_role ) names(redcapUserRoleStructure(rcon $ version())) else names(redcapUserStructure(rcon $ version())),
8990 " data_export" ),
9091 add = coll )
9192
9293 checkmate :: reportAssertions(coll )
93-
94- form_access_field <- names(data )[grepl(" _form_access$" , names(data ))]
95- export_access_field <- names(data )[grepl(" _export_access$" , names(data ))]
96- instrument <- rcon $ instruments()$ instrument_name
97-
98- prepUserImportData_validateAllFormsPresent(data = data ,
99- form_access_field = form_access_field ,
100- export_access_field = export_access_field ,
101- instrument = instrument ,
102- consolidate = consolidate ,
103- coll = coll )
104-
105- checkmate :: reportAssertions(coll )
94+
95+ # Prior to redcapAPI version 2.11.5, functionality surrounding form validation
96+ # did not work properly. See GH issue #474.
97+ # Specifically user permissions for forms and forms export were checked against
98+ # the list of all instruments. The prior design was to generate an error
99+ # if one of the instruments was not present.
100+ # The current design is to let REDCap API handle the missing instruments,
101+ # which will set the permissions to "No Access".
102+ # The functions "prepUserImportData_validateAllFormsPresent" and
103+ # "prepUserImportData_extractFormName" were removed with this change.
106104
107105 # ##################################################################
108106 # Functional Code ####
@@ -119,7 +117,7 @@ prepUserImportData <- function(data,
119117 fields_to_remove <- c(" email" , " lastname" , " firstname" ,
120118 " data_access_group_id" )
121119 data <- data [! names(data ) %in% fields_to_remove ]
122-
120+
123121 # Convert values to numeric
124122
125123 for (nm in names(data )){
@@ -200,55 +198,3 @@ prepUserImportData_consolidateAccess <- function(d, suffix){
200198
201199 apply(d , MARGIN = 1 , FUN = paste0 , collapse = " ," )
202200}
203-
204- prepUserImportData_extractFormName <- function (x , instrument ){
205- forms <- strsplit(x , " ," )
206- forms <- lapply(forms ,
207- function (f ) sub(" [:].+$" , " " , f ))
208-
209- instrument_present <- logical (length(instrument ))
210-
211- for (i in seq_along(instrument_present )){
212- instrument_present [i ] <-
213- all(vapply(forms , function (f ) instrument [i ] %in% forms [[i ]], logical (1 )))
214- }
215-
216- instrument [instrument_present ]
217- }
218-
219- prepUserImportData_validateAllFormsPresent <- function (data ,
220- form_access_field ,
221- export_access_field ,
222- instrument ,
223- consolidate ,
224- coll ){
225- # If consolidating, we need to make sure that all of the forms are present
226- # in both form access and data export access.
227- if (consolidate ){
228- form_access_forms <- sub(" _form_access$" , " " , form_access_field )
229- export_access_forms <- sub(" _export_access$" , " " , export_access_field )
230- }
231-
232- # if not consolidating forms, we need to make sure all of the forms are
233- # represented in the standard format
234-
235- if (! consolidate ){
236- form_access_forms <- prepUserImportData_extractFormName(data $ forms , instrument )
237- export_access_forms <- prepUserImportData_extractFormName(data $ forms_export , instrument )
238- }
239-
240- all_form_access <- all(form_access_forms %in% instrument )
241- all_export_access <- all(export_access_forms %in% instrument )
242-
243- if (! all_form_access ){
244- msg <- sprintf(" At least one user is missing an entry for the form(s): %s" ,
245- paste0(setdiff(instrument , all_form_access ), collapse = " , " ))
246- coll $ push(msg )
247- }
248-
249- if (! all_export_access ){
250- msg <- sprintf(" At least one user is missing an export entry for the form(s): %s" ,
251- paste0(setdiff(instrument , all_export_access ), collapse = " , " ))
252- coll $ push(msg )
253- }
254- }
0 commit comments