Skip to content

Commit 2522605

Browse files
toph-allenkarawoo
andauthored
feat: add lock_content() and unlock_content() (#457)
Co-authored-by: Kara Woo <[email protected]>
1 parent 14f7487 commit 2522605

39 files changed

+321
-2
lines changed

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export(get_variants)
125125
export(groups_create_remote)
126126
export(has_image)
127127
export(has_thumbnail)
128+
export(lock_content)
128129
export(page_cursor)
129130
export(page_offset)
130131
export(poll_task)
@@ -163,6 +164,7 @@ export(swap_vanity_url)
163164
export(swap_vanity_urls)
164165
export(tbl_connect)
165166
export(terminate_jobs)
167+
export(unlock_content)
166168
export(update_integration)
167169
export(user_guid_from_username)
168170
export(users_create_remote)

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
- Support content search API with the `search_content()` function. (#272)
1313
- New `search_content()` function which lets you search and filter content items
1414
on the Connect server. (#272, #447)
15+
- New `lock_content()` and `unlock_content()` functions for locking and unlocking
16+
content items. (#453)
1517

1618
# connectapi 0.8.0
1719

R/connect.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ Connect <- R6::R6Class(
4545
#' @param server The base URL of your Posit Connect server.
4646
#' @param api_key Your Posit Connect API key.
4747
initialize = function(server, api_key) {
48-
message_if_not_testing(glue::glue("Defining Connect with server: {server}"))
48+
message_if_not_testing(glue::glue(
49+
"Defining Connect with server: {server}"
50+
))
4951
if (is.null(httr::parse_url(server)$scheme)) {
5052
stop(glue::glue(
5153
"ERROR: Please provide a protocol (http / https). You gave: {server}"
@@ -450,7 +452,10 @@ Connect <- R6::R6Class(
450452
include = "tags,owner"
451453
) {
452454
if (!is.null(guid)) {
453-
return(self$GET(v1_url("content", guid), query = list(include = include)))
455+
return(self$GET(
456+
v1_url("content", guid),
457+
query = list(include = include)
458+
))
454459
}
455460

456461
query <- list(

R/content.R

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,65 @@ content_update_owner <- function(content, owner_guid) {
10511051
content_update(content = content, owner_guid = owner_guid)
10521052
}
10531053

1054+
#' Lock or Unlock Content
1055+
#'
1056+
#' Lock or unlock a content item. When content is locked, all processes are
1057+
#' terminated, rendering is disabled, and new bundles cannot be deployed.
1058+
#'
1059+
#' `lock_content()` locks a content item with an optional message displayed to
1060+
#' visitors (supports Markdown).
1061+
#'
1062+
#' `unlock_content()` unlocks a content item, reverting the effects of locking.
1063+
#'
1064+
#' @param content An R6 content item
1065+
#' @param locked_message Optional. A custom message that is displayed by the
1066+
#' content item when locked. It is possible to format this message using Markdown.
1067+
#'
1068+
#' @return An R6 content item
1069+
#'
1070+
#' @family content functions
1071+
#' @rdname lock_content
1072+
#' @export
1073+
#' @examples
1074+
#' \dontrun{
1075+
#' # Lock content with a message
1076+
#' client <- connect()
1077+
#' content <- content_item(client, "content-guid")
1078+
#' content <- lock_content(content, locked_message = "Ah ah ah! You didn't say the magic word!")
1079+
#'
1080+
#' # Lock content without a message
1081+
#' content <- lock_content(content)
1082+
#'
1083+
#' # Unlock content
1084+
#' content <- unlock_content(content)
1085+
#' }
1086+
lock_content <- function(content, locked_message = "") {
1087+
validate_R6_class(content, "Content")
1088+
error_if_less_than(content$connect$version, "2024.08.0")
1089+
1090+
update_params <- list(locked = TRUE)
1091+
if (!is.null(locked_message)) {
1092+
update_params$locked_message <- locked_message
1093+
}
1094+
1095+
content$update(!!!update_params)
1096+
content$get_content_remote()
1097+
1098+
return(content)
1099+
}
1100+
1101+
#' @rdname lock_content
1102+
#' @export
1103+
unlock_content <- function(content) {
1104+
validate_R6_class(content, "Content")
1105+
error_if_less_than(content$connect$version, "2024.08.0")
1106+
1107+
content$update(locked = FALSE, locked_message = "")
1108+
content$get_content_remote()
1109+
1110+
return(content)
1111+
}
1112+
10541113

10551114
#' Verify Content Name
10561115
#'

man/content_delete.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/content_item.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/content_title.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/content_update.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/create_random_name.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/dashboard_url.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)