Skip to content

Commit

Permalink
Lagt til mulighet å sende mapping mellom resh og shusnavn inn som inp…
Browse files Browse the repository at this point in the history
…utparameter til userAttribute og navbarWidget2. Tillater visning av sykehusnavn i nedtrekksmeny for valg av avdeling og rolle.
  • Loading branch information
kevinthon committed Jan 15, 2025
1 parent 2e27bf2 commit 7f08706
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
8 changes: 7 additions & 1 deletion R/moduleNavbarWidget.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,22 @@ navbarWidgetServer <- function(id, orgName,


#' @rdname navbarWidget
#' @param map_orgname A data.frame containing two columns:
#' \describe{
#' \item{UnitId}{unit ids}
#' \item{orgname}{corresponding organization names}
#' }
#' @export
navbarWidgetServer2 <- function(
id,
orgName,
map_orgname = NULL,
caller = environmentName(topenv(parent.frame()))
) {

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

user <- userAttribute()
user <- userAttribute(map_orgname = map_orgname)
stopifnot(length(user$name) > 0)

# Initial privileges and affiliation will be first in list
Expand Down
47 changes: 14 additions & 33 deletions R/userAttribute.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ userInfo <- function(
}
}

switch(entity,
switch(
entity,
user = user,
groups = groups,
resh_id = resh_id,
Expand All @@ -180,6 +181,11 @@ userInfo <- function(
#' SHINYPROXY_USERGROUPS that corresponds to the apps a given user can access.
#' @param unit Integer providing the look-up unit id. Default value is NULL in
#' which case all privileges for \code{group} are returned.
#' @param map_orgname A data.frame containing two columns:
#' \describe{
#' \item{UnitId}{unit ids}
#' \item{orgname}{corresponding organization names}
#' }
#'
#' @return Invisibly a list of user metadata and privileges:
#' \describe{
Expand All @@ -194,7 +200,8 @@ userInfo <- function(
#' }
#' @export

userAttribute <- function(unit = NULL) {
userAttribute <- function(unit = NULL,
map_orgname = NULL) {

if (Sys.getenv("FALK_EXTENDED_USER_RIGHTS") == "" ||
Sys.getenv("FALK_APP_ID") == "") {
Expand Down Expand Up @@ -222,29 +229,11 @@ userAttribute <- function(unit = NULL) {
orgs <- tilganger$U
roles <- tilganger$R

# nolint start
# if (Sys.getenv("http_proxy") == "") {
# f <- file.path(Sys.getenv("R_RAP_CONFIG_PATH"), "rapbaseConfig.yml")
# if (file.exists(f)) {
# proxy <- yaml::yaml.load_file(f)$network$proxy$http
# Sys.setenv(http_proxy = proxy)
# Sys.setenv(https_proxy = proxy)
# }
# }
# proxy <- file.path(Sys.getenv("R_RAP_CONFIG_PATH"), "rapbaseConfig.yml")$
#tilgangstre_url <- Sys.getenv("ACCESSTREE_URL")
#httr::set_config(httr::config(ssl_verifypeer = 0L))
#tilgangstre <- httr::GET(tilgangstre_url)
#tilgangstre <- httr::content(tilgangstre, as="text")
# HACK I PÅVENTE AV PROXYINNSTILLINGER
tilgangstre <- "{\"AccessUnits\":[{\"UnitId\":0,\"ParentUnitId\":null,\"HasDatabase\":true,\"ExternalId\":\"0\",\"HealthUnitId\":null,\"Title\":\"Nasjonal instans\",\"TitleWithPath\":\"Nasjonal instans\",\"ValidFrom\":null,\"ValidTo\":null,\"ExtraData\":null},{\"UnitId\":100083,\"ParentUnitId\":0,\"HasDatabase\":true,\"ExternalId\":\"100083\",\"HealthUnitId\":null,\"Title\":\"Helse Stavanger HF\",\"TitleWithPath\":\"Helse Stavanger HF\",\"ValidFrom\":null,\"ValidTo\":null,\"ExtraData\":null},{\"UnitId\":102212,\"ParentUnitId\":null,\"HasDatabase\":true,\"ExternalId\":\"102212\",\"HealthUnitId\":null,\"Title\":\"Helse Midt-Norge IT\",\"TitleWithPath\":\"Helse Midt-Norge IT\",\"ValidFrom\":null,\"ValidTo\":null,\"ExtraData\":null},{\"UnitId\":104919,\"ParentUnitId\":null,\"HasDatabase\":true,\"ExternalId\":\"104919\",\"HealthUnitId\":null,\"Title\":\"Helse Vest IKT\",\"TitleWithPath\":\"Helse Vest IKT\",\"ValidFrom\":null,\"ValidTo\":null,\"ExtraData\":null},{\"UnitId\":105403,\"ParentUnitId\":100083,\"HasDatabase\":false,\"ExternalId\":\"105403\",\"HealthUnitId\":null,\"Title\":\"Ortopedisk avdeling\",\"TitleWithPath\":\"Helse Stavanger HF/Ortopedisk avdeling\",\"ValidFrom\":null,\"ValidTo\":null,\"ExtraData\":null}]}"
# tilgangstreyaml <- yaml::read_yaml(
# paste0(Sys.getenv("R_RAP_CONFIG_PATH"), "/accesstree.yaml"))
# tilgangstrejson <- tilgangstreyaml$data$accesstree.json
# tilgangstre <- jsonlite::fromJSON(tilgangstrejson, flatten = FALSE)[[1]]
# nolint end
tilgangstre <- jsonlite::fromJSON(tilgangstre, flatten = FALSE)[[1]]
orgNames <- tilgangstre$TitleWithPath[match(orgs, tilgangstre$UnitId)]
if (!is.null(map_orgname)) {
orgNames <- map_orgname$orgname[match(orgs, map_orgname$UnitId)]

Check warning on line 233 in R/userAttribute.R

View check run for this annotation

Codecov / codecov/patch

R/userAttribute.R#L233

Added line #L233 was not covered by tests
} else {
orgNames <- rep("Ukjent", length(units))
}

name <- Sys.getenv("SHINYPROXY_USERNAME")
fullName <- parse(text = paste0(
Expand All @@ -255,14 +244,6 @@ userAttribute <- function(unit = NULL) {
phone <- Sys.getenv("FALK_USER_PHONE")
email <- Sys.getenv("FALK_USER_EMAIL")

# Look up org, role and unit name
# nolint start
# orgNames <- vector()
# for (i in seq_len(length(units))) {
# orgNames[i] <- rapbase::unitAttribute(tilganger$U[i], "titlewithpath")
# }
# nolint end

list(
name = rep(name, length(units)),
fullName = rep(fullName, length(units)),
Expand Down
7 changes: 7 additions & 0 deletions man/navbarWidget.Rd

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

8 changes: 7 additions & 1 deletion man/userAttribute.Rd

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

0 comments on commit 7f08706

Please sign in to comment.