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

feat: updated user details table #1010

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
53 changes: 4 additions & 49 deletions components/board.user/R/userprofile_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,67 +20,22 @@ UserProfileBoard <- function(id, auth, nav_count) {
))
})

observeEvent(auth$logged, {
if (!auth$logged) {
return()
}

removeModal()

session$sendCustomMessage(
"get-subs",
list(
ns = ns(NULL)
)
)
})

output$plan <- renderUI({
plan_class <- "info"
if (auth$level == "premium") {
plan_class <- "success"
}
cl <- sprintf("badge badge-%s", plan_class)
p(
span("Subscription level", style = "color:grey;"),
span(class = cl, tools::toTitleCase(auth$level))
span(paste0("Subscription level: ", tools::toTitleCase(auth$level)))
)
})

observeEvent(input$manage, {
dbg("[UserBoard] !!! auth$email = ", auth$email)
dbg("[UserBoard] !!! auth$stripe_id = ", auth$stripe_id)
dbg("[UserBoard] !!! auth$href = ", auth$href)

response <- httr::POST(
"https://api.stripe.com/v1/billing_portal/sessions",
body = list(
customer = auth$stripe_id,
return_url = auth$href
),
httr::authenticate(
Sys.getenv("OMICS_STRIPE_KEY"),
""
),
encode = "form"
)

httr::warn_for_status(response)
content <- httr::content(response)
session$sendCustomMessage("manage-sub", content$url)
})

output$userdata <- renderTable(
{
dbg("[UserBoard::userdata] renderDataTable")
cl <- "badge badge-info"
browser()
values <- c(
Name = auth$username,
Email = auth$email,
Plan = auth$level,
Start = "",
End = "",
Status = "active"
End = auth$expiry,
Datasets = auth$options$MAX_DATASETS
)
values[which(values == "")] <- "(not set)"
data.frame(" " = names(values), " " = values, check.names = FALSE)
Expand Down
1 change: 0 additions & 1 deletion components/board.user/R/userprofile_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ UserProfileUI <- function(id) {
shiny::h4("Subscription"),
uiOutput(ns("plan")),
shiny::tableOutput(ns("userdata"))
),
bslib::layout_columns(
col_widths = 12,
PlotModuleUI(
Expand Down
12 changes: 12 additions & 0 deletions components/modules/AuthenticationModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,7 @@ LoginCodeAuthenticationModule <- function(id,
email = NA,
level = "",
limit = "",
expiry = "",
options = opt, ## global
user_dir = PGX.DIR ## global
)
Expand Down Expand Up @@ -897,6 +898,7 @@ LoginCodeAuthenticationModule <- function(id,
USER$password <- NA
USER$level <- ""
USER$limit <- ""
USER$expiry <- ""

email_sent <<- FALSE
login_code <<- NULL
Expand Down Expand Up @@ -957,9 +959,14 @@ LoginCodeAuthenticationModule <- function(id,
if (user_in_db) {
dbg("[LoginCodeAuthenticationModule] using sqlite DB OPTIONS")
USER$options <- read_user_options_db(user_email, user_database)
USER$username <- read_user_field_db(USER$email, user_database, "firstname")
USER$level <- read_user_field_db(USER$email, user_database, "level")
USER$expiry <- read_user_field_db(USER$email, user_database, "expiry")
} else {
dbg("[LoginCodeAuthenticationModule] using user OPTIONS")
USER$options <- read_user_options(user_dir)
USER$level <- "free"
USER$expiry <- "unlimited"
}
session$sendCustomMessage("set-user", list(user = user_email))

Expand Down Expand Up @@ -1173,9 +1180,14 @@ LoginCodeAuthenticationModule <- function(id,
if (user_in_db) {
dbg("[LoginCodeAuthenticationModule] using sqlite DB OPTIONS")
USER$options <- read_user_options_db(USER$email, user_database)
USER$username <- read_user_field_db(USER$email, user_database, "firstname")
USER$level <- read_user_field_db(USER$email, user_database, "level")
USER$expiry <- read_user_field_db(USER$email, user_database, "expiry")
} else {
dbg("[LoginCodeAuthenticationModule] using user OPTIONS")
USER$options <- read_user_options(USER$user_dir)
USER$level <- "free"
USER$expiry <- "unlimited"
}
session$sendCustomMessage("set-user", list(user = USER$email))
entered_code("") ## important for next user
Expand Down
14 changes: 14 additions & 0 deletions components/modules/AuthenticationModule_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ read_user_options_db <- function(email, user_database = NULL) {
new_opt
}

read_user_field_db <- function(email, user_database, field) {
connection <- connect_db(user_database)
user_config <- query_by_email(email, connection)
disconnect_db(connection)
if (!is.null(user_config)) {
## restrict user options only to these options.
ALLOWED_USER_OPTS <- field
dbg("[read_user_field] 1 : user: ", email, " ; field: ", field)
user_config <- user_config[which(names(user_config) %in% ALLOWED_USER_OPTS)]
}
if (nrow(user_config) == 0) return("")
user_config |> as.character()
}

upgrade.dialog <- function(ns, current.plan) {
btn_basic <- "Go Basic!"
btn_starter <- "Get Starter!"
Expand Down
Loading