From 5dc6cbf97583944858459e26b86528fa7bf937b7 Mon Sep 17 00:00:00 2001 From: Neal Richardson Date: Wed, 15 Oct 2025 08:19:21 -0400 Subject: [PATCH 1/4] refactor: remove unnecessary get_connect() and get_content() R6 methods --- R/connect.R | 5 -- R/content.R | 127 +++++++++++++++----------------- R/deploy.R | 26 +++---- R/git.R | 4 +- R/promote.R | 2 +- R/schedule.R | 14 ++-- R/tags.R | 4 +- R/variant.R | 30 ++++---- tests/integrated/helper.R | 4 +- tests/integrated/test-content.R | 18 ++--- tests/integrated/test-deploy.R | 20 ++--- tests/integrated/test-get.R | 4 +- tests/integrated/test-run-as.R | 8 +- 13 files changed, 125 insertions(+), 141 deletions(-) diff --git a/R/connect.R b/R/connect.R index 3daa3b7f0..0631c8950 100644 --- a/R/connect.R +++ b/R/connect.R @@ -36,11 +36,6 @@ Connect <- R6::R6Class( #' @field using_auth Indicates that the API key is added to each HTTP call. using_auth = TRUE, - #' @description Return this connect. - get_connect = function() { - self - }, - #' @description Initialize a new connect. #' @param server The base URL of your Posit Connect server. #' @param api_key Your Posit Connect API key. diff --git a/R/content.R b/R/content.R index 30bdfde4c..355e21d03 100644 --- a/R/content.R +++ b/R/content.R @@ -22,24 +22,17 @@ Content <- R6::R6Class( # at least guid, url, title to be functional self$content <- content }, - #' @description Returns the `Connect` instance. - get_connect = function() { - self$connect - }, - #' @description Returns the underlying content data. - get_content = function() { - self$content - }, + #' @description Obtain the content data from the Connect server. get_content_remote = function() { - new_content_details <- self$get_connect()$content(self$get_content()$guid) + new_content_details <- self$connect$content(self$content$guid) self$content <- new_content_details - self$get_content() + self$content }, #' @description Return the set of content bundles. get_bundles = function() { - url <- v1_url("content", self$get_content()$guid, "bundles") - self$get_connect()$GET(url) + url <- v1_url("content", self$content$guid, "bundles") + self$connect$GET(url) }, #' @description Download the source archive for a content bundle. #' @param bundle_id The bundle identifer. @@ -52,12 +45,12 @@ Content <- R6::R6Class( ) { url <- v1_url( "content", - self$get_content()$guid, + self$content$guid, "bundles", bundle_id, "download" ) - self$get_connect()$GET( + self$connect$GET( url, httr::write_disk(filename, overwrite = overwrite), parser = "raw" @@ -67,20 +60,20 @@ Content <- R6::R6Class( #' @description Delete a content bundle. #' @param bundle_id The bundle identifer. bundle_delete = function(bundle_id) { - url <- v1_url("content", self$get_content()$guid, "bundles", bundle_id) - self$get_connect()$DELETE(url) + url <- v1_url("content", self$content$guid, "bundles", bundle_id) + self$connect$DELETE(url) }, #' @description Get this (remote) content item. internal_content = function() { - url <- unversioned_url("applications", self$get_content()$guid) - self$get_connect()$GET(url) + url <- unversioned_url("applications", self$content$guid) + self$connect$GET(url) }, #' @description Update this content item. #' @param ... Content fields. update = function(...) { - con <- self$get_connect() + con <- self$connect error_if_less_than(con$version, "1.8.6") - url <- v1_url("content", self$get_content()$guid) + url <- v1_url("content", self$content$guid) body <- rlang::list2(...) if (length(body)) { # Only need to make a request if there are changes @@ -90,13 +83,13 @@ Content <- R6::R6Class( }, #' @description Delete this content item. danger_delete = function() { - con <- self$get_connect() - url <- v1_url("content", self$get_content()$guid) + con <- self$connect + url <- v1_url("content", self$content$guid) con$DELETE(url) }, #' @description Return the URL for this content. get_url = function() { - self$get_content()$content_url + self$content$content_url }, #' @description Return the URL for this content in the Posit Connect dashboard. #' @param pane The pane in the dashboard to link to. @@ -170,13 +163,13 @@ Content <- R6::R6Class( warn_experimental("job") url <- unversioned_url( "applications", - self$get_content()$guid, + self$content$guid, "job", key ) - res <- self$get_connect()$GET(url) + res <- self$connect$GET(url) - content_guid <- self$get_content()$guid + content_guid <- self$content$guid purrr::map( list(res), ~ purrr::list_modify(.x, app_guid = content_guid) @@ -198,16 +191,16 @@ Content <- R6::R6Class( warn_experimental("variants") url <- unversioned_url( "applications", - self$get_content()$guid, + self$content$guid, "variants" ) - self$get_connect()$GET(url) + self$connect$GET(url) }, #' @description Set a tag for this content. #' @param tag_id The tag identifier. tag_set = function(tag_id) { - self$get_connect()$set_content_tag( - self$get_content()$guid, + self$connect$set_content_tag( + self$content$guid, tag_id = tag_id ) }, @@ -215,23 +208,23 @@ Content <- R6::R6Class( #' @param tag_id The tag identifier. tag_delete = function(tag_id) { # note that deleting the parent tag deletes all children - self$get_connect()$remove_content_tag( - self$get_content()$guid, + self$connect$remove_content_tag( + self$content$guid, tag_id = tag_id ) }, #' @description The tags for this content. tags = function() { - url <- v1_url("content", self$get_content()$guid, "tags") - self$get_connect()$GET(url) + url <- v1_url("content", self$content$guid, "tags") + self$connect$GET(url) }, #' @description Add a principal to the ACL for this content. #' @param principal_guid GUID for the target user or group. #' @param principal_type Acting on user or group. #' @param role The kind of content access. permissions_add = function(principal_guid, principal_type, role) { - url <- v1_url("content", self$get_content()$guid, "permissions") - self$get_connect()$POST( + url <- v1_url("content", self$content$guid, "permissions") + self$connect$POST( url, body = list( principal_guid = principal_guid, @@ -246,8 +239,8 @@ Content <- R6::R6Class( #' @param principal_type Acting on user or group. #' @param role The kind of content access. permissions_update = function(id, principal_guid, principal_type, role) { - url <- v1_url("content", self$get_content()$guid, "permissions", id) - self$get_connect()$PUT( + url <- v1_url("content", self$content$guid, "permissions", id) + self$connect$PUT( url, body = list( principal_guid = principal_guid, @@ -259,20 +252,20 @@ Content <- R6::R6Class( #' @description Remove an entry from the ACL for this content. #' @param id The target identifier. permissions_delete = function(id) { - url <- v1_url("content", self$get_content()$guid, "permissions", id) - self$get_connect()$DELETE(url) + url <- v1_url("content", self$content$guid, "permissions", id) + self$connect$DELETE(url) }, #' @description Obtain some or all of the ACL for this content. #' @param id The target identifier. #' @param add_owner Include the content owner in the result set. permissions = function(id = NULL, add_owner = FALSE) { - guid <- self$get_content()$guid + guid <- self$content$guid if (is.null(id)) { - url <- v1_url("content", self$get_content()$guid, "permissions") + url <- v1_url("content", self$content$guid, "permissions") } else { - url <- v1_url("content", self$get_content()$guid, "permissions", id) + url <- v1_url("content", self$content$guid, "permissions", id) } - res <- self$get_connect()$GET(url) + res <- self$connect$GET(url) # NOTE: the default for the low-level functions is to map to the API # as close as possible. This differs from the "cleaner UX" functions if (add_owner) { @@ -280,7 +273,7 @@ Content <- R6::R6Class( id = NA_character_, content_guid = guid, # TODO: what if groups can own content? - principal_guid = self$get_content()$owner_guid, + principal_guid = self$content$owner_guid, principal_type = "user", role = "owner" ) @@ -290,14 +283,14 @@ Content <- R6::R6Class( }, #' @description Return the environment variables set for this content. environment = function() { - url <- v1_url("content", self$get_content()$guid, "environment") - self$get_connect()$GET(url) + url <- v1_url("content", self$content$guid, "environment") + self$connect$GET(url) }, #' @description Adjust the environment variables set for this content. #' @param ... Environment variable names and values. Use `NA` as the value #' to unset variables. environment_set = function(...) { - url <- v1_url("content", self$get_content()$guid, "environment") + url <- v1_url("content", self$content$guid, "environment") # post with # key = NA to remove vals <- rlang::list2(...) @@ -307,12 +300,12 @@ Content <- R6::R6Class( }) names(body) <- NULL - self$get_connect()$PATCH(path = url, body = body) + self$connect$PATCH(path = url, body = body) }, #' @description Overwrite the environment variables set for this content. #' @param ... Environment variable names and values. environment_all = function(...) { - url <- v1_url("content", self$get_content()$guid, "environment") + url <- v1_url("content", self$content$guid, "environment") vals <- rlang::list2(...) if (length(vals) == 0) { @@ -326,14 +319,14 @@ Content <- R6::R6Class( names(body) <- NULL } - self$get_connect()$PUT(path = url, body = body) + self$connect$PUT(path = url, body = body) }, #' @description Deploy this content #' @param bundle_id Target bundle identifier. deploy = function(bundle_id = NULL) { body <- list(bundle_id = bundle_id) - self$get_connect()$POST( - v1_url("content", self$get_content()$guid, "deploy"), + self$connect$POST( + v1_url("content", self$content$guid, "deploy"), body = body ) }, @@ -341,8 +334,8 @@ Content <- R6::R6Class( #' @param enabled Polling enabled. repo_enable = function(enabled = TRUE) { warn_experimental("repo_enable") - self$get_connect()$PUT( - unversioned_url("applications", self$get_content()$guid, "repo"), + self$connect$PUT( + unversioned_url("applications", self$content$guid, "repo"), body = list( enabled = enabled ) @@ -354,8 +347,8 @@ Content <- R6::R6Class( #' @param subdirectory Git repository directory repo_set = function(repository, branch, subdirectory) { warn_experimental("repo_set") - self$get_connect()$POST( - unversioned_url("applications", self$get_content()$guid, "repo"), + self$connect$POST( + unversioned_url("applications", self$content$guid, "repo"), body = list( repository = repository, branch = branch, @@ -371,18 +364,18 @@ Content <- R6::R6Class( #' @param ... Unused. print = function(...) { cat("Posit Connect Content: \n") - cat(" Content GUID: ", self$get_content()$guid, "\n", sep = "") + cat(" Content GUID: ", self$content$guid, "\n", sep = "") cat( " Content URL: ", - self$get_content()$dashboard_url, + self$content$dashboard_url, "\n", sep = "" ) - cat(" Content Title: ", self$get_content()$title, "\n", sep = "") + cat(" Content Title: ", self$content$title, "\n", sep = "") cat("\n") cat( 'content_item(client, guid = "', - self$get_content()$guid, + self$content$guid, '")', "\n", sep = "" @@ -521,7 +514,7 @@ Environment <- R6::R6Class( get_environment <- function(content) { validate_R6_class(content, "Content") content_data <- content$get_content_remote() - connect_client <- content$get_connect() + connect_client <- content$connect return(Environment$new(connect_client, content_data)) } @@ -594,7 +587,7 @@ content_item <- function(connect, guid) { # TODO : think about how to handle if GUID does not exist validate_R6_class(connect, "Connect") - res <- connect$get_connect()$content(guid) + res <- connect$content(guid) Content$new(connect = connect, content = res) } @@ -617,7 +610,7 @@ content_title <- function(connect, guid, default = "Unknown Content") { content_title <- tryCatch( { - res <- suppressMessages(connect$get_connect()$content(guid)) + res <- suppressMessages(connect$content(guid)) # TODO: What about length 0? if (is.null(res$title)) { return(default) @@ -991,7 +984,7 @@ content_delete <- function(content, force = FALSE) { message(glue::glue("Deleting content '{cn$title}' ({cn$guid})")) res <- content$danger_delete() - content$get_connect()$raise_error(res) + content$connect$raise_error(res) return(content) } @@ -1181,7 +1174,7 @@ delete_bundle <- function(content, bundle_id) { "Deleting bundle {bundle_id} for content '{cn$title}' ({cn$guid})" )) res <- content$bundle_delete(bundle_id) - content$get_connect()$raise_error(res) + content$connect$raise_error(res) return(content) } @@ -1351,7 +1344,7 @@ get_user_permission <- function(content, guid, add_owner = TRUE) { #' @rdname permissions #' @export get_my_permission <- function(content, add_owner = TRUE) { - my_guid <- content$get_connect()$GET("me")$guid + my_guid <- content$connect$GET("me")$guid get_user_permission(content, my_guid, add_owner = add_owner) } diff --git a/R/deploy.R b/R/deploy.R index 99ab46f21..7239f617e 100644 --- a/R/deploy.R +++ b/R/deploy.R @@ -72,10 +72,6 @@ Task <- R6::R6Class( } self$task <- task }, - #' @description Return the associated Connect instance. - get_connect = function() { - self$connect - }, #' @description Return the underlying task. get_task = function() { self$task @@ -146,10 +142,10 @@ ContentTask <- R6::R6Class( #' @param ... Unused. print = function(...) { cat("Posit Connect Content Task: \n") - cat(" Content GUID: ", self$get_content()$guid, "\n", sep = "") + cat(" Content GUID: ", self$content$guid, "\n", sep = "") cat( " URL: ", - self$get_content()$dashboard_url, + self$content$dashboard_url, "\n", sep = "" ) @@ -193,7 +189,7 @@ Vanity <- R6::R6Class( #' @param ... Unused. print = function(...) { cat("Posit Connect Content Vanity URL: \n") - cat(" Content GUID: ", self$get_content()$guid, "\n", sep = "") + cat(" Content GUID: ", self$content$guid, "\n", sep = "") cat(" Vanity URL: ", self$get_vanity()$path, "\n", sep = "") cat("\n") invisible(self) @@ -463,7 +459,7 @@ deploy_current <- function(content) { validate_R6_class(content, "Content") res <- content$deploy() return(ContentTask$new( - connect = content$get_connect(), + connect = content$connect, content = content, task = res )) @@ -491,9 +487,9 @@ deploy_current <- function(content) { #' @export set_vanity_url <- function(content, url, force = FALSE) { validate_R6_class(content, "Content") - con <- content$get_connect() + con <- content$connect error_if_less_than(con$version, "1.8.6") - guid <- content$get_content()$guid + guid <- content$content$guid scoped_experimental_silence() # TODO: Check that the URL provided is appropriate @@ -522,9 +518,9 @@ set_vanity_url <- function(content, url, force = FALSE) { #' @family content functions #' @export delete_vanity_url <- function(content) { - con <- content$get_connect() + con <- content$connect error_if_less_than(con$version, "1.8.6") - guid <- content$get_content()$guid + guid <- content$content$guid con$DELETE(v1_url("content", guid, "vanity"), parser = "parsed") @@ -543,9 +539,9 @@ delete_vanity_url <- function(content) { #' @export get_vanity_url <- function(content) { validate_R6_class(content, "Content") - con <- content$get_connect() + con <- content$connect error_if_less_than(con$version, "1.8.6") - guid <- content$get_content()$guid + guid <- content$content$guid van <- tryCatch( { @@ -667,7 +663,7 @@ swap_vanity_url <- function(from, to) { #' @export poll_task <- function(task, wait = 1, callback = message) { validate_R6_class(task, c("Task", "ContentTask", "VariantTask")) - con <- task$get_connect() + con <- task$connect all_task_data <- list() diff --git a/R/git.R b/R/git.R index 876fef26d..4837299c1 100644 --- a/R/git.R +++ b/R/git.R @@ -157,7 +157,7 @@ deploy_repo_update <- function(content) { warn_experimental("deploy_repo_update") scoped_experimental_silence() - con <- content$get_connect() + con <- content$connect internal_meta <- content$internal_content() repo_data <- tryCatch( { @@ -190,5 +190,5 @@ deploy_repo_update <- function(content) { } task <- content$deploy() - ContentTask$new(connect = con, content = content$get_content(), task = task) + ContentTask$new(connect = con, content = content$content, task = task) } diff --git a/R/promote.R b/R/promote.R index 0ff7417f5..68276d6ef 100644 --- a/R/promote.R +++ b/R/promote.R @@ -48,7 +48,7 @@ promote <- function(from, to, to_key, from_key, name) { to_app <- content_ensure(connect = to_client, name = name) to_app <- content_item(connect = to_client, guid = to_app$guid) - task <- deploy(to_client, bundle = bundle, guid = to_app$get_content()$guid) + task <- deploy(to_client, bundle = bundle, guid = to_app$content$guid) poll_task(task) diff --git a/R/schedule.R b/R/schedule.R index 67a8dabef..97b5090d5 100644 --- a/R/schedule.R +++ b/R/schedule.R @@ -23,18 +23,18 @@ VariantSchedule <- R6::R6Class( #' @description Perform an HTTP GET request of the named API path. Returns an object parsed from the HTTP response. #' @param path API path. GET = function(path) { - self$get_connect()$GET(path) + self$connect$GET(path) }, #' @description Perform an HTTP POST request of the named API path. Returns an object parsed from the HTTP response. #' @param path API path. #' @param body The HTTP payload. POST = function(path, body) { - self$get_connect()$POST(path = path, body = body) + self$connect$POST(path = path, body = body) }, #' @description Perform an HTTP DELETE request of the named API path. Returns the HTTP response object. #' @param path API path. DELETE = function(path) { - self$get_connect()$DELETE(path = path) + self$connect$DELETE(path = path) }, #' @description Set the schedule for this variant #' @param ... Schedule fields. @@ -57,7 +57,7 @@ VariantSchedule <- R6::R6Class( } else { path <- unversioned_url("schedules", self$get_schedule()$id) } - cli <- self$get_connect() + cli <- self$connect res <- cli$POST(path = path, body = params) self$schedule_data <- res @@ -129,7 +129,7 @@ VariantSchedule <- R6::R6Class( "year" = glue::glue("Every {schdata$N} year{plural}"), "Unknown schedule" ) - tz_offset <- .get_offset(self$get_connect(), rawdata$timezone) + tz_offset <- .get_offset(self$connect, rawdata$timezone) c( desc, # TODO: a nice way to print out relative times...? @@ -166,7 +166,7 @@ get_variant_schedule <- function(variant) { validate_R6_class(variant, "Variant") content_details <- variant$get_content() - connect_client <- variant$get_connect() + connect_client <- variant$connect variant_key <- variant$key variant_schedule <- variant$get_schedule_remote() @@ -500,7 +500,7 @@ example_schedules <- list( #' @export set_schedule_remove <- function(.schedule) { validate_R6_class(.schedule, "VariantSchedule") - cli <- .schedule$get_connect() + cli <- .schedule$connect path <- unversioned_url("schedules", .schedule$get_schedule()$id) cli$DELETE(path = path) get_variant(.schedule, .schedule$key) diff --git a/R/tags.R b/R/tags.R index 27a5c2bb5..f48c49493 100644 --- a/R/tags.R +++ b/R/tags.R @@ -192,7 +192,7 @@ get_content_tags <- function(content) { ctags <- content$tags() # TODO: find a way to build a tag tree from a list of tags - tagtree <- get_tags(content$get_connect()) + tagtree <- get_tags(content$connect) res <- filter_tag_tree_id( tagtree, purrr::map_chr(ctags, ~ as.character(.x$id)) @@ -213,7 +213,7 @@ set_content_tag_tree <- function(content, ...) { ) } - tags <- get_tags(content$get_connect()) + tags <- get_tags(content$connect) # check that tags exist tmp <- purrr::pluck(tags, !!!params) diff --git a/R/variant.R b/R/variant.R index 7d04f97aa..8b9b903e7 100644 --- a/R/variant.R +++ b/R/variant.R @@ -20,7 +20,7 @@ Variant <- R6::R6Class( #' @description Get and store the (remote) variant data. get_variant_remote = function() { path <- unversioned_url("variants", self$get_variant()$id) - self$variant <- self$get_connect()$GET(path) + self$variant <- self$connect$GET(path) self$variant }, #' @description Initialize this variant. @@ -45,7 +45,7 @@ Variant <- R6::R6Class( ) { warn_experimental("send_mail") url <- unversioned_url("variants", self$get_variant()$id, "sender") - self$get_connect()$POST( + self$connect$POST( path = url, query = list( email = arg_match(to), @@ -61,7 +61,7 @@ Variant <- R6::R6Class( get_schedule_remote = function() { warn_experimental("get_schedule_remote") url <- unversioned_url("variants", self$get_variant()$id, "schedules") - res <- self$get_connect()$GET(url) + res <- self$connect$GET(url) if (length(res) == 1) { res <- res[[1]] @@ -69,7 +69,7 @@ Variant <- R6::R6Class( if (length(res) > 0) { # add the content guid and variant key - content_guid <- self$get_content()$guid + content_guid <- self$content$guid variant_key <- self$key res <- purrr::list_modify( res, @@ -84,7 +84,7 @@ Variant <- R6::R6Class( get_subscribers = function() { warn_experimental("subscribers") path <- unversioned_url("variants", self$get_variant()$id, "subscribers") - self$get_connect()$GET(path) + self$connect$GET(path) }, #' @description Remove a named subscriber. #' @param guid User GUID. @@ -96,23 +96,23 @@ Variant <- R6::R6Class( "subscribers", guid ) - self$get_connect()$DELETE(path) + self$connect$DELETE(path) }, #' @description Add named subscribers. #' @param guids User GUIDs. add_subscribers = function(guids) { warn_experimental("subscribers") path <- unversioned_url("variants", self$get_variant()$id, "subscribers") - self$get_connect()$POST(path = path, body = guids) + self$connect$POST(path = path, body = guids) }, #' @description Render this variant. render = function() { warn_experimental("render") path <- unversioned_url("variants", self$get_variant()$id, "render") - res <- self$get_connect()$POST(path) + res <- self$connect$POST(path) # add the content guid and variant key - content_guid <- self$get_content()$guid + content_guid <- self$content$guid variant_key <- self$key purrr::list_modify( @@ -125,9 +125,9 @@ Variant <- R6::R6Class( renderings = function() { warn_experimental("renderings") url <- unversioned_url("variants", self$get_variant()$id, "renderings") - res <- self$get_connect()$GET(path = url) + res <- self$connect$GET(path = url) # add the content guid and variant key - content_guid <- self$get_content()$guid + content_guid <- self$content$guid variant_key <- self$key purrr::map( @@ -145,7 +145,7 @@ Variant <- R6::R6Class( params <- rlang::list2(...) # TODO: allow updating a variant url <- unversioned_url("variants", self$get_variant()$id) - res <- self$get_connect()$POST(url, body = params) + res <- self$connect$POST(url, body = params) return(self) }, #' @description Jobs for this variant. @@ -284,8 +284,8 @@ get_variant <- function(content, key) { scoped_experimental_silence() validate_R6_class(content, "Content") Variant$new( - connect = content$get_connect(), - content = content$get_content(), + connect = content$connect, + content = content$content, key = key ) } @@ -329,7 +329,7 @@ variant_render <- function(variant) { rendered <- variant$render() VariantTask$new( - connect = variant$get_connect(), + connect = variant$connect, content = variant$get_content(), key = variant$key, task = rendered diff --git a/tests/integrated/helper.R b/tests/integrated/helper.R index f738d2b9a..5d5d4c2bc 100644 --- a/tests/integrated/helper.R +++ b/tests/integrated/helper.R @@ -31,8 +31,8 @@ deploy_example <- function(connect, name, ...) { ... ) - guid <- tsk$get_content()$guid - content <- content_item(tsk$get_connect(), guid) + guid <- tsk$content$guid + content <- content_item(tsk$connect, guid) # TODO: a smarter, noninteractive wait... suppressMessages(poll_task(tsk)) diff --git a/tests/integrated/test-content.R b/tests/integrated/test-content.R index 1796c9265..958e7df12 100644 --- a/tests/integrated/test-content.R +++ b/tests/integrated/test-content.R @@ -15,7 +15,7 @@ test_that("content_item works", { cont1_tmp <- test_conn_1 %>% content_item(guid = cont1_guid) expect_true(validate_R6_class(cont1_tmp, "Content")) - expect_equal(cont1_tmp$get_content()$guid, cont1_guid) + expect_equal(cont1_tmp$content$guid, cont1_guid) }) test_that("content_title works in a simple example", { @@ -43,8 +43,8 @@ test_that("content_title handles NULL titles gracefully", { ) ) c2 <- deploy(connect = test_conn_1, bundle = bnd, name = c2_name, title = NA) - expect_null(c2$get_content()$title) - null_title <- content_title(test_conn_1, c2$get_content()$guid, "Test Title") + expect_null(c2$content$title) + null_title <- content_title(test_conn_1, c2$content$guid, "Test Title") expect_identical(null_title, "Test Title") }) @@ -110,16 +110,16 @@ test_that("content_update_access_type works", { # returns as expected tsk <- content_update_access_type(tsk, "all") - expect_equal(tsk$get_content()$access_type, "all") + expect_equal(tsk$content$access_type, "all") # modifies the R6 object in place content_update_access_type(tsk, "logged_in") - expect_equal(tsk$get_content()$access_type, "logged_in") + expect_equal(tsk$content$access_type, "logged_in") # works twice content_update_access_type(tsk, "acl") content_update_access_type(tsk, "acl") - expect_equal(tsk$get_content()$access_type, "acl") + expect_equal(tsk$content$access_type, "acl") expect_error(content_update_access_type(tsk), "one of") }) @@ -133,13 +133,13 @@ test_that("content_update works", { tsk <- deploy(connect = test_conn_1, bundle = bund) content_update(tsk, title = "test content_update") - expect_equal(tsk$get_content()$title, "test content_update") + expect_equal(tsk$content$title, "test content_update") # should not change or error with empty input - expect_equal(content_update(tsk)$get_content()$title, "test content_update") + expect_equal(content_update(tsk)$content$title, "test content_update") expect_equal( - content_update(tsk, title = "test content_update2")$get_content()$title, + content_update(tsk, title = "test content_update2")$content$title, "test content_update2" ) }) diff --git a/tests/integrated/test-deploy.R b/tests/integrated/test-deploy.R index 31c51b2da..66d24507a 100644 --- a/tests/integrated/test-deploy.R +++ b/tests/integrated/test-deploy.R @@ -41,13 +41,13 @@ test_that("bundle_dir deploys", { title = cont1_title ) - cont1_guid <<- tsk$get_content()$guid + cont1_guid <<- tsk$content$guid cont1_content <<- tsk # how should we test that deployment happened? expect_true(validate_R6_class(tsk, "Content")) - expect_equal(tsk$get_content()$name, cont1_name) - expect_equal(tsk$get_content()$title, cont1_title) + expect_equal(tsk$content$name, cont1_name) + expect_equal(tsk$content$title, cont1_title) expect_true(validate_R6_class(tsk, "ContentTask")) expect_gt(nchar(tsk$get_task()$task_id), 0) @@ -55,9 +55,9 @@ test_that("bundle_dir deploys", { # with a guid tsk2 <- deploy(connect = test_conn_1, bundle = bund, guid = cont1_guid) expect_true(validate_R6_class(tsk2, "Content")) - expect_equal(tsk2$get_content()$name, cont1_name) - expect_equal(tsk2$get_content()$title, cont1_title) - expect_equal(tsk2$get_content()$guid, cont1_guid) + expect_equal(tsk2$content$name, cont1_name) + expect_equal(tsk2$content$title, cont1_title) + expect_equal(tsk2$content$guid, cont1_guid) }) test_that("bundle_path deploys", { @@ -104,7 +104,7 @@ test_that("delete_bundle() and get_bundles() work", { tsk <- deploy(connect = test_conn_1, bundle = bund) poll_task(tsk) first_bnd <- tsk$get_content_remote()$bundle_id - my_guid <- tsk$get_content()$guid + my_guid <- tsk$content$guid tsk <- deploy(connect = test_conn_1, bundle = bund, guid = my_guid) poll_task(tsk) @@ -292,7 +292,7 @@ test_that("set_image_url works", { res <- set_image_url( cont1_content, - glue::glue("{cont1_content$get_connect()$server}/connect/__favicon__") + glue::glue("{cont1_content$connect$server}/connect/__favicon__") ) expect_true(validate_R6_class(res, "Content")) @@ -491,7 +491,7 @@ test_that("deployment timestamps respect timezone", { ) ) myc <- deploy(test_conn_1, bnd) - myc_guid <- myc$get_content()$guid + myc_guid <- myc$content$guid # will fail without the png package invisible(tryCatch(test_conn_1$GET(url = myc$get_url()), error = function(e) { @@ -602,7 +602,7 @@ test_that("set_thumbnail works with remote paths", { res <- set_thumbnail( cont1_content, - glue::glue("{cont1_content$get_connect()$server}/connect/__favicon__") + glue::glue("{cont1_content$connect$server}/connect/__favicon__") ) expect_true(validate_R6_class(res, "Content")) diff --git a/tests/integrated/test-get.R b/tests/integrated/test-get.R index 0a5635e2f..0e41106cc 100644 --- a/tests/integrated/test-get.R +++ b/tests/integrated/test-get.R @@ -109,7 +109,7 @@ test_that("content_list_with_permissions predicate works", { progress_enabled = FALSE, cl <- content_list_with_permissions( test_conn_1, - .p = ~ .x$guid == deployed$get_content()$guid + .p = ~ .x$guid == deployed$content$guid ) ) @@ -141,7 +141,7 @@ test_that("content_list_guid_has_access works", { expect_true(nrow(filt) <= nrow(cl)) expect_true(nrow(filt) > 0) - expect_true(deployed$get_content()$guid %in% filt$guid) + expect_true(deployed$content$guid %in% filt$guid) }) test_that("content_list_by_tag works", { diff --git a/tests/integrated/test-run-as.R b/tests/integrated/test-run-as.R index b2d996804..3e2a83f4b 100644 --- a/tests/integrated/test-run-as.R +++ b/tests/integrated/test-run-as.R @@ -9,13 +9,13 @@ test_that("set_run_as works with a good linux user", { scoped_experimental_silence() res <- set_run_as(shiny_content, "rstudio-connect") expect_equal( - res$get_content()$run_as, + res$content$run_as, "rstudio-connect" ) skip("TODO: failing because of a bug in Connect") res2 <- set_run_as(shiny_content, NULL) - expect_null(res2$get_content()$run_as) + expect_null(res2$content$run_as) }) test_that("set_run_as fails with a bad linux user", { @@ -37,7 +37,7 @@ test_that("set_run_as works for run_as_current_user", { ) expect_true( - shiny_content$get_content()$run_as_current_user + shiny_content$content$run_as_current_user ) res2 <- set_run_as( @@ -47,6 +47,6 @@ test_that("set_run_as works for run_as_current_user", { ) expect_false( - shiny_content$get_content()$run_as_current_user + shiny_content$content$run_as_current_user ) }) From ef56226765a9fdf4b242a9e986fb0fb298f97ff8 Mon Sep 17 00:00:00 2001 From: Neal Richardson Date: Wed, 15 Oct 2025 08:24:41 -0400 Subject: [PATCH 2/4] doc --- man/Content.Rd | 22 ---------------------- man/ContentTask.Rd | 2 -- man/EnvironmentR6.Rd | 2 -- man/PositConnect.Rd | 11 ----------- man/Task.Rd | 11 ----------- man/Vanity.Rd | 2 -- man/VariantR6.Rd | 2 -- man/VariantSchedule.Rd | 2 -- man/VariantTask.Rd | 2 -- 9 files changed, 56 deletions(-) diff --git a/man/Content.Rd b/man/Content.Rd index 127fd0e57..e8b45a1b2 100644 --- a/man/Content.Rd +++ b/man/Content.Rd @@ -48,8 +48,6 @@ Other R6 classes: \subsection{Public methods}{ \itemize{ \item \href{#method-Content-new}{\code{Content$new()}} -\item \href{#method-Content-get_connect}{\code{Content$get_connect()}} -\item \href{#method-Content-get_content}{\code{Content$get_content()}} \item \href{#method-Content-get_content_remote}{\code{Content$get_content_remote()}} \item \href{#method-Content-get_bundles}{\code{Content$get_bundles()}} \item \href{#method-Content-bundle_download}{\code{Content$bundle_download()}} @@ -99,26 +97,6 @@ Initialize this content. } \if{html}{\out{}} } -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Content-get_connect}{}}} -\subsection{Method \code{get_connect()}}{ -Returns the \code{Connect} instance. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Content$get_connect()}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Content-get_content}{}}} -\subsection{Method \code{get_content()}}{ -Returns the underlying content data. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Content$get_content()}\if{html}{\out{
}} -} - } \if{html}{\out{
}} \if{html}{\out{}} diff --git a/man/ContentTask.Rd b/man/ContentTask.Rd index fcb880aa9..f83bff856 100644 --- a/man/ContentTask.Rd +++ b/man/ContentTask.Rd @@ -58,8 +58,6 @@ Other R6 classes:
  • connectapi::Content$environment_all()
  • connectapi::Content$environment_set()
  • connectapi::Content$get_bundles()
  • -
  • connectapi::Content$get_connect()
  • -
  • connectapi::Content$get_content()
  • connectapi::Content$get_content_remote()
  • connectapi::Content$get_dashboard_url()
  • connectapi::Content$get_url()
  • diff --git a/man/EnvironmentR6.Rd b/man/EnvironmentR6.Rd index 45fd60be9..f179e4dae 100644 --- a/man/EnvironmentR6.Rd +++ b/man/EnvironmentR6.Rd @@ -56,8 +56,6 @@ Other R6 classes:
  • connectapi::Content$danger_delete()
  • connectapi::Content$deploy()
  • connectapi::Content$get_bundles()
  • -
  • connectapi::Content$get_connect()
  • -
  • connectapi::Content$get_content()
  • connectapi::Content$get_content_remote()
  • connectapi::Content$get_dashboard_url()
  • connectapi::Content$get_url()
  • diff --git a/man/PositConnect.Rd b/man/PositConnect.Rd index ce5b14769..241b0c9a4 100644 --- a/man/PositConnect.Rd +++ b/man/PositConnect.Rd @@ -68,7 +68,6 @@ Other R6 classes: \section{Methods}{ \subsection{Public methods}{ \itemize{ -\item \href{#method-Connect-get_connect}{\code{Connect$get_connect()}} \item \href{#method-Connect-new}{\code{Connect$new()}} \item \href{#method-Connect-httr_config}{\code{Connect$httr_config()}} \item \href{#method-Connect-print}{\code{Connect$print()}} @@ -131,16 +130,6 @@ Other R6 classes: \item \href{#method-Connect-server_settings}{\code{Connect$server_settings()}} \item \href{#method-Connect-clone}{\code{Connect$clone()}} } -} -\if{html}{\out{
    }} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Connect-get_connect}{}}} -\subsection{Method \code{get_connect()}}{ -Return this connect. -\subsection{Usage}{ -\if{html}{\out{
    }}\preformatted{Connect$get_connect()}\if{html}{\out{
    }} -} - } \if{html}{\out{
    }} \if{html}{\out{}} diff --git a/man/Task.Rd b/man/Task.Rd index dc1b6a085..df76f9ab4 100644 --- a/man/Task.Rd +++ b/man/Task.Rd @@ -39,7 +39,6 @@ Other R6 classes: \subsection{Public methods}{ \itemize{ \item \href{#method-Task-new}{\code{Task$new()}} -\item \href{#method-Task-get_connect}{\code{Task$get_connect()}} \item \href{#method-Task-get_task}{\code{Task$get_task()}} \item \href{#method-Task-add_data}{\code{Task$add_data()}} \item \href{#method-Task-get_data}{\code{Task$get_data()}} @@ -65,16 +64,6 @@ Initialize this task. } \if{html}{\out{}} } -} -\if{html}{\out{
    }} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Task-get_connect}{}}} -\subsection{Method \code{get_connect()}}{ -Return the associated Connect instance. -\subsection{Usage}{ -\if{html}{\out{
    }}\preformatted{Task$get_connect()}\if{html}{\out{
    }} -} - } \if{html}{\out{
    }} \if{html}{\out{}} diff --git a/man/Vanity.Rd b/man/Vanity.Rd index 06972c992..80a1cdc66 100644 --- a/man/Vanity.Rd +++ b/man/Vanity.Rd @@ -54,8 +54,6 @@ Other R6 classes:
  • connectapi::Content$environment_all()
  • connectapi::Content$environment_set()
  • connectapi::Content$get_bundles()
  • -
  • connectapi::Content$get_connect()
  • -
  • connectapi::Content$get_content()
  • connectapi::Content$get_content_remote()
  • connectapi::Content$get_dashboard_url()
  • connectapi::Content$get_url()
  • diff --git a/man/VariantR6.Rd b/man/VariantR6.Rd index 188fd1cbc..be0cc4a6a 100644 --- a/man/VariantR6.Rd +++ b/man/VariantR6.Rd @@ -71,8 +71,6 @@ Other R6 classes:
  • connectapi::Content$environment_all()
  • connectapi::Content$environment_set()
  • connectapi::Content$get_bundles()
  • -
  • connectapi::Content$get_connect()
  • -
  • connectapi::Content$get_content()
  • connectapi::Content$get_content_remote()
  • connectapi::Content$internal_content()
  • connectapi::Content$packages()
  • diff --git a/man/VariantSchedule.Rd b/man/VariantSchedule.Rd index f4d69f59a..ee961e1ad 100644 --- a/man/VariantSchedule.Rd +++ b/man/VariantSchedule.Rd @@ -61,8 +61,6 @@ Other R6 classes:
  • connectapi::Content$environment_all()
  • connectapi::Content$environment_set()
  • connectapi::Content$get_bundles()
  • -
  • connectapi::Content$get_connect()
  • -
  • connectapi::Content$get_content()
  • connectapi::Content$get_content_remote()
  • connectapi::Content$internal_content()
  • connectapi::Content$packages()
  • diff --git a/man/VariantTask.Rd b/man/VariantTask.Rd index 680248450..4f23bd9ef 100644 --- a/man/VariantTask.Rd +++ b/man/VariantTask.Rd @@ -58,8 +58,6 @@ Other R6 classes:
  • connectapi::Content$environment_all()
  • connectapi::Content$environment_set()
  • connectapi::Content$get_bundles()
  • -
  • connectapi::Content$get_connect()
  • -
  • connectapi::Content$get_content()
  • connectapi::Content$get_content_remote()
  • connectapi::Content$internal_content()
  • connectapi::Content$packages()
  • From ee341c8dc0bf54ff53d88651c5f4e40a93f85842 Mon Sep 17 00:00:00 2001 From: Neal Richardson Date: Wed, 15 Oct 2025 08:41:07 -0400 Subject: [PATCH 3/4] Missed a couple --- R/schedule.R | 2 +- R/variant.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/schedule.R b/R/schedule.R index 97b5090d5..e5e3ca030 100644 --- a/R/schedule.R +++ b/R/schedule.R @@ -165,7 +165,7 @@ get_variant_schedule <- function(variant) { scoped_experimental_silence() validate_R6_class(variant, "Variant") - content_details <- variant$get_content() + content_details <- variant$content connect_client <- variant$connect variant_key <- variant$key diff --git a/R/variant.R b/R/variant.R index 8b9b903e7..7001393fd 100644 --- a/R/variant.R +++ b/R/variant.R @@ -330,7 +330,7 @@ variant_render <- function(variant) { VariantTask$new( connect = variant$connect, - content = variant$get_content(), + content = variant$content, key = variant$key, task = rendered ) From 1f52da495339b017ccc1c9315ed4621da4f9c51c Mon Sep 17 00:00:00 2001 From: Neal Richardson Date: Wed, 15 Oct 2025 08:43:17 -0400 Subject: [PATCH 4/4] Remove get_variant method --- R/schedule.R | 4 ++-- R/variant.R | 25 +++++++++++-------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/R/schedule.R b/R/schedule.R index e5e3ca030..f427a42ef 100644 --- a/R/schedule.R +++ b/R/schedule.R @@ -50,8 +50,8 @@ VariantSchedule <- R6::R6Class( if (self$is_empty()) { params <- purrr::list_modify( params, - app_id = self$get_variant()$app_id, - variant_id = self$get_variant()$id + app_id = self$variant$app_id, + variant_id = self$variant$id ) path <- unversioned_url("schedules") } else { diff --git a/R/variant.R b/R/variant.R index 7001393fd..a526f3946 100644 --- a/R/variant.R +++ b/R/variant.R @@ -14,12 +14,9 @@ Variant <- R6::R6Class( #' @field variant The variant. variant = NULL, #' @description Get the underlying variant data. - get_variant = function() { - self$variant - }, #' @description Get and store the (remote) variant data. get_variant_remote = function() { - path <- unversioned_url("variants", self$get_variant()$id) + path <- unversioned_url("variants", self$variant$id) self$variant <- self$connect$GET(path) self$variant }, @@ -44,12 +41,12 @@ Variant <- R6::R6Class( to = c("me", "collaborators", "collaborators_viewers") ) { warn_experimental("send_mail") - url <- unversioned_url("variants", self$get_variant()$id, "sender") + url <- unversioned_url("variants", self$variant$id, "sender") self$connect$POST( path = url, query = list( email = arg_match(to), - rendering_id = self$get_variant()$rendering_id + rendering_id = self$variant$rendering_id ) ) }, @@ -60,7 +57,7 @@ Variant <- R6::R6Class( #' @description Get the (remote) schedule data. get_schedule_remote = function() { warn_experimental("get_schedule_remote") - url <- unversioned_url("variants", self$get_variant()$id, "schedules") + url <- unversioned_url("variants", self$variant$id, "schedules") res <- self$connect$GET(url) if (length(res) == 1) { @@ -83,7 +80,7 @@ Variant <- R6::R6Class( #' @description Get the subscribers. get_subscribers = function() { warn_experimental("subscribers") - path <- unversioned_url("variants", self$get_variant()$id, "subscribers") + path <- unversioned_url("variants", self$variant$id, "subscribers") self$connect$GET(path) }, #' @description Remove a named subscriber. @@ -92,7 +89,7 @@ Variant <- R6::R6Class( warn_experimental("subscribers") path <- unversioned_url( "variants", - self$get_variant()$id, + self$variant$id, "subscribers", guid ) @@ -102,13 +99,13 @@ Variant <- R6::R6Class( #' @param guids User GUIDs. add_subscribers = function(guids) { warn_experimental("subscribers") - path <- unversioned_url("variants", self$get_variant()$id, "subscribers") + path <- unversioned_url("variants", self$variant$id, "subscribers") self$connect$POST(path = path, body = guids) }, #' @description Render this variant. render = function() { warn_experimental("render") - path <- unversioned_url("variants", self$get_variant()$id, "render") + path <- unversioned_url("variants", self$variant$id, "render") res <- self$connect$POST(path) # add the content guid and variant key @@ -124,7 +121,7 @@ Variant <- R6::R6Class( #' @description List the renderings of this variant. renderings = function() { warn_experimental("renderings") - url <- unversioned_url("variants", self$get_variant()$id, "renderings") + url <- unversioned_url("variants", self$variant$id, "renderings") res <- self$connect$GET(path = url) # add the content guid and variant key content_guid <- self$content$guid @@ -144,7 +141,7 @@ Variant <- R6::R6Class( update_variant = function(...) { params <- rlang::list2(...) # TODO: allow updating a variant - url <- unversioned_url("variants", self$get_variant()$id) + url <- unversioned_url("variants", self$variant$id) res <- self$connect$POST(url, body = params) return(self) }, @@ -180,7 +177,7 @@ Variant <- R6::R6Class( #' @param pane The pane in the dashboard to link to. get_dashboard_url = function(pane = "access") { base_content <- super$get_dashboard_url("") - glue::glue("{base_content}{pane}/{self$get_variant()$id}") + glue::glue("{base_content}{pane}/{self$variant$id}") }, # nolint start: commented_code_linter # TODO: dashboard cannot navigate directly to renderings today