From c7e4155f3f5ed767c0cdc3d210db26307f975c51 Mon Sep 17 00:00:00 2001 From: Colin Gillespie Date: Mon, 10 Jun 2024 16:47:59 +0100 Subject: [PATCH] Use the latest version of connectapi (#35) * Use the latest version of connectapi * fix: #15 --- DESCRIPTION | 8 ++++---- NEWS.md | 5 +++++ R/check.R | 2 +- R/sanitise.R | 2 +- R/summarise_users.R | 25 ++++++++++++++++--------- man/check.Rd | 2 +- man/sanitise.Rd | 2 +- 7 files changed, 29 insertions(+), 17 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 487ca9c..9e5a3bf 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,16 +1,16 @@ Type: Package Package: audit.connect Title: Posit Connect Health Check -Version: 0.7.4 +Version: 0.7.5 Authors@R: person("Jumping", "Rivers", , "info@jumpingrivers.com", role = c("aut", "cre")) Description: Posit Connect Health Check. Deploys various content types to assess whether Connect is functioning correctly. License: file LICENSE Imports: - audit.base (>= 0.6.10), + audit.base (>= 0.6.15), cli, - connectapi (>= 0.1.3.1), + connectapi (>= 0.2.0), dplyr, fs, httr, @@ -21,7 +21,7 @@ Imports: purrr, quarto (>= 1.3), rlang, - rsconnect (>= 1.1.0), + rsconnect (>= 1.3.1), stringr, tibble Suggests: diff --git a/NEWS.md b/NEWS.md index e108e81..5960d04 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# audit.connect 0.7.5 _2024-06-10_ + - fix: Use latest version of {connactapi} + - chore: Fix Rd warnings due to R4.4 + - fix: #15 + # audit.connect 0.7.4 _2024-04-04_ - feat: Force `server` to have `http(?s)` - feat: Improved error message when testing status response diff --git a/R/check.R b/R/check.R index 64e414b..b91b0f7 100644 --- a/R/check.R +++ b/R/check.R @@ -3,7 +3,7 @@ #' This functions runs all Posit tests. #' To skip tests, set check to `no` in the config yaml file. #' See `create_config()` -#' @param server Connect server. If NULL, use the ENV variable CONNECT_SERVER +#' @param server Connect server (URL). If NULL, use the ENV variable CONNECT_SERVER. #' @param token Connect api token. If NULL, use the ENV variable CONNECT_API_KEY #' @param dir directory location of the the config file #' @param debug_level Integer, 0 to 2. diff --git a/R/sanitise.R b/R/sanitise.R index 7c9e505..833ef0a 100644 --- a/R/sanitise.R +++ b/R/sanitise.R @@ -1,6 +1,6 @@ #' Sanitise {audit.connect} object #' -#' This function removes user-identifying data from an {audit.connect} object +#' This function removes user-identifying data from an audit.connect object #' @param audit_connect_check An object from audit.connect::check() #' @export sanitise = function(audit_connect_check) { diff --git a/R/summarise_users.R b/R/summarise_users.R index e89c50b..f1c64ad 100644 --- a/R/summarise_users.R +++ b/R/summarise_users.R @@ -44,13 +44,20 @@ print_audit_users = function(user_list) { print_audit_user_apps = function(client, debug_level) { suppress = get_suppress(debug_level) - apps = suppress(connectapi::cache_apps(client)) - # Remove any api keys; don't need or want them - apps = purrr::map(apps, ~{.x$EnvironmentJson = NULL; .x}) # nolint - app_creators = purrr::map_df(apps, - ~dplyr::tibble(owner = .x[["owner_username"]], - locked = .x$owner_locked)) - locked_users = dplyr::filter(app_creators, .data$locked) # nolint: object_usage_linter - cli::cli_alert_info("{nrow(locked_users)} applications owned by locked users") - apps + content = suppress(connectapi::get_content(client)) + locked_users = suppress(connectapi::get_users(client)) |> + dplyr::filter(.data$locked) + locked_content = dplyr::inner_join(content, locked_users, + by = dplyr::join_by(owner_guid == guid)) |> + dplyr::group_by(username) |> + dplyr::summarise(n = dplyr::n()) |> + dplyr::arrange(dplyr::desc(n)) + + cli::cli_alert_info("{sum(locked_content$n)} applications owned by locked users") + + for (i in seq_len(nrow(locked_content))) { + row = locked_content[i, ] + cli::cli_alert_info("{row$n} locked application{?s} owned by {cli::style_italic(row$username)}") + } + content } diff --git a/man/check.Rd b/man/check.Rd index a56b48b..456f6c4 100644 --- a/man/check.Rd +++ b/man/check.Rd @@ -7,7 +7,7 @@ check(server = NULL, token = NULL, dir = ".", debug_level = 0:2) } \arguments{ -\item{server}{Connect server. If NULL, use the ENV variable CONNECT_SERVER} +\item{server}{Connect server (URL). If NULL, use the ENV variable CONNECT_SERVER.} \item{token}{Connect api token. If NULL, use the ENV variable CONNECT_API_KEY} diff --git a/man/sanitise.Rd b/man/sanitise.Rd index e175a31..23425a4 100644 --- a/man/sanitise.Rd +++ b/man/sanitise.Rd @@ -10,5 +10,5 @@ sanitise(audit_connect_check) \item{audit_connect_check}{An object from audit.connect::check()} } \description{ -This function removes user-identifying data from an {audit.connect} object +This function removes user-identifying data from an audit.connect object }