diff --git a/DESCRIPTION b/DESCRIPTION index 1872a04..5e98762 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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. diff --git a/R/fetchPermissions.R b/R/fetchPermissions.R index 91bd874..ea2a94b 100644 --- a/R/fetchPermissions.R +++ b/R/fetchPermissions.R @@ -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 diff --git a/R/setPermissions.R b/R/setPermissions.R index 5c91789..8225201 100644 --- a/R/setPermissions.R +++ b/R/setPermissions.R @@ -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. @@ -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) @@ -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) } diff --git a/R/startGobbler.R b/R/startGobbler.R index be6bb67..9751b62 100644 --- a/R/startGobbler.R +++ b/R/startGobbler.R @@ -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))) } diff --git a/man/fetchPermissions.Rd b/man/fetchPermissions.Rd index 2a941aa..828ab88 100644 --- a/man/fetchPermissions.Rd +++ b/man/fetchPermissions.Rd @@ -32,9 +32,12 @@ If not provided, there is no restriction on the uploaded asset name. 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. } } \description{ diff --git a/man/setPermissions.Rd b/man/setPermissions.Rd index 1ae44d4..52793f2 100644 --- a/man/setPermissions.Rd +++ b/man/setPermissions.Rd @@ -11,6 +11,7 @@ setPermissions( url, owners = NULL, uploaders = NULL, + globalWrite = NULL, append = TRUE ) } @@ -30,6 +31,9 @@ If \code{NULL}, no change is made to the existing owners of the 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.} +\item{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.} + \item{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.} } diff --git a/man/startGobbler.Rd b/man/startGobbler.Rd index 471616f..62f81b0 100644 --- a/man/startGobbler.Rd +++ b/man/startGobbler.Rd @@ -10,7 +10,7 @@ startGobbler( registry = tempfile(), port = NULL, wait = 1, - version = "0.3.4", + version = "0.3.7", overwrite = FALSE ) diff --git a/tests/testthat/test-permissions.R b/tests/testthat/test-permissions.R index 4055623..b90e070 100644 --- a/tests/testthat/test-permissions.R +++ b/tests/testthat/test-permissions.R @@ -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) @@ -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) })