Skip to content

Commit 12211c9

Browse files
committed
Added dry-run option for setPermissions for preview of changes.
As the append logic inside setPermissions is a little involved, so users can double-check that they're setting the right permissions.
1 parent ecc94c0 commit 12211c9

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: gobbler
2-
Version: 0.3.16
3-
Date: 2025-06-22
2+
Version: 0.3.17
3+
Date: 2025-07-02
44
Title: Interface to the gobbler service
55
Description:
66
Friendly interface to the gobbler service.

R/setPermissions.R

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#' @param spoof String containing the name of a user on whose behalf this request is being made.
2020
#' This should only be used if the Gobbler service allows spoofing by the current user.
2121
#' If \code{NULL}, no spoofing is performed.
22+
#' @param dryRun Logical scalar indicating whether to return the new permissions without actually modifying the registry.
2223
#' @inheritParams createProject
2324
#'
2425
#' @author Aaron Lun
@@ -28,7 +29,11 @@
2829
#'
2930
#' \code{\link{createProject}}, to set permissions during project creation.
3031
#'
31-
#' @return \code{NULL} is invisibly returned upon successful setting of the permissions.
32+
#' @return If \code{dryRun=FALSE}, \code{NULL} is invisibly returned upon successful setting of the permissions.
33+
#'
34+
#' If \code{dryRun=TRUE}, a named list is returned containing the new permissions for the project/asset.
35+
#' This contains zero, one or more of \code{owners}, \code{uploaders} and \code{global_write} (see \code{\link{fetchPermissions}} for descriptions).
36+
#' A missing field indicates that it will not be updated in the project/asset permissions.
3237
#'
3338
#' @examples
3439
#' info <- startGobbler()
@@ -55,7 +60,7 @@
5560
#' fetchPermissions("test", registry=info$registry)
5661
#'
5762
#' @export
58-
setPermissions <- function(project, registry, staging, url, asset=NULL, owners=NULL, uploaders=NULL, globalWrite=NULL, append=TRUE, spoof=NULL) {
63+
setPermissions <- function(project, registry, staging, url, asset=NULL, owners=NULL, uploaders=NULL, globalWrite=NULL, append=TRUE, spoof=NULL, dryRun=FALSE) {
5964
perms <- list()
6065
names(perms) <- character(0)
6166

@@ -87,7 +92,11 @@ setPermissions <- function(project, registry, staging, url, asset=NULL, owners=N
8792
perms$global_write <- globalWrite
8893
}
8994

95+
if (dryRun) {
96+
return(perms)
97+
}
9098
payload$permissions <- perms
99+
91100
dump_request(staging, url, "set_permissions", payload, spoof=spoof)
92101
invisible(NULL)
93102
}

man/setPermissions.Rd

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-permissions.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ test_that("project-level permission setting works as expected", {
4545
expect_identical(perms$owners, list("LTLA"))
4646
expect_identical(length(perms$uploaders), 2L)
4747

48+
# Dry-run has no effect.
49+
out <- setPermissions("test-perms", owners="foobar", staging=info$staging, url=info$url, registry=info$registry, dryRun=TRUE)
50+
expect_identical(out$owners, list("LTLA", "foobar"))
51+
expect_null(out$uploaders)
52+
perms <- fetchPermissions("test-perms", registry=info$registry)
53+
expect_identical(perms$owners, list("LTLA"))
54+
expect_identical(length(perms$uploaders), 2L)
55+
4856
# Now resetting the uploaders.
4957
setPermissions("test-perms", uploaders=list(), append=FALSE, staging=info$staging, url=info$url, registry=info$registry)
5058
perms <- fetchPermissions("test-perms", registry=info$registry)

0 commit comments

Comments
 (0)