Skip to content

Commit

Permalink
Added globalWrite= option to setPermissions.
Browse files Browse the repository at this point in the history
Bumped the version of the gobbler binary to use for testing the global
write option. Also documented global_write= in fetchPermissions output.
  • Loading branch information
LTLA committed Oct 18, 2024
1 parent 36c2178 commit 3670080
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 7 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: gobbler
Version: 0.3.9
Date: 2024-10-02
Version: 0.3.10
Date: 2024-10-18
Title: Interface to the gobbler service
Description:
Friendly interface to the gobbler service.
Expand Down
5 changes: 4 additions & 1 deletion R/fetchPermissions.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
#' If not provided, there is no restriction on the uploaded version name.
#' \item (optional) \code{until}, a \link{POSIXct} object containing the expiry date of this authorization.
#' If not provided, the authorization does not expire.
#' \item (optional) \code{trusted}, whether the uploader is trusted.
#' \item (optional) \code{trusted}, a logical scalar indicating whether the uploader is trusted.
#' If not provided, defaults to \code{FALSE}.
#' }
#' \item (optional) \code{global_write}, a logical scalar indicating whether global writes are enabled.
#' In this mode, any user can create any number of new assets in this project.
#' Each user can also upload new versions of any asset that they created in this mode.
#' }
#'
#' @author Aaron Lun
Expand Down
8 changes: 7 additions & 1 deletion R/setPermissions.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#' @param uploaders List specifying the authorized uploaders for this project.
#' See the \code{uploaders} field in the \code{\link{fetchPermissions}} return value for the expected format.
#' If \code{NULL}, no change is made to the existing uploaders of the project.
#' @param globalWrite Logical scalar indicating whether global writes should be enabled (see \code{\link{fetchPermissions}} for details).
#' If \code{NULL}, no change is made to the global write status of the project.
#' @param append Logical scalar indicating whether \code{owners} and \code{uploaders} should be appended to the existing owners and uploaders, respectively, of the project.
#' If \code{FALSE}, the \code{owners} and \code{uploaders} are used to replace the existing values.
#' @param registry String containing a path to the registry.
Expand Down Expand Up @@ -47,7 +49,7 @@
#' fetchPermissions("test", registry=info$registry)
#'
#' @export
setPermissions <- function(project, registry, staging, url, owners=NULL, uploaders=NULL, append=TRUE) {
setPermissions <- function(project, registry, staging, url, owners=NULL, uploaders=NULL, globalWrite=NULL, append=TRUE) {
perms <- list()
if (append) {
old.perms <- fetchPermissions(project, registry=registry)
Expand All @@ -70,6 +72,10 @@ setPermissions <- function(project, registry, staging, url, owners=NULL, uploade
perms$uploaders <- sanitize_uploaders(perms$uploaders)
}

if (!is.null(globalWrite)) {
perms$global_write <- globalWrite
}

dump_request(staging, url, "set_permissions", list(project=project, permissions=perms))
invisible(NULL)
}
2 changes: 1 addition & 1 deletion R/startGobbler.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#'
#' @export
#' @importFrom utils download.file
startGobbler <- function(staging=tempfile(), registry=tempfile(), port = NULL, wait = 1, version = "0.3.4", overwrite = FALSE) {
startGobbler <- function(staging=tempfile(), registry=tempfile(), port = NULL, wait = 1, version = "0.3.7", overwrite = FALSE) {
if (!is.null(running$active)) {
return(list(new=FALSE, staging=running$staging, registry=running$registry, port=running$port, url=assemble_url(running$port)))
}
Expand Down
5 changes: 4 additions & 1 deletion man/fetchPermissions.Rd

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

4 changes: 4 additions & 0 deletions man/setPermissions.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/startGobbler.Rd

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

9 changes: 9 additions & 0 deletions tests/testthat/test-permissions.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ test_that("permission setting works as expected", {
expect_identical(length(perms$uploaders), 1L)
expect_identical(perms$uploaders[[1]]$id, "lawremi")
expect_equal(perms$uploaders[[1]]$until, until)
expect_null(perms$global_write)

# Checking uploader appending, while also checking owners=NULL.
setPermissions("test-perms", uploaders=list(list(id="ArtifactDB-bot", trusted=TRUE)), staging=info$staging, url=info$url, registry=info$registry)
Expand Down Expand Up @@ -49,4 +50,12 @@ test_that("permission setting works as expected", {
perms <- fetchPermissions("test-perms", registry=info$registry)
expect_identical(perms$owners, list("LTLA"))
expect_identical(length(perms$uploaders), 0L)

# Enabling global writes.
setPermissions("test-perms", globalWrite=TRUE, staging=info$staging, url=info$url, registry=info$registry)
perms <- fetchPermissions("test-perms", registry=info$registry)
expect_true(perms$global_write)
setPermissions("test-perms", globalWrite=FALSE, staging=info$staging, url=info$url, registry=info$registry)
perms <- fetchPermissions("test-perms", registry=info$registry)
expect_false(perms$global_write)
})

0 comments on commit 3670080

Please sign in to comment.