From 8128f109d0dca873247e229cd604f1642dfbf565 Mon Sep 17 00:00:00 2001 From: afwillia Date: Thu, 13 Jun 2024 12:25:49 -0700 Subject: [PATCH 1/7] Change stop() to nx_report_error() for user permission error --- server.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server.R b/server.R index 8f3ed576..f3cd9472 100644 --- a/server.R +++ b/server.R @@ -141,7 +141,13 @@ shinyServer(function(input, output, session) { }, 1L) asset_views(all_asset_views[has_access == 1]) - if (length(asset_views) == 0) stop("You do not have DOWNLOAD access to any supported Asset Views.") + if (length(asset_views) == 0) { + nx_report_error( + title = "You do not have DOWNLOAD access to any supported Asset Views", + message = "Contact your DCC admin for access" + ) + hide(selector = "#NXReportButton") # hide OK button so users can't continue + } updateSelectInput(session, "dropdown_asset_view", choices = asset_views() ) From 32fc4ad457f972914d78774d72f911d30837419d Mon Sep 17 00:00:00 2001 From: afwillia Date: Tue, 2 Jul 2024 15:21:34 -0700 Subject: [PATCH 2/7] Create function to read DCA config file and explicitly check for required variables and set defaults for missing optional ones. --- R/read_dca_config.R | 101 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 R/read_dca_config.R diff --git a/R/read_dca_config.R b/R/read_dca_config.R new file mode 100644 index 00000000..2bbfe4bf --- /dev/null +++ b/R/read_dca_config.R @@ -0,0 +1,101 @@ +#' @title Read the DCA config file and report issues +#' @param config URL or filepath to a DCA JSON config file +read_dca_config <- function(config) { + conf <- jsonlite::fromJSON(config) + + name_check <- function(req, prov) { + if (!all(req %in% prov)) { + which_miss <- req[which(!req %in% prov)] + stop(sprintf("DCA config missing %s", which_miss)) + } + } + + lvl_1_props_req <- list( + "dcc" = list(), + "dca" = list(), + "schematic" = list() + ) + lvl_1_props_ops <- list() # Placeholder for optional properties + lvl_1_props_conf <- names(conf) + name_check(names(lvl_1_props_req), lvl_1_props_conf) + + dca_props_req <- list() # Placeholder for required DCA properties + dca_props_ops <- list( + "use_compliance_dashboard" = FALSE, + "primary_col" = "#2a668d", + "secondary_col" = "#184e71", + "sidebar_col" = "#191919" + ) + dca_props_conf <- names(conf$dca) + name_check(names(dca_props_req), dca_props_conf) + + if (!"use_compliance_dashboard" %in% dca_props_conf) { + conf$dca$use_compliance_dashboard <- FALSE + } + if (!"primary_col" %in% dca_props_conf) { + conf$dca$primary_col <- "#2a668d" + } + if (!"secondary_col" %in% dca_props_conf) { + conf$dca$secondary_col <- "#184e71" + } + if (!"primary_col" %in% dca_props_conf) { + conf$dca$sidebar_col <- "#191919" + } + + # required elements should not have a default. Should error if not provided. + # WIP, confirm required and move others to ops with defaults + schematic_props_req <- list( + "manifest_generate" = list(), + "model_validate" = list(), + "model_submit" = list() + ) + schematic_props_ops <- list( + "global" = list() + ) + schematic_props_conf <- names(conf$schematic) + name_check(names(schematic_props_req), schematic_props_conf) + + if (!"global" %in% schematic_props_conf) { + conf$schematic$global <- list() + } + + global_ops <- list( + "data_model_labels" = "class_label" + ) + global_conf <- names(conf$schematic$global) + if (!"data_model_labels" %in% global_conf) { + conf$schematic$global$data_model_labels <- "class_label" + } + + # required elements should not have a default. Should error if not provided. + # WIP, confirm required and move others to ops with defaults + mg_props_req <- list( + "output_format" = "excel", + "use_annotations" = TRUE + ) + mg_props_ops <- list() + mg_props_conf <- names(conf$schematic$manifest_generate) + name_check(names(mg_props_req), mg_props_conf) + + # required elements should not have a default. Should error if not provided. + # WIP, confirm required and move others to ops with defaults + mv_props_req <- list( + "restrict_rules" = FALSE + ) + mv_props_ops <- list() + mv_props_conf <- names(conf$schematic$model_validate) + name_check(names(mv_props_req), mv_props_conf) + + # required elements should not have a default. Should error if not provided. + # WIP, confirm required and move others to ops with defaults + ms_props_req <- list( + "table_manipulation" = "replace", + "manifest_record_type" = "file_only", + "hide_blanks" = FALSE + ) + ms_props_ops <- list() + ms_props_conf <- names(conf$schematic$model_submit) + + conf + +} From 3887dc10180a18cb7b2797b6666be1af4dc78d73 Mon Sep 17 00:00:00 2001 From: afwillia Date: Tue, 2 Jul 2024 15:23:53 -0700 Subject: [PATCH 3/7] Read DCA config with function --- server.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.R b/server.R index f3cd9472..fc740883 100644 --- a/server.R +++ b/server.R @@ -184,7 +184,7 @@ shinyServer(function(input, output, session) { tenant_config_react(tenants_config[tenants_config$synapse_asset_view == selected$master_asset_view(), ]) if (dca_schematic_api == "offline") tenant_config_react(tenants_config[tenants_config$name == "DCA Demo", ]) - dcc_config_react(read_json( + dcc_config_react(read_dca_config( file.path(config_dir, tenant_config_react()$config_location) )) From fb6466924714054d13e6d950a13ff9c76b999420 Mon Sep 17 00:00:00 2001 From: afwillia Date: Tue, 2 Jul 2024 15:24:10 -0700 Subject: [PATCH 4/7] Add function to read DCA config file --- functions/read_dca_config.R | 101 ++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 functions/read_dca_config.R diff --git a/functions/read_dca_config.R b/functions/read_dca_config.R new file mode 100644 index 00000000..2bbfe4bf --- /dev/null +++ b/functions/read_dca_config.R @@ -0,0 +1,101 @@ +#' @title Read the DCA config file and report issues +#' @param config URL or filepath to a DCA JSON config file +read_dca_config <- function(config) { + conf <- jsonlite::fromJSON(config) + + name_check <- function(req, prov) { + if (!all(req %in% prov)) { + which_miss <- req[which(!req %in% prov)] + stop(sprintf("DCA config missing %s", which_miss)) + } + } + + lvl_1_props_req <- list( + "dcc" = list(), + "dca" = list(), + "schematic" = list() + ) + lvl_1_props_ops <- list() # Placeholder for optional properties + lvl_1_props_conf <- names(conf) + name_check(names(lvl_1_props_req), lvl_1_props_conf) + + dca_props_req <- list() # Placeholder for required DCA properties + dca_props_ops <- list( + "use_compliance_dashboard" = FALSE, + "primary_col" = "#2a668d", + "secondary_col" = "#184e71", + "sidebar_col" = "#191919" + ) + dca_props_conf <- names(conf$dca) + name_check(names(dca_props_req), dca_props_conf) + + if (!"use_compliance_dashboard" %in% dca_props_conf) { + conf$dca$use_compliance_dashboard <- FALSE + } + if (!"primary_col" %in% dca_props_conf) { + conf$dca$primary_col <- "#2a668d" + } + if (!"secondary_col" %in% dca_props_conf) { + conf$dca$secondary_col <- "#184e71" + } + if (!"primary_col" %in% dca_props_conf) { + conf$dca$sidebar_col <- "#191919" + } + + # required elements should not have a default. Should error if not provided. + # WIP, confirm required and move others to ops with defaults + schematic_props_req <- list( + "manifest_generate" = list(), + "model_validate" = list(), + "model_submit" = list() + ) + schematic_props_ops <- list( + "global" = list() + ) + schematic_props_conf <- names(conf$schematic) + name_check(names(schematic_props_req), schematic_props_conf) + + if (!"global" %in% schematic_props_conf) { + conf$schematic$global <- list() + } + + global_ops <- list( + "data_model_labels" = "class_label" + ) + global_conf <- names(conf$schematic$global) + if (!"data_model_labels" %in% global_conf) { + conf$schematic$global$data_model_labels <- "class_label" + } + + # required elements should not have a default. Should error if not provided. + # WIP, confirm required and move others to ops with defaults + mg_props_req <- list( + "output_format" = "excel", + "use_annotations" = TRUE + ) + mg_props_ops <- list() + mg_props_conf <- names(conf$schematic$manifest_generate) + name_check(names(mg_props_req), mg_props_conf) + + # required elements should not have a default. Should error if not provided. + # WIP, confirm required and move others to ops with defaults + mv_props_req <- list( + "restrict_rules" = FALSE + ) + mv_props_ops <- list() + mv_props_conf <- names(conf$schematic$model_validate) + name_check(names(mv_props_req), mv_props_conf) + + # required elements should not have a default. Should error if not provided. + # WIP, confirm required and move others to ops with defaults + ms_props_req <- list( + "table_manipulation" = "replace", + "manifest_record_type" = "file_only", + "hide_blanks" = FALSE + ) + ms_props_ops <- list() + ms_props_conf <- names(conf$schematic$model_submit) + + conf + +} From 4996ebb78a7c376196e7fa1b23a52378bc52ab49 Mon Sep 17 00:00:00 2001 From: afwillia Date: Wed, 3 Jul 2024 10:11:54 -0700 Subject: [PATCH 5/7] add cross_manifest_validation to config check --- R/read_dca_config.R | 8 +++++++- functions/read_dca_config.R | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/R/read_dca_config.R b/R/read_dca_config.R index 2bbfe4bf..8bfc1278 100644 --- a/R/read_dca_config.R +++ b/R/read_dca_config.R @@ -82,10 +82,16 @@ read_dca_config <- function(config) { mv_props_req <- list( "restrict_rules" = FALSE ) - mv_props_ops <- list() + mv_props_ops <- list( + "cross_manifest_validation" = FALSE + ) mv_props_conf <- names(conf$schematic$model_validate) name_check(names(mv_props_req), mv_props_conf) + if (!"cross_manifest_validation" %in% mv_props_confg) { + conf$schematic$model_validate$cross_manifest_validation <- FALSE + } + # required elements should not have a default. Should error if not provided. # WIP, confirm required and move others to ops with defaults ms_props_req <- list( diff --git a/functions/read_dca_config.R b/functions/read_dca_config.R index 2bbfe4bf..8bfc1278 100644 --- a/functions/read_dca_config.R +++ b/functions/read_dca_config.R @@ -82,10 +82,16 @@ read_dca_config <- function(config) { mv_props_req <- list( "restrict_rules" = FALSE ) - mv_props_ops <- list() + mv_props_ops <- list( + "cross_manifest_validation" = FALSE + ) mv_props_conf <- names(conf$schematic$model_validate) name_check(names(mv_props_req), mv_props_conf) + if (!"cross_manifest_validation" %in% mv_props_confg) { + conf$schematic$model_validate$cross_manifest_validation <- FALSE + } + # required elements should not have a default. Should error if not provided. # WIP, confirm required and move others to ops with defaults ms_props_req <- list( From 95c353fefc3805bb629046b031cb005455f63e8b Mon Sep 17 00:00:00 2001 From: afwillia Date: Wed, 3 Jul 2024 10:17:49 -0700 Subject: [PATCH 6/7] Update submit parameters to config check --- R/read_dca_config.R | 24 +++++++++++++++++++++--- functions/read_dca_config.R | 24 +++++++++++++++++++++--- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/R/read_dca_config.R b/R/read_dca_config.R index 8bfc1278..b21aa0ea 100644 --- a/R/read_dca_config.R +++ b/R/read_dca_config.R @@ -88,7 +88,7 @@ read_dca_config <- function(config) { mv_props_conf <- names(conf$schematic$model_validate) name_check(names(mv_props_req), mv_props_conf) - if (!"cross_manifest_validation" %in% mv_props_confg) { + if (!"cross_manifest_validation" %in% mv_props_conf) { conf$schematic$model_validate$cross_manifest_validation <- FALSE } @@ -96,11 +96,29 @@ read_dca_config <- function(config) { # WIP, confirm required and move others to ops with defaults ms_props_req <- list( "table_manipulation" = "replace", - "manifest_record_type" = "file_only", + "manifest_record_type" = "file_only" + ) + ms_props_ops <- list( + "table_column_names" = "class_label", + "annotation_keys" = "class_label", + "file_annotations_upload" = TRUE, "hide_blanks" = FALSE ) - ms_props_ops <- list() ms_props_conf <- names(conf$schematic$model_submit) + name_check(names(ms_props_req), ms_props_conf) + + if (!"table_column_names" %in% ms_props_conf) { + conf$schematic$model_submit$table_column_names <- "class_label" + } + if (!"annotation_keys" %in% ms_props_conf) { + conf$schematic$model_submit$annotation_keys <- "class_label" + } + if (!"file_annotations_upload" %in% ms_props_conf) { + conf$schematic$model_submit$file_annotations_upload <- TRUE + } + if (!"hide_blanks" %in% ms_props_conf) { + conf$schematic$model_submit$hide_blanks <- FALSE + } conf diff --git a/functions/read_dca_config.R b/functions/read_dca_config.R index 8bfc1278..b21aa0ea 100644 --- a/functions/read_dca_config.R +++ b/functions/read_dca_config.R @@ -88,7 +88,7 @@ read_dca_config <- function(config) { mv_props_conf <- names(conf$schematic$model_validate) name_check(names(mv_props_req), mv_props_conf) - if (!"cross_manifest_validation" %in% mv_props_confg) { + if (!"cross_manifest_validation" %in% mv_props_conf) { conf$schematic$model_validate$cross_manifest_validation <- FALSE } @@ -96,11 +96,29 @@ read_dca_config <- function(config) { # WIP, confirm required and move others to ops with defaults ms_props_req <- list( "table_manipulation" = "replace", - "manifest_record_type" = "file_only", + "manifest_record_type" = "file_only" + ) + ms_props_ops <- list( + "table_column_names" = "class_label", + "annotation_keys" = "class_label", + "file_annotations_upload" = TRUE, "hide_blanks" = FALSE ) - ms_props_ops <- list() ms_props_conf <- names(conf$schematic$model_submit) + name_check(names(ms_props_req), ms_props_conf) + + if (!"table_column_names" %in% ms_props_conf) { + conf$schematic$model_submit$table_column_names <- "class_label" + } + if (!"annotation_keys" %in% ms_props_conf) { + conf$schematic$model_submit$annotation_keys <- "class_label" + } + if (!"file_annotations_upload" %in% ms_props_conf) { + conf$schematic$model_submit$file_annotations_upload <- TRUE + } + if (!"hide_blanks" %in% ms_props_conf) { + conf$schematic$model_submit$hide_blanks <- FALSE + } conf From 9f6365e6ffb7c2803a5c6505baf026d621fdb565 Mon Sep 17 00:00:00 2001 From: afwillia Date: Wed, 3 Jul 2024 10:57:51 -0700 Subject: [PATCH 7/7] Add dcc options to config check --- R/read_dca_config.R | 23 +++++++++++++++++++++++ functions/read_dca_config.R | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/R/read_dca_config.R b/R/read_dca_config.R index b21aa0ea..747959ef 100644 --- a/R/read_dca_config.R +++ b/R/read_dca_config.R @@ -42,6 +42,29 @@ read_dca_config <- function(config) { conf$dca$sidebar_col <- "#191919" } + dcc_props_req <- list( + "name" = list(), + "synapse_asset_view" = list(), + "data_model_url" = list(), + "template_menu_config_file" = list() + ) + dcc_props_ops <- list( + "data_model_info" = NA_character_, + "logo_location" = "https://raw.githubusercontent.com/Sage-Bionetworks/data_curator_config/prod/demo/sage_logo_mark_only.png", + "logo_link" = "https://synapse.org", + "dcc_help_link" = NA_character_, + "portal_help_link" = NA_character_ + ) + dcc_props_conf <- names(conf$dcc) + name_check(names(dcc_props_req), dcc_props_conf) + + if (!"logo_location" %in% dcc_props_conf) { + conf$dcc$logo_location <- dcc_props_ops$logo_location + } + if (!"logo_link" %in% dcc_props_conf) { + conf$dcc$logo_link <- dcc_props_ops$logo_link + } + # required elements should not have a default. Should error if not provided. # WIP, confirm required and move others to ops with defaults schematic_props_req <- list( diff --git a/functions/read_dca_config.R b/functions/read_dca_config.R index b21aa0ea..747959ef 100644 --- a/functions/read_dca_config.R +++ b/functions/read_dca_config.R @@ -42,6 +42,29 @@ read_dca_config <- function(config) { conf$dca$sidebar_col <- "#191919" } + dcc_props_req <- list( + "name" = list(), + "synapse_asset_view" = list(), + "data_model_url" = list(), + "template_menu_config_file" = list() + ) + dcc_props_ops <- list( + "data_model_info" = NA_character_, + "logo_location" = "https://raw.githubusercontent.com/Sage-Bionetworks/data_curator_config/prod/demo/sage_logo_mark_only.png", + "logo_link" = "https://synapse.org", + "dcc_help_link" = NA_character_, + "portal_help_link" = NA_character_ + ) + dcc_props_conf <- names(conf$dcc) + name_check(names(dcc_props_req), dcc_props_conf) + + if (!"logo_location" %in% dcc_props_conf) { + conf$dcc$logo_location <- dcc_props_ops$logo_location + } + if (!"logo_link" %in% dcc_props_conf) { + conf$dcc$logo_link <- dcc_props_ops$logo_link + } + # required elements should not have a default. Should error if not provided. # WIP, confirm required and move others to ops with defaults schematic_props_req <- list(