Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to get workspaces for user #4

Merged
merged 2 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/assets.R
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
44 changes: 44 additions & 0 deletions R/my_workspaces.R
Original file line number Diff line number Diff line change
@@ -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)

}
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions man/my_workspaces.Rd

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

4 changes: 2 additions & 2 deletions man/workspace_assets.Rd

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

13 changes: 13 additions & 0 deletions tests/testthat/api/myworkspaces-0ccf8b.R
Original file line number Diff line number Diff line change
@@ -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")
48 changes: 48 additions & 0 deletions tests/testthat/test-my_workspaces.R
Original file line number Diff line number Diff line change
@@ -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"
)

})

})