diff --git a/NAMESPACE b/NAMESPACE index d97685f..c7a65b7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,7 @@ export(asset_info) export(create_folder) export(download_file) export(my_user_id) +export(my_workspaces) export(new_document) export(new_document_version) export(objectiveR) diff --git a/R/assets.R b/R/assets.R index c6cf43d..6dce9e2 100644 --- a/R/assets.R +++ b/R/assets.R @@ -1,4 +1,4 @@ -#' Get data frame of workspace assets +#' Get data frame of assets in workspace #' #' @param workspace_uuid UUID of workspace #' @param type List of asset types to return. Defaults to all types; diff --git a/R/my_workspaces.R b/R/my_workspaces.R new file mode 100644 index 0000000..f207586 --- /dev/null +++ b/R/my_workspaces.R @@ -0,0 +1,44 @@ +#' Get workspaces the current user is a member of +#' +#' @param workgroup_uuid UUID of workgroup to filter by +#' @param page Page number of responses to return (0..N). +#' @param size Number of results to be returned per page. +#' @inheritParams objectiveR +#' +#' @return Data frame +#' +#' @export + +my_workspaces <- function(workgroup_uuid = NULL, + page = NULL, + size = NULL, + use_proxy = FALSE) { + + response <- objectiveR( + endpoint = "myworkspaces", + url_query = list(workgroupUuid = workgroup_uuid, + page = page, + size = size) + ) + + content <- + httr2::resp_body_json(response)$content |> + lapply( + \(content) { + data.frame( + workspace_name = content$name, + workspace_uuid = content$uuid, + participant_uuid = content$participant$uuid, + owner_name = paste(content$owner$givenName, + content$owner$familyName), + owner_email = content$owner$email, + owner_uuid = content$owner$uuid, + workgroup_name = content$workgroup$name, + workgroup_uuid = content$workgroup$uuid + ) + } + ) + + Reduce(dplyr::bind_rows, content) + +} diff --git a/_pkgdown.yml b/_pkgdown.yml index 3653a24..849e414 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -48,6 +48,7 @@ reference: Workspaces are the containers that connect a collection of documents and folders (Assets) with a collection of Users (Participants) contents: + - my_workspaces - participants - subtitle: Assets diff --git a/man/my_workspaces.Rd b/man/my_workspaces.Rd new file mode 100644 index 0000000..648f79d --- /dev/null +++ b/man/my_workspaces.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/my_workspaces.R +\name{my_workspaces} +\alias{my_workspaces} +\title{Get workspaces the current user is a member of} +\usage{ +my_workspaces( + workgroup_uuid = NULL, + page = NULL, + size = NULL, + use_proxy = FALSE +) +} +\arguments{ +\item{workgroup_uuid}{UUID of workgroup to filter by} + +\item{page}{Page number of responses to return (0..N).} + +\item{size}{Number of results to be returned per page.} + +\item{use_proxy}{Logical to indicate whether to use proxy} +} +\value{ +Data frame +} +\description{ +Get workspaces the current user is a member of +} diff --git a/man/workspace_assets.Rd b/man/workspace_assets.Rd index ea32932..38cd859 100644 --- a/man/workspace_assets.Rd +++ b/man/workspace_assets.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/assets.R \name{workspace_assets} \alias{workspace_assets} -\title{Get data frame of workspace assets} +\title{Get data frame of assets in workspace} \usage{ workspace_assets( workspace_uuid, @@ -28,5 +28,5 @@ document, folder and link.} Data frame } \description{ -Get data frame of workspace assets +Get data frame of assets in workspace } diff --git a/tests/testthat/api/myworkspaces-0ccf8b.R b/tests/testthat/api/myworkspaces-0ccf8b.R new file mode 100644 index 0000000..6c6e79b --- /dev/null +++ b/tests/testthat/api/myworkspaces-0ccf8b.R @@ -0,0 +1,13 @@ +structure(list(method = "GET", url = "https://api/myworkspaces?workgroupUuid=df05-8377-f703-4ce8-a163-9104-2bc6-64e5", + status_code = 200L, headers = structure(list(Date = "Thu, 09 May 2024 15:49:51 GMT", + `Content-Type` = "application/json", `Transfer-Encoding` = "chunked", + Connection = "keep-alive", `X-CONNECT-MDC` = "apipGcxcEvR", + `X-Frame-Options` = "deny", `X-XSS-Protection` = "1; mode=block", + `Cache-Control` = "no-cache, no-store", Expires = "0", + Pragma = "no-cache", `Strict-Transport-Security` = "max-age=31536000 ; includeSubDomains", + `Content-Security-Policy` = "script-src 'self' 'unsafe-inline'", + `X-Content-Type-Options` = "nosniff", `Referrer-Policy` = "strict-origin-when-cross-origin", + `Feature-Policy` = "vibrate 'none'; geolocation 'none'", + Authorization = "REDACTED", `Set-Cookie` = "REDACTED"), class = "httr2_headers"), + body = charToRaw("{\"content\":[{\"uuid\":\"test_workspace_uuid\",\"name\":\"test_workspace_name\",\"participant\":{\"uuid\":\"test_participant_uuid\"},\"owner\":{\"uuid\":\"test_owner_uuid\",\"email\":\"test_owner_email\",\"givenName\":\"test_owner_name\",\"familyName\":\"test_owener_surname\"},\"workgroup\":{\"uuid\":\"test_workgroup_uuid\",\"name\":\"test_workgroup_name\"}}]}"), + cache = new.env(parent = emptyenv())), class = "httr2_response") diff --git a/tests/testthat/test-my_workspaces.R b/tests/testthat/test-my_workspaces.R new file mode 100644 index 0000000..93a01fc --- /dev/null +++ b/tests/testthat/test-my_workspaces.R @@ -0,0 +1,48 @@ + +without_internet({ + + test_that("Valid request created", { + + expect_GET( + my_workspaces(), + "https://secure.objectiveconnect.co.uk/publicapi/1/myworkspaces" + ) + + expect_GET( + my_workspaces(workgroup_uuid = "test_workgroup"), + paste0("https://secure.objectiveconnect.co.uk/publicapi/1/myworkspaces?", + "workgroupUuid=test_workgroup") + ) + + }) + +}) + +with_mock_api({ + + with_envvar( + + new = c("OBJECTIVER_USR" = "test_usr", + "OBJECTIVER_PWD" = "test_pwd"), + + code = { + + test_that("Function returns dataframe", { + + expect_s3_class( + my_workspaces(workgroup_uuid = "test_workgroup_uuid"), + "data.frame" + ) + + }) + + expect_equal( + unique( + my_workspaces(workgroup_uuid = "test_workgroup_uuid")$workgroup_uuid + ), + "test_workgroup_uuid" + ) + + }) + +})