Skip to content

Commit

Permalink
Merge pull request #703 from pharmaR/jt-700-noncredential_deploy
Browse files Browse the repository at this point in the history
Allow a non-credentialed deployment
  • Loading branch information
AARON-CLARK authored Jan 12, 2024
2 parents 12e418d + b6fb751 commit d902f3c
Show file tree
Hide file tree
Showing 23 changed files with 227 additions and 124 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: riskassessment
Title: A web app designed to interface with the `riskmetric` package
Version: 3.0.0.9009
Version: 3.0.0.9010
Authors@R: c(
person("Aaron", "Clark", role = c("aut", "cre"), email = "aaron.clark@biogen.com"),
person("Robert", "Krajcik", role = "aut", email = "robert.krajcik@biogen.com"),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Fixed bug where HTML reports displayed a darker green in the cards' meters
* Only run configuration checkers when configuring the database
* Added dependencies/reverse dependencies card hyperlink (#597)
* Added non-shinymanager deployment option (#700)

# riskassessment 3.0.0

Expand Down
12 changes: 9 additions & 3 deletions R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ app_server <- function(input, output, session) {
res_auth[["admin"]] <- !isTRUE(golem::get_golem_options('nonadmin'))
res_auth[["user"]] <- "test_user"
res_auth[["role"]] <- ifelse(!isTRUE(golem::get_golem_options('nonadmin')), "admin", "reviewer")
} else if (isFALSE(get_db_config("use_shinymanager"))) {
res_auth <- reactiveValues()
res_auth[["admin"]] <- FALSE
res_auth[["user"]] <- session$user %||% "anonymous"
res_auth[["role"]] <- intersect(unlist(session$groups, use.names = FALSE), dbSelect("select user_role from roles")[[1]]) %||% "default"
} else {
# check_credentials directly on sqlite db
res_auth <- shinymanager::secure_server(
Expand All @@ -64,7 +69,7 @@ app_server <- function(input, output, session) {
})

observeEvent(res_auth$user, {
req(res_auth$admin == TRUE | "weight_adjust" %in% credential_config$privileges[[res_auth$role]])
req(res_auth$admin == TRUE || any(c("admin", "weight_adjust") %in% unlist(credential_config$privileges[res_auth$role])))

appendTab("apptabs",
tabPanel(
Expand All @@ -86,12 +91,13 @@ app_server <- function(input, output, session) {
admin_ui
}
),
if (res_auth$admin)
if (res_auth$admin == TRUE || "admin" %in% unlist(credential_config$privileges[res_auth$role]))
tabPanel(
id = "privilege_id",
title = "Roles & Privileges",
mod_user_roles_ui("userRoles")
),
if ("weight_adjust" %in% unlist(credential_config$privileges[res_auth$role]))
tabPanel(
id = "reweight_id",
title = "Assessment Reweighting",
Expand All @@ -105,7 +111,7 @@ app_server <- function(input, output, session) {
observeEvent(credential_config$privileges, {
req(user$role)

if ("weight_adjust" %in% credential_config$privileges[[user$role]])
if ("weight_adjust" %in% unlist(credential_config$privileges[user$role]))
showTab("credentials", "Assessment Reweighting")
else
hideTab("credentials", "Assessment Reweighting")
Expand Down
8 changes: 4 additions & 4 deletions R/mod_addComment.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ addCommentUI <- function(id) {
#'
addCommentServer <- function(id, metric_abrv, user, credentials, pkg_name) {
if (missing(credentials))
credentials <- get_db_config("credentials")
credentials <- get_credential_config()

moduleServer(id, function(input, output, session) {

Expand All @@ -50,22 +50,22 @@ addCommentServer <- function(id, metric_abrv, user, credentials, pkg_name) {
width = "100%",
rows = 4,
placeholder = glue::glue(
"Commenting as user: {user$name}, role: {user$role}"
"Commenting as user: {user$name}, role: {paste(user$role, collapse = ', ')}"
)
)
})

observeEvent(input$submit_comment, {
req(input$add_comment)
req("general_comment" %in% credentials$privileges[[user$role]])
req("general_comment" %in% unlist(credentials$privileges[user$role], use.name = FALSE))

comment <- trimws(input$add_comment)

if (comment != "") {

dbUpdate(
"INSERT INTO comments values({pkg_name()}, {user$name},
{user$role}, {comment}, {metric_abrv},
{paste(user$role, collapse = ', ')}, {comment}, {metric_abrv},
{getTimeStamp()})"
)

Expand Down
2 changes: 1 addition & 1 deletion R/mod_code_explorer.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ mod_code_explorer_server <- function(id, selected_pkg, pkgdir = reactiveVal(), c
),
br(), br(),
div(id = ns("comments_for_fe"), fluidRow(
if ("general_comment" %in% credentials$privileges[[user$role]]) addCommentUI(id = ns("add_comment")),
if ("general_comment" %in% unlist(credentials$privileges[user$role], use.name = FALSE)) addCommentUI(id = ns("add_comment")),
viewCommentsUI(id = ns("view_comments"))))
)
}
Expand Down
4 changes: 2 additions & 2 deletions R/mod_communityMetrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ communityMetricsUI <- function(id) {
#'
communityMetricsServer <- function(id, selected_pkg, community_metrics, user, credentials) {
if (missing(credentials))
credentials <- get_db_config("credentials")
credentials <- get_credential_config()

moduleServer(id, function(input, output, session) {

Expand All @@ -51,7 +51,7 @@ communityMetricsServer <- function(id, selected_pkg, community_metrics, user, cr
plotly::plotlyOutput(NS(id, "downloads_plot"), height = "500px")))),
br(), br(),
div(id = "comments_for_cum", fluidRow(
if ("general_comment" %in% credentials$privileges[[user$role]]) addCommentUI(id = session$ns("add_comment")),
if ("general_comment" %in% unlist(credentials$privileges[user$role], use.name = FALSE)) addCommentUI(id = session$ns("add_comment")),
viewCommentsUI(id = session$ns("view_comments"))))
)
}
Expand Down
26 changes: 13 additions & 13 deletions R/mod_decision_automation.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ mod_decision_automation_ui_2 <- function(id){
#' @importFrom sortable sortable_js sortable_options sortable_js_capture_input
mod_decision_automation_server <- function(id, user, credentials){
if (missing(credentials))
credentials <- get_db_config("credentials")
credentials <- get_credential_config()
moduleServer( id, function(input, output, session){
ns <- session$ns

Expand Down Expand Up @@ -428,7 +428,7 @@ mod_decision_automation_server <- function(id, user, credentials){
#### Outputs ####
purrr::walk(c("auto_dropdown", "auto_dropdown2"), ~
observeEvent(input[[.x]], {
req("auto_decision_adjust" %in% credentials$privileges[[user$role]])
req("auto_decision_adjust" %in% unlist(credentials$privileges[user$role], use.name = FALSE))

showModal(modalDialog(
size = "l",
Expand Down Expand Up @@ -515,7 +515,7 @@ mod_decision_automation_server <- function(id, user, credentials){
})

output$auto_classify <- renderUI({
if ("auto_decision_adjust" %in% credentials$privileges[[user$role]]) {
if ("auto_decision_adjust" %in% unlist(credentials$privileges[user$role], use.name = FALSE)) {
tagList(
br(),br(),
hr(),
Expand All @@ -540,7 +540,7 @@ mod_decision_automation_server <- function(id, user, credentials){
})

output$decision_rule_div <- renderUI({
req("auto_decision_adjust" %in% credentials$privileges[[user$role]])
req("auto_decision_adjust" %in% unlist(credentials$privileges[user$role], use.name = FALSE))
tagList(
div(
style = "display: flex",
Expand Down Expand Up @@ -625,7 +625,7 @@ mod_decision_automation_server <- function(id, user, credentials){

output$auto_settings <-
renderUI({
req("auto_decision_adjust" %in% credentials$privileges[[user$role]])
req("auto_decision_adjust" %in% unlist(credentials$privileges[user$role], use.name = FALSE))

div(
style = "float: right;",
Expand All @@ -637,7 +637,7 @@ mod_decision_automation_server <- function(id, user, credentials){

output$auto_settings2 <-
renderUI({
req("auto_decision_adjust" %in% credentials$privileges[[user$role]])
req("auto_decision_adjust" %in% unlist(credentials$privileges[user$role], use.name = FALSE))

div(
style = "float: right;",
Expand Down Expand Up @@ -721,7 +721,7 @@ mod_decision_automation_server <- function(id, user, credentials){
})

observeEvent(input$submit_auto, {
req("auto_decision_adjust" %in% credentials$privileges[[user$role]])
req("auto_decision_adjust" %in% unlist(credentials$privileges[user$role], use.name = FALSE))

showModal(modalDialog(
size = "l",
Expand Down Expand Up @@ -752,7 +752,7 @@ mod_decision_automation_server <- function(id, user, credentials){
})

observeEvent(input$submit_color, {
req("auto_decision_adjust" %in% credentials$privileges[[user$role]])
req("auto_decision_adjust" %in% unlist(credentials$privileges[user$role], use.name = FALSE))

showModal(modalDialog(
size = "l",
Expand Down Expand Up @@ -784,7 +784,7 @@ mod_decision_automation_server <- function(id, user, credentials){
})

observeEvent(input$confirm_submit_auto, {
req("auto_decision_adjust" %in% credentials$privileges[[user$role]])
req("auto_decision_adjust" %in% unlist(credentials$privileges[user$role], use.name = FALSE))
req(!disable_auto_submit())

out_lst <- purrr::compact(reactiveValuesToList(auto_decision))
Expand All @@ -796,7 +796,7 @@ mod_decision_automation_server <- function(id, user, credentials){
if (rlang::is_empty(rules_updates)) {
risk_rule_update(rules_updates)
dbUpdate("DELETE FROM rules")
loggit::loggit("INFO", glue::glue("Decision automation rules have been disabled by {user$name} ({user$role})."))
loggit::loggit("INFO", glue::glue("Decision automation rules have been disabled by {user$name} ({paste(user$role, collapse = ', ')})."))
} else {
if (!is.null(rule_lst[["rule_else"]][["decision"]]))
rules_updates[["rule_else"]] <- rule_lst[["rule_else"]]
Expand All @@ -812,7 +812,7 @@ mod_decision_automation_server <- function(id, user, credentials){
glue::glue_collapse(", ")
dbUpdate("DELETE FROM rules")
dbUpdate(glue::glue("INSERT INTO rules (rule_type, metric_id, condition, decision_id) VALUES {rule_out};"))
loggit::loggit("INFO", glue::glue("Decision automation rules were updated/implemented by {user$name} ({user$role})."))
loggit::loggit("INFO", glue::glue("Decision automation rules were updated/implemented by {user$name} ({paste(user$role, collapse = ', ')})."))
}

removeModal()
Expand All @@ -829,7 +829,7 @@ mod_decision_automation_server <- function(id, user, credentials){


observeEvent(input$confirm_submit_col, {
req("auto_decision_adjust" %in% credentials$privileges[[user$role]])
req("auto_decision_adjust" %in% unlist(credentials$privileges[user$role], use.name = FALSE))

selected_colors <-
decision_lst %>%
Expand All @@ -839,7 +839,7 @@ mod_decision_automation_server <- function(id, user, credentials){
dbUpdate("UPDATE decision_categories SET color = {.x} WHERE decision = {.y}")
shinyjs::runjs(glue::glue("document.documentElement.style.setProperty('--{risk_lbl(.y, type = 'attribute')}-color', '{.x}');"))
})
loggit::loggit("INFO", glue::glue("The decision category display colors were modified by {user$name} ({user$role})"))
loggit::loggit("INFO", glue::glue("The decision category display colors were modified by {user$name} ({paste(user$role, collapse = ', ')})"))
color_current(selected_colors)

removeModal()
Expand Down
2 changes: 1 addition & 1 deletion R/mod_downloadHandler.R
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ mod_downloadHandler_server <- function(id, pkgs, user, metric_weights){
app_version = golem::get_golem_options('app_version'),
metric_weights = metric_weights(),
user_name = user$name,
user_role = user$role,
user_role = paste(user$role, collapse = ', '),
overall_comments = overall_comments,
pkg_summary = pkg_summary,
mm_comments = mm_comments,
Expand Down
4 changes: 2 additions & 2 deletions R/mod_introJS.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ introJSUI <- function(id) {
#' @keywords internal
introJSServer <- function(id, text, user, credentials) {
if (missing(credentials))
credentials <- get_db_config("credentials")
credentials <- get_credential_config()
moduleServer(id, function(input, output, session) {

steps <- reactive({
if(user$admin || "weight_adjust" %in% credentials$privileges[[user$role]]) {
if(user$admin || "weight_adjust" %in% unlist(credentials$privileges[user$role], use.name = FALSE)) {
apptab_steps <- bind_rows(apptab_admn, apptab_steps)
}

Expand Down
4 changes: 2 additions & 2 deletions R/mod_maintenanceMetrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ maintenanceMetricsUI <- function(id) {
#'
maintenanceMetricsServer <- function(id, selected_pkg, maint_metrics, user, credentials, parent) {
if (missing(credentials))
credentials <- get_db_config("credentials")
credentials <- get_credential_config()

moduleServer(id, function(input, output, session) {
ns <- NS(id)
Expand All @@ -39,7 +39,7 @@ maintenanceMetricsServer <- function(id, selected_pkg, maint_metrics, user, cred
metricGridUI(NS(id, 'metricGrid')),
br(), br(),
fluidRow(div(id = "comments_for_mm",
if ("general_comment" %in% credentials$privileges[[user$role]]) addCommentUI(NS(id, 'add_comment')),
if ("general_comment" %in% unlist(credentials$privileges[user$role], use.name = FALSE)) addCommentUI(NS(id, 'add_comment')),
viewCommentsUI(NS(id, 'view_comments')))
)
)
Expand Down
2 changes: 1 addition & 1 deletion R/mod_pkg_explorer.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ mod_pkg_explorer_server <- function(id, selected_pkg,
),
br(), br(),
div(id = ns("comments_for_se"), fluidRow(
if ("general_comment" %in% credentials$privileges[[user$role]]) addCommentUI(id = ns("add_comment")),
if ("general_comment" %in% unlist(credentials$privileges[user$role], use.name = FALSE)) addCommentUI(id = ns("add_comment")),
viewCommentsUI(id = ns("view_comments")))),
id = id
)
Expand Down
10 changes: 5 additions & 5 deletions R/mod_reportPreview.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ reportPreviewServer <- function(id, selected_pkg, maint_metrics, com_metrics,
downloads_plot_data, user, credentials, app_version,
metric_weights) {
if (missing(credentials))
credentials <- get_db_config("credentials")
credentials <- get_credential_config()

moduleServer(id, function(input, output, session) {

Expand Down Expand Up @@ -82,7 +82,7 @@ reportPreviewServer <- function(id, selected_pkg, maint_metrics, com_metrics,

br(), br(),

if ("overall_comment" %in% credentials$privileges[[user$role]])
if ("overall_comment" %in% unlist(credentials$privileges[user$role], use.name = FALSE))
div(id = NS(id, "pkg-summary-grp"),
# Compose pkg summary - either disabled, enabled, or pre-populated
uiOutput(NS(id, "pkg_summary_ui")),
Expand Down Expand Up @@ -119,7 +119,7 @@ reportPreviewServer <- function(id, selected_pkg, maint_metrics, com_metrics,
HTML("<span class='h2 txtasis'>R Package Risk Assessment </span><br>"),
HTML(glue::glue("<span class='h4 txtasis'>Report for Package: {selected_pkg$name()}</span><br>")),
if("Report Author" %in% report_includes())
HTML(glue::glue("<span class='h4 txtasis'>Author (Role): {user$name} ({user$role})</span><br>")),
HTML(glue::glue("<span class='h4 txtasis'>Author (Role): {user$name} ({paste(user$role, collapse = ', ')})</span><br>")),
if("Report Date" %in% report_includes())
HTML(glue::glue("<span class='h4 txtasis'>Report Date: {format(get_time(), '%B %d, %Y')}</span><br>")),

Expand Down Expand Up @@ -289,7 +289,7 @@ reportPreviewServer <- function(id, selected_pkg, maint_metrics, com_metrics,
} else { # first summary!
dbUpdate(
"INSERT INTO comments
VALUES ({selected_pkg$name()}, {user$name}, {user$role},
VALUES ({selected_pkg$name()}, {user$name}, {paste(user$role, collapse = ', ')},
{current_summary}, 's', {getTimeStamp()})")
showModal(modalDialog(
title = h2("Summary Submitted"),
Expand All @@ -315,7 +315,7 @@ reportPreviewServer <- function(id, selected_pkg, maint_metrics, com_metrics,
SET comment = {input$pkg_summary}, added_on = {getTimeStamp()}
WHERE id = {selected_pkg$name()} AND
user_name = {user$name} AND
user_role = {user$role} AND
user_role = {paste(user$role, collapse = ', ')} AND
comment_type = 's'"
)

Expand Down
Loading

0 comments on commit d902f3c

Please sign in to comment.