Skip to content

Commit 1e36533

Browse files
authored
Merge pull request #475 from vubiostat/issue-474-forms
clean up user import form validation
2 parents c0c9b77 + b6ed7f2 commit 1e36533

4 files changed

Lines changed: 24 additions & 72 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: redcapAPI
22
Type: Package
33
Title: Interface to 'REDCap'
4-
Version: 2.11.4
4+
Version: 2.11.5
55
Authors@R: c(
66
person("Benjamin", "Nutter", email = "benjamin.nutter@gmail.com",
77
role = c("ctb", "aut")),

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ A future release of version 3.0.0 will introduce several breaking changes!
77
* The `redcapFactor` class is being discontinued with all its supporting methods (including `redcapFactorFlip`). Please use `recastRecords` instead.
88
* The `recodeCheck` function is being discontinued. Please use `recastRecords` instead.
99

10+
## 2.11.5
11+
12+
* Deleted functions `prepUserImportData_validateAllFormsPresent` and `prepUserImportData_extractFormName`.
13+
1014
## 2.11.4
1115

1216
* Updated to allow for `project_pi_email` as an allowed field of project info.

R/prepUserImportData.R

Lines changed: 16 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
}

tests/testthat/test-101-userMethods-Functionality.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,14 @@ test_that(
8282
data = data.frame(username = EXPENDABLE_USER,
8383
data_export = 1,
8484
forms = c("record_id:0"),
85-
forms_export = "record_id:0"),
85+
# leaving an instrument off implicitly sets permission to 0
86+
forms_export = ""),
8687
consolidate = FALSE)
8788

8889
Users <- exportUsers(rcon)
8990
Users <- Users[Users$username %in% EXPENDABLE_USER, ]
9091
expect_true(grepl("record_id:0",Users$forms))
92+
expect_true(grepl("record_id:0",Users$forms_export))
9193
}
9294
)
9395

0 commit comments

Comments
 (0)