Skip to content

Commit

Permalink
Merge pull request #101 from molgenis/feat/create-project-with-userlist
Browse files Browse the repository at this point in the history
Feat/create project with userlist
  • Loading branch information
marikaris authored Nov 16, 2023
2 parents c0f6e33 + 664f170 commit d7a8eeb
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 13 deletions.
23 changes: 18 additions & 5 deletions R/project.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#' \item{cannot end with a \code{-}.}
#' \item{must consist of lowercase letters and numbers.}
#' }
#' @return TRUE if successful
#' @param users A list collection of the users that should have access to the project
#' @return NULL
#'
#' @importFrom httr PUT
#'
Expand All @@ -17,20 +18,32 @@
#' }
#'
#' @export
armadillo.create_project <- function(project_name) { # nolint
armadillo.create_project <- function(project_name, users = NULL) { # nolint
if (is.null(users)) {
users = list()
}
.create_project(project_name, users)

if (length(users) == 0){
usermessage <- "without users"
} else {
usermessage <- paste0("with users: ", paste(unlist(users), collapse=", "))
}
message(paste0("Created project '", project_name, "' ", usermessage))
}

.create_project <- function(project_name, users) {
.check_project_name(project_name)

response <- httr::PUT(
url = .get_url(),
path = "/access/projects",
body = list(name = project_name),
body = list(name = project_name, users = users),
config = c(httr::content_type_json(),
httr::add_headers(.get_auth_header())),
encode = "json"
)
.handle_request_error(response)

message(paste0("Created project '", project_name, "'"))
}

#' Delete project
Expand Down
6 changes: 2 additions & 4 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
## 2.2.0 Add functions for projects
## 2.3.0
* #80 Create project with users
* #81 Retrieve users of projects

## 2.1.11 Bugfixes
* Update github pages using CI
* Fix #98 Cannot create subsets for projects other than "gecko"
* Fix #79 load_table function doesn't show error messages

Expand Down
7 changes: 3 additions & 4 deletions man/armadillo.create_project.Rd

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

45 changes: 45 additions & 0 deletions tests/testthat/test-project.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,51 @@ test_that("armadillo.create_project creates a folder", {
stub_registry_clear()
})

test_that("armadillo.create_project with users", {
stub_request("put", uri = "https://test.nl/access/projects") %>%
wi_th(
headers = list(
"Accept" =
"application/json, text/xml, application/xml, */*",
"Content-Type" = "application/json"),
body = '{"name":"project","users":["[email protected]","[email protected]"]}'
) %>%
to_return(
status = 204
)

expect_message(
armadillo.create_project(
"project",
list("[email protected]", "[email protected]")
),
"Created project 'project' with users: [email protected], [email protected]"
)

stub_registry_clear()
})

test_that("armadillo.create_project with empty user list", {
stub_request("put", uri = "https://test.nl/access/projects") %>%
wi_th(
headers = list(
"Accept" =
"application/json, text/xml, application/xml, */*",
"Content-Type" = "application/json"),
body = '{"name":"project"}'
) %>%
to_return(
status = 204
)

expect_message(
armadillo.create_project("project", list()),
"Created project 'project' without users"
)

stub_registry_clear()
})

test_that("armadillo.list_projects lists all shared buckets", {
stub_request("get", uri = "https://test.nl/access/projects") %>%
to_return(
Expand Down

0 comments on commit d7a8eeb

Please sign in to comment.