Skip to content

Commit 88864b8

Browse files
committed
update w/ dhm example
1 parent d94c0bb commit 88864b8

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

R/check_authorized_users.R

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,24 @@ check_authorized_users <- function(
2424
checkmate::assert_scalar(gh_actor)
2525
checkmate::assert_string(base_hub_path)
2626

27-
model_metadata <- hubData::load_model_metadata(base_hub_path)
28-
29-
dir_users_map <- model_metadata |>
30-
dplyr::group_by(.data$model_id) |>
31-
dplyr::summarize(
32-
authorized_users = list(
33-
as.character(na.omit(.data$designated_github_users))
34-
),
35-
.groups = "drop"
36-
) |>
27+
model_metadata <- hubData::load_model_metadata(base_hub_path) |>
28+
dplyr::mutate(is_model_dir = TRUE) |>
3729
dplyr::rename(dir = "model_id")
3830

3931
changed_dirs_tbl <- tibble::tibble(dir = changed_dirs)
4032

4133
authorization_check <- changed_dirs_tbl |>
42-
dplyr::left_join(dir_users_map, by = "dir") |>
43-
dplyr::mutate(
44-
dir_not_modifiable = purrr::map_lgl(.data$authorized_users, is.null),
45-
has_authorized_users = purrr::map_lgl(
46-
.data$authorized_users,
47-
\(authorized) length(authorized) > 0
48-
),
49-
actor_authorized = purrr::map_lgl(
50-
.data$authorized_users,
51-
\(authorized) gh_actor %in% authorized
34+
dplyr::left_join(model_metadata, by = "dir", na_matches = "never") |>
35+
dplyr::group_by(.data$dir) |>
36+
dplyr::summarize(
37+
modifiable = all(tidyr::replace_na(.data$is_model_dir, FALSE)),
38+
actor_authorized = !!gh_actor %in% .data$designated_github_users,
39+
authorized_users = paste(
40+
na.omit(.data$designated_github_users),
41+
collapse = ", "
5242
),
43+
has_authorized_users = length(na.omit(.data$designated_github_users)) > 0,
44+
.groups = "drop"
5345
)
5446

5547
problem_dirs <- authorization_check |>
@@ -59,7 +51,7 @@ check_authorized_users <- function(
5951
error_messages <- problem_dirs |>
6052
dplyr::mutate(
6153
error_msg = dplyr::case_when(
62-
.data$dir_not_modifiable ~
54+
!.data$modifiable ~
6355
glue::glue(
6456
"'{.data$dir}' cannot be modified in auto-approved PRs.",
6557
"If this is your team's model output subdirectory, check ",
@@ -71,7 +63,7 @@ check_authorized_users <- function(
7163
),
7264
.data$has_authorized_users ~
7365
glue::glue(
74-
"Only the following users can modify: '{.data$dir}/': {purrr::map_chr(.data$authorized_users, ~paste(.x, collapse = ', '))}"
66+
"Only the following users can modify: '{.data$dir}/': {.data$authorized_users}"
7567
),
7668
TRUE ~ "Unknown authorization error"
7769
)

0 commit comments

Comments
 (0)