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 content action. #54

Merged
merged 6 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
RoxygenNote: 7.2.1
32 changes: 17 additions & 15 deletions R/members.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,25 +157,27 @@ space_member_add.data.frame <- function(space, users, ...) {
#' @inheritParams space_info
#' @param users ID number or email of the user to be removed, or a data frame
#' with either a `user_id` or `email` column.
#' @param remove_projects Whether to remove user's projects from the workspace
#' and move them to their personal space or to keep the projects in the
#' workspace.
#' @param content_action What to do with the users content after they are
#' removed from the space. Options for the content are to: "leave"
#' leaving the content where it is, "archive" moving the content to
Comment on lines +161 to +162
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing "leave" on its own made me realize it might be a bit counter-intuitive -- sounds like leaving a place more than leaving in place. I wonder if the option could be "keep" instead?

  • "keep": keep content where it is
  • "archive": move tp space archive
  • "trash": move to space trash

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think those would make sense. I might re-map them here. It is a bit more difficult on my end to tweak them at this point.

#' the space archive, and "trash" moving the content to the spaces
#' trash.
#' @param ask Whether to ask user for confirmation of deletion.
#'
#' @export
space_member_remove <- function(space, users, remove_projects = NULL, ask = TRUE) {
space_member_remove <- function(space, users, content_action = NULL, ask = TRUE) {
UseMethod("space_member_remove", users)
}

#' @rdname space_member_remove
#' @export
space_member_remove.numeric <- function(space, users, remove_projects = NULL, ask = TRUE) {
space_member_remove.numeric <- function(space, users, content_action = NULL, ask = TRUE) {
if (!rlang::is_scalar_integerish(users)) {
usethis::ui_stop("{ui_field('users')} must be a single user ID or email. For removing multiple users please pass a data frame.")
}

if (rlang::is_null(remove_projects)) {
usethis::ui_stop("{ui_field('remove_projects')} must be {ui_value(TRUE)} or {ui_value(FALSE)}. If {ui_value(TRUE)} user's projects are moved to their personal space. If {ui_value(FALSE)}, user's projects are left in the workspace.")
if (rlang::is_null(content_action)) {
usethis::ui_stop("{ui_field('content_action')} must be either \"leave\", \"archive\", \"trash\".")
}

if (ask) {
Expand All @@ -189,12 +191,12 @@ space_member_remove.numeric <- function(space, users, remove_projects = NULL, as

space_id <- space_id(space)

remove_projects_value <- tolower(as.character(remove_projects))
content_action <- as.character(content_action)

req <- rscloud_rest(
path = c("spaces", space_id, "members", users),
verb = "DELETE",
query = list(remove_projects = remove_projects_value)
query = list(content_action = content_action)
)

usethis::ui_done("Removed member with {ui_field('user_id')} {ui_value(users)}.")
Expand All @@ -204,7 +206,7 @@ space_member_remove.numeric <- function(space, users, remove_projects = NULL, as

#' @rdname space_member_remove
#' @export
space_member_remove.character <- function(space, users, remove_projects = NULL, ask = TRUE) {
space_member_remove.character <- function(space, users, content_action = NULL, ask = TRUE) {
if (!is_valid_email(users)) {
usethis::ui_stop("{ui_field('users')} must be a single user ID or email. For removing multiple users please pass a data frame.")
}
Expand All @@ -215,16 +217,16 @@ space_member_remove.character <- function(space, users, remove_projects = NULL,

space_member_remove(space,
users = id_to_remove,
remove_projects = remove_projects,
content_action = content_action,
ask = ask
)
}

#' @rdname space_member_remove
#' @export
space_member_remove.data.frame <- function(space, users, remove_projects = NULL, ask = TRUE) {
if (rlang::is_null(remove_projects)) {
usethis::ui_stop("{ui_field('remove_projects')} must be {ui_value(TRUE)} or {ui_value(FALSE)}. If {ui_value(TRUE)} user's projects are moved to their personal space. If {ui_value(FALSE)}, user's projects are left in the workspace.")
space_member_remove.data.frame <- function(space, users, content_action = NULL, ask = TRUE) {
if (rlang::is_null(content_action)) {
usethis::ui_stop("{ui_field('content_action')} must be either \"leave\", \"archive\", \"trash\".")
}

users <- if (!is.null(user_id <- users[["user_id"]])) {
Expand All @@ -248,7 +250,7 @@ space_member_remove.data.frame <- function(space, users, remove_projects = NULL,
}
}

purrr::walk(users, space_member_remove, space = space, remove_projects = remove_projects, ask = FALSE)
purrr::walk(users, space_member_remove, space = space, content_action = content_action, ask = FALSE)
invisible(space)
}

Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ members <- space %>%
space_member_list() %>%
dplyr::filter(email != "rscloud.test.01@gmail.com")
space %>%
purrr::safely(space_member_remove)(members, remove_projects = TRUE, ask = FALSE)
purrr::safely(space_member_remove)(members, content_action = "leave", ask = FALSE)

space %>%
purrr::possibly(space_invitation_list, otherwise = NULL)() %>%
Expand Down
16 changes: 9 additions & 7 deletions man/space_member_remove.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/helper-initialize.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ clean_up <- function() {
space_member_list() %>%
dplyr::filter(email != "rscloud.test.01@gmail.com")
space %>%
purrr::safely(space_member_remove)(members, remove_projects = TRUE, ask = FALSE)
purrr::safely(space_member_remove)(members, content_action = "leave", ask = FALSE)

space %>%
purrr::possibly(space_invitation_list, otherwise = NULL)() %>%
Expand Down