Skip to content

Commit

Permalink
casting billingID as character, bigint_as_char in fromJSON, standardi…
Browse files Browse the repository at this point in the history
…zing parameter order, unlisting list columns, adding some parameter checks, returning getDatabaseBillingAcccount as tibble, adding indentationLevel to section fields, starting to replace snapshot tests and make them behave well.
  • Loading branch information
nickdickinson committed Mar 13, 2024
1 parent ec3e8c3 commit 73314e5
Show file tree
Hide file tree
Showing 21 changed files with 170 additions and 75 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Imports:
tidyselect (>= 1.2.0),
magrittr
Encoding: UTF-8
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE)
Suggests:
ggplot2,
Expand Down
10 changes: 4 additions & 6 deletions R/auth.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ activityInfoRootUrl <- local({
function(newUrl) {
if (!missing(newUrl)) {
url <<- newUrl
activityInfoAuthentication()
activityInfoAuthentication(NULL)
invisible()
} else {
url
Expand All @@ -55,17 +55,15 @@ activityInfoAuthentication <- local({
function(newValue) {
if (!missing(newValue)) {
credentials <<- newValue
if (!is.null(credentials)&&credentialType(credentials) == "basic") deprecationOfBasicAuthWarning()
} else {
if (file.exists(credentialsFile)) {

if (is.null(credentials)&&file.exists(credentialsFile)) {
authObj = readRDS(file = credentialsFile) %>% filter(server == activityInfoRootUrl())

if (nrow(authObj) == 1) {
credentials <<- authObj %>% pull(credentials)
if (credentialType(credentials) == "basic") deprecationOfBasicAuthWarning()
} else if (nrow(authObj)==0) {
credentials <<- NULL
} else {
} else if (nrow(authObj) > 1) {
warning(sprintf("...file exists, but has more than one key. Try saving the key again.\n", path.expand(path = credentialsFile)))
}
}
Expand Down
55 changes: 44 additions & 11 deletions R/billingInfo.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#' @title getBillingAccount
#' @description Get billing account information
#' @param asDataFrame Output as data.frame, Default: TRUE
#' @param billingId Billing ID
#' @param asDataFrame Output as data.frame, Default: TRUE
#' @return Billing account information in list or data.frame output
#' @rdname getBillingAccount
#' @export
#' @importFrom tibble as_tibble

getBillingAccount <- function(asDataFrame = TRUE, billingId) {
getBillingAccount <- function(billingId, asDataFrame = TRUE) {
if(missing(billingId)) stop("A billingId must be provided")
stopifnot("A single billingId must be provided" = (length(billingId)==1))

billingInfo <- getResource(paste0("/billingAccounts/", billingId), task = "Getting billing account info")
billingInfo$id <- as.character(billingInfo$id)
if (asDataFrame == TRUE) {
billingInfo <- tibble::as_tibble(billingInfo)
return(billingInfo)
Expand All @@ -20,22 +24,33 @@ getBillingAccount <- function(asDataFrame = TRUE, billingId) {

#' @title getBillingAccountDatabases
#' @description Data for all databases under billing account
#' @param asDataFrame Output as data.frame, Default: TRUE
#' @param billingId Billing ID
#' @param asDataFrame Output as data.frame, Default: TRUE
#' @return Information on databases under billing account in list or data.frame output
#' @rdname getBillingAccountDatabases
#' @export
#' @importFrom tibble tibble

getBillingAccountDatabases <- function(asDataFrame = TRUE, billingId) {
getBillingAccountDatabases <- function(billingId, asDataFrame = TRUE) {
if(missing(billingId)) stop("A billingId must be provided")
stopifnot("A single billingId must be provided" = (length(billingId)==1))

billingDatabases <- getResource(paste0("/billingAccounts/", billingId, "/databases"),
task = "Getting billing account databases")

billingDatabases <- lapply(billingDatabases, function(x) {
x$billingAccountId <- as.character(x$billingAccountId)
x
})

if (asDataFrame == TRUE) {
billingDatabases <- tibble::tibble(
databaseId = unlist(lapply(billingDatabases, function(x) {x$databaseId})),
label = unlist(lapply(billingDatabases, function(x) {x$label})),
description = unlist(lapply(billingDatabases, function(x) { if(nzchar(x$description)) x$description else NA_character_ })),
owner = lapply(billingDatabases, function(x) {x$owner}),
ownerId = unlist(lapply(billingDatabases, function(x) {x$owner[["id"]]})),
ownerName = unlist(lapply(billingDatabases, function(x) {x$owner[["name"]]})),
ownerEmail = unlist(lapply(billingDatabases, function(x) {x$owner[["email"]]})),
formCount = unlist(lapply(billingDatabases, function(x) {x$formCount})),
userCount = unlist(lapply(billingDatabases, function(x) {x$userCount})),
basicUserCount = unlist(lapply(billingDatabases, function(x) {x$basicUserCount})),
Expand All @@ -60,21 +75,27 @@ getBillingAccountDatabases <- function(asDataFrame = TRUE, billingId) {
#' @export

getBillingAccountDomains <- function(billingId) {
if(missing(billingId)) stop("A billingId must be provided")
stopifnot("A single billingId must be provided" = (length(billingId)==1))

billingDomains <- getResource(paste0("/billingAccounts/", billingId, "/domains"), task = "Getting billing account domains")
return(billingDomains)
}


#' @title getBillingAccountUsers
#' @description Billing account users
#' @param asDataFrame Output as data.frame, Default: TRUE
#' @param billingId Billing ID
#' @param asDataFrame Output as data.frame, Default: TRUE
#' @return Billing account user(s) in list or data.frame output
#' @rdname getBillingAccountUsers
#' @export
#' @importFrom tibble tibble

getBillingAccountUsers <- function(asDataFrame = TRUE, billingId) {
getBillingAccountUsers <- function(billingId, asDataFrame = TRUE) {
if(missing(billingId)) stop("A billingId must be provided")
stopifnot("A single billingId must be provided" = (length(billingId)==1))

billingUsers <- getResource(paste0("/billingAccounts/", billingId, "/users"), task = "Getting billing account users")
if (asDataFrame == TRUE) {
billingUsers <- tibble::tibble(
Expand All @@ -95,29 +116,41 @@ getBillingAccountUsers <- function(asDataFrame = TRUE, billingId) {

#' @title getDatabaseBillingAccount
#' @description Get database owner for a given database. This gives the owning organization rather than the user who created the database.
#' @param asDataFrame Data.frame output, Default: TRUE
#' @param databaseId Database ID
#' @param asDataFrame Data.frame output, Default: TRUE
#' @return Database owner in list output
#' @rdname getDatabaseBillingAccount
#' @export

getDatabaseBillingAccount <- function(asDataFrame = TRUE, databaseId) {
getDatabaseBillingAccount <- function(databaseId, asDataFrame = TRUE) {
if(missing(databaseId)) stop("A databaseId must be provided")
stopifnot("A single databaseId must be provided" = (length(databaseId)==1))

databaseOwner <- getResource(paste0("/databases/", databaseId, "/billingAccount"), task = "Getting database owner")
databaseOwner$id <- as.character(databaseOwner$id)

if (asDataFrame) {
databaseOwner <- as_tibble(databaseOwner)
}
return(databaseOwner)
}


#' @title getBillingAccountDatabaseUsers
#' @description Get data for users from a specific database. Can be more useful than `getDatabaseUsers()` as you also retrieve the database owner's info as well.
#' @param asDataFrame Data.frame output, Default: TRUE
#' @param billingId Billing ID
#' @param asDataFrame Data.frame output, Default: TRUE
#' @param databaseId Database ID
#' @return User information from the specified database in list or data.frame output
#' @rdname getBillingAccountDatabaseUsers
#' @export
#' @importFrom tibble tibble

getBillingAccountDatabaseUsers <- function(asDataFrame = TRUE, billingId, databaseId) {
getBillingAccountDatabaseUsers <- function(billingId, databaseId, asDataFrame = TRUE) {
if(missing(billingId)||missing(databaseId)) stop("A billingId and a databaseId must be provided")
stopifnot("A single billingId must be provided" = (length(billingId)==1))
stopifnot("A single databaseId must be provided" = (length(databaseId)==1))

databaseUsers <- getResource(paste0("billingAccounts/", billingId, "/users?databaseId=", databaseId), task = "Getting database data")
if (asDataFrame == TRUE) {
databaseUsers <- tibble::tibble(
Expand Down
4 changes: 2 additions & 2 deletions R/databases.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ getDatabases <- function(asDataFrame = TRUE) {
databaseId = unlist(lapply(databases, function(x) {x$databaseId})),
label = unlist(lapply(databases, function(x) {x$label})),
description = unlist(lapply(databases, function(x) { if(nzchar(x$description)) x$description else NA_character_ })),
ownerId = unlist(lapply(databases, function(x) {x$ownerId})),
billingAccountId = unlist(lapply(databases, function(x) {x$billingAccountId})),
ownerId = as.character(unlist(lapply(databases, function(x) {x$ownerId}))),
billingAccountId = as.character(unlist(lapply(databases, function(x) {x$billingAccountId}))),
suspended = unlist(lapply(databases, function(x) {x$suspended}))
)
return(dbDF)
Expand Down
9 changes: 7 additions & 2 deletions R/formField.R
Original file line number Diff line number Diff line change
Expand Up @@ -710,12 +710,17 @@ userFieldSchema <- function(label, description = NULL, databaseId, code = NULL,
#' @inheritParams formFieldSchema
#' @family field schemas
#' @export
sectionFieldSchema <- function(label, description = NULL) {
sectionFieldSchema <- function(label, description = NULL, indentationLevel = 1L) {
schema <- do.call(
formFieldSchema,
args = c(
list(type = "section"),
as.list(environment())
formFieldArgs(as.list(environment())),
list(
typeParameters = list(
"indentationLevel" = indentationLevel
)
)
)
)

Expand Down
2 changes: 1 addition & 1 deletion R/rest.R
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ fromActivityInfoJson <- function(x) {
return(invisible())
}
}
fromJSON(txt = x, simplifyDataFrame = FALSE, simplifyMatrix = FALSE)
fromJSON(txt = x, simplifyDataFrame = FALSE, simplifyMatrix = FALSE, bigint_as_char = TRUE)
}

#'
Expand Down
2 changes: 1 addition & 1 deletion man/addRecord.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/deleteRecord.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/getAttachment.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/getBillingAccount.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/getBillingAccountDatabaseUsers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/getBillingAccountDatabases.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/getBillingAccountUsers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/getDatabaseBillingAccount.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/recoverRecord.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/updateRecord.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 16 additions & 22 deletions tests/testthat/_snaps/databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,25 @@
1 c10000004 Person form c10000002 FORM PRIVATE
2 c10000005 Children c10000004 SUB_FORM PRIVATE

# addDatabaseUser() and deleteDatabaseUser() and getDatabaseUsers() and getDatabaseUser() and getDatabaseUser2() work
# addDatabaseUser() and deleteDatabaseUser() and getDatabaseUsers() and getDatabaseUser() and getDatabaseUser2() work and expected fields are present

list(list(added = TRUE, user = list(activationStatus = "PENDING",
list(list(activationStatus = "PENDING", databaseId = "<id value>",
deliveryStatus = "UNKNOWN", email = "<id value>", inviteTime = "<date or time value>",
lastLoginTime = "<date or time value>", name = "Test database user",
userId = "<id value>", version = 1L), list(activationStatus = "PENDING",
databaseId = "<id value>", deliveryStatus = "UNKNOWN", email = "<id value>",
grants = list(), inviteTime = "<date or time value>", lastLoginTime = "<date or time value>",
name = "Test database user", role = list(id = "<id value>",
parameters = list(), resources = "Empty resources until we can ensure a sort order in the API."),
userId = "<id value>", version = 1)), list(added = TRUE,
user = list(activationStatus = "PENDING", databaseId = "<id value>",
deliveryStatus = "UNKNOWN", email = "<id value>", grants = list(),
inviteTime = "<date or time value>", lastLoginTime = "<date or time value>",
name = "Test database user", role = list(id = "<id value>",
parameters = list(), resources = "Empty resources until we can ensure a sort order in the API."),
userId = "<id value>", version = 1)))
inviteTime = "<date or time value>", lastLoginTime = "<date or time value>",
name = "Test database user", userId = "<id value>", version = 1L))

---

list(list(databaseId = "<id value>", deliveryStatus = "UNKNOWN",
email = "<id value>", inviteAccepted = FALSE, inviteDate = "<date or time value>",
name = "Test database user", role = list(id = "<id value>",
parameters = list(), resources = "Empty resources until we can ensure a sort order in the API."),
userId = "<id value>", userLicenseType = "BASIC", version = 1L),
list(databaseId = "<id value>", deliveryStatus = "UNKNOWN",
email = "<id value>", inviteAccepted = FALSE, inviteDate = "<date or time value>",
name = "Test database user", role = list(id = "<id value>",
parameters = list(), resources = "Empty resources until we can ensure a sort order in the API."),
userId = "<id value>", userLicenseType = "BASIC", version = 1L))
list(list(activationStatus = "PENDING", databaseId = "<id value>",
deliveryStatus = "UNKNOWN", email = "<id value>", inviteAccepted = FALSE,
inviteDate = "<date or time value>", lastLoginDate = "<date or time value>",
name = "Test database user", userId = "<id value>", userLicenseType = "BASIC",
version = 1L), list(activationStatus = "PENDING", databaseId = "<id value>",
deliveryStatus = "UNKNOWN", email = "<id value>", inviteAccepted = FALSE,
inviteDate = "<date or time value>", lastLoginDate = "<date or time value>",
name = "Test database user", userId = "<id value>", userLicenseType = "BASIC",
version = 1L))

Loading

0 comments on commit 73314e5

Please sign in to comment.