Skip to content

Commit

Permalink
Merge pull request #138 from Rapporteket/poc-without-PoC
Browse files Browse the repository at this point in the history
Extend rapbase towards standalone container apps at Rapporteket
  • Loading branch information
areedv authored Feb 27, 2023
2 parents 64b395f + 9bbc085 commit 48039ad
Show file tree
Hide file tree
Showing 49 changed files with 2,479 additions and 698 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@
^appveyor\.yml$
^\.lintr$
^data-raw$
^doc$
^Meta$
^docker-compose.yml$
^.devcontainer$
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- {os: macOS-latest, r: 'release'}
- {os: ubuntu-20.04, r: 'release'}
- {os: ubuntu-20.04, r: 'devel'}
- {os: ubuntu-18.04, r: 'oldrel'}
- {os: ubuntu-20.04, r: 'oldrel'}
- {os: ubuntu-20.04, r: '3.6'}

env:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
.RData
vignettes/*.pdf
docs/
/doc/
/Meta/
11 changes: 7 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rapbase
Type: Package
Title: Base Functions and Resources for Rapporteket
Version: 1.23.1.9000
Version: 1.24.0
Authors@R: c(
person(given = "Are",
family = "Edvardsen",
Expand All @@ -24,6 +24,7 @@ LazyData: true
Depends:
R (>= 3.5.0)
Imports:
blob,
bookdown,
DBI,
digest,
Expand All @@ -41,14 +42,16 @@ Imports:
sendmailR,
shiny,
shinyalert,
sship (>= 0.8.0),
sship (>= 0.9.0),
utils,
yaml
RoxygenNote: 7.2.1
RoxygenNote: 7.2.3
URL: https://github.com/Rapporteket/rapbase
BugReports: https://github.com/Rapporteket/rapbase/issues
Suggests:
httptest,
lifecycle,
rvest,
testthat
testthat,
withr
VignetteBuilder: knitr
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export(autoReportInput)
export(autoReportOrgInput)
export(autoReportOrgServer)
export(autoReportServer)
export(autoReportServer2)
export(autoReportUI)
export(cleanStagingData)
export(createAutoReport)
Expand Down Expand Up @@ -57,6 +58,7 @@ export(mtimeStagingData)
export(navbarWidgetApp)
export(navbarWidgetInput)
export(navbarWidgetServer)
export(navbarWidgetServer2)
export(noOptOutOk)
export(orgList2df)
export(rapCloseDbConnection)
Expand All @@ -78,7 +80,9 @@ export(statsGuideUI)
export(statsInput)
export(statsServer)
export(statsUI)
export(unitAttribute)
export(upgradeAutoReportData)
export(userAttribute)
export(userInfo)
export(writeAutoReportData)
importFrom(magrittr,"%>%")
Expand Down
16 changes: 14 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# rapbase 1.24.0

In summary, registries at Rapporteket may now run as standalone container apps. Thus, shiny-server is no longer a requirement for app deployment. Below is a summary of what has been done.

* Extended handling of user attributes when behind an app proxy (spring boot/shinyproxy)
* Added a database backend for staging data
* Per app (registry) encryption of staging data (regardless of file or database backend)
* Added a vignette with a short description of staging data server side set-up

## Breaking changes
By introducing encryption, staging data will not work across this and previous versions. All existing staging data should therefore be removed when upgrading to this version of rapbase (or downgrading from this to any previous version). To remove all staging data delete all related files and directories. If staging data uses a database backend, the database itself should be dropped. There should be no need for further actions as both files and database will be recreated upon the next request for storing of staging data.

# rapbase 1.23.1

* Fixed Fixed bug in log sanitizer function ([#130](https://github.com/Rapporteket/rapbase/pull/130))
Expand Down Expand Up @@ -28,7 +40,7 @@

* Fix short-term error in function finding next run date in auto reports
* As result of the above a new field "startDate" was added to auto report data with functions for upgrading existing data missing this field ([#99](https://github.com/Rapporteket/rapbase/pull/99)) and the start date is checked before reports are run ([#100](https://github.com/Rapporteket/rapbase/pull/100))
* R package sship now installed from Cran rather than GitHUb ([#101](https://github.com/Rapporteket/rapbase/pull/101))
* R package sship now installed from Cran rather than GitHub ([#101](https://github.com/Rapporteket/rapbase/pull/101))

# rapbase 1.20.1

Expand All @@ -44,7 +56,7 @@

# rapbase 1.19.3

* Added T1 fontencoding to default LaTeX template for proper printing of symbols (_e.g._ > and <) in pdfs ([#94](https://github.com/Rapporteket/rapbase/pull/94))
* Added T1 font encoding to default LaTeX template for proper printing of symbols (_e.g._ > and <) in pdfs ([#94](https://github.com/Rapporteket/rapbase/pull/94))
* Replaced function none ascii with unicode characters

# rapbase 1.19.2
Expand Down
48 changes: 32 additions & 16 deletions R/autoReport.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ createAutoReport <- function(synopsis, package, type = "subscription", fun,
if (is.null(terminateDate)) {
context <- Sys.getenv("R_RAP_INSTANCE")
terminateDate <- as.POSIXlt(Sys.Date())
if (context %in% c("PRODUCTION")) {
if (context %in% c("PRODUCTION", "PRODUCTIONC")) {
terminateDate$year <- terminateDate$year + 3
} else {
terminateDate$mon <- terminateDate$mon + 1
Expand Down Expand Up @@ -645,7 +645,7 @@ findNextRunDate <- function(runDayOfYear,
#'
#' Make a table to be rendered in a shiny app providing automated reports
#' from a given user or registry as obtained from the shiny session
#' object provided.
#' object provided or environmental variables when run inside an app container.
#'
#' Each table record (line) represents a uniquely defined automated report.
#' For each line two shiny action buttons are provided to allow
Expand All @@ -670,40 +670,56 @@ findNextRunDate <- function(runDayOfYear,
#'
#' @param session A shiny session object
#' @param namespace String naming namespace. Defaults to \code{character()} in
#' which case no namespace will be created. When this function is used by shiny
#' modules namespace must be provided.
#' which case no namespace will be created. When this function is used by
#' shiny modules namespace must be provided.
#' @param user Character string providing the username. Introduced as a new
#' argument when running apps inside containers. Default value is set to
#' \code{rapbase::getUserName(session)} to allow backward compatibility.
#' @param group Character string defining the registry, normally corresponding
#' to the R package name and the value stemming from the SHINYPROXY_GROUPS
#' environment variable. Introduced as a new argument when running apps inside
#' containers. Default value is set to \code{rapbase::getUserGroups(session)}
#' to allow backward compatibility.
#' @param orgId Character string or integer defining the organization (id) for
#' \code{user}. Default value is set to \code{rapbase::getUserReshId(session)}
#' to allow backward compatibility.
#' @param type Character string defining the type of auto reports to tabulate.
#' Must be one of \code{"subscription"}, \code{"dispatchment"} or
#' \code{"bulletin"}. Default value set to \code{"subscription"}.
#' Must be one of \code{"subscription"}, \code{"dispatchment"} or
#' \code{"bulletin"}. Default value set to \code{"subscription"}.
#' @param mapOrgId Data frame containing the two columns 'name' and 'id'
#' corresponding to unique name and id of organizations. Default is NULL in
#' which case the ids provided in auto report data will be used. In case
#' mapOrgId is not NULL but no id match is found the id found in the auto
#' report data will also be used
#' corresponding to unique name and id of organizations. Default is NULL in
#' which case the ids provided in auto report data will be used. In case
#' mapOrgId is not NULL but no id match is found the id found in the auto
#' report data will also be used
#' @param includeReportId Logical if the unique report id should be added as
#' the last column in the table. FALSE by default.
#' the last column in the table. FALSE by default.
#'
#' @return Matrix providing a table to be rendered in a shiny app
#' @importFrom magrittr "%>%"
#' @export
# nolint end

makeAutoReportTab <- function(session, namespace = character(),
type = "subscription", mapOrgId = NULL,
makeAutoReportTab <- function(session,
namespace = character(),
user = rapbase::getUserName(session),
group = rapbase::getUserGroups(session),
orgId = rapbase::getUserReshId(session),
type = "subscription",
mapOrgId = NULL,
includeReportId = FALSE) {
stopifnot(type %in% c("subscription", "dispatchment", "bulletin"))

. <- ""

l <- list()
autoRep <- readAutoReportData() %>%
filterAutoRep(., by = "package", pass = getUserGroups(session)) %>%
filterAutoRep(., by = "package", pass = group) %>%
filterAutoRep(., by = "type", pass = type)

if (type == "subscription") {
autoRep <- autoRep %>%
filterAutoRep(., by = "owner", pass = getUserName(session)) %>%
filterAutoRep(., by = "organization", pass = getUserReshId(session))
filterAutoRep(., by = "owner", pass = user) %>%
filterAutoRep(., by = "organization", pass = orgId)
}

dateFormat <- "%A %e. %B %Y"
Expand Down
24 changes: 16 additions & 8 deletions R/log.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,14 @@ NULL
#' try(appLogger(list()))
#' }
#'
appLogger <- function(session, msg = "No message provided") {
appLogger <- function(session, msg = "No message provided",
.topcall = sys.call(-1), .topenv = parent.frame()) {
name <- "appLog"
content <- c(getSessionData(session), list(message = msg))
parent_environment <- environmentName(topenv(.topenv))
content <- c(
getSessionData(session, group = parent_environment),
list(message = msg)
)
event <- makeLogRecord(content)
appendLog(event, name)
}
Expand Down Expand Up @@ -270,16 +275,19 @@ makeLogRecord <- function(content) {
#' Internal function providing session data relevant to logging.
#'
#' @param session A shiny session object
#' @param group Character string providing the name of the app R package name.
#' The term "group" is used to relate to the environmental variable
#' SHINYPROXY_USERGROUPS that corresponds to the apps a given user can access.
#'
#' @return A list of relevant log fields
#' @keywords internal
getSessionData <- function(session) {
getSessionData <- function(session, group = NULL) {
list(
user = rapbase::getUserName(session),
name = rapbase::getUserFullName(session),
group = rapbase::getUserGroups(session),
role = rapbase::getUserRole(session),
resh_id = rapbase::getUserReshId(session)
user = rapbase::getUserName(session, group),
name = rapbase::getUserFullName(session, group),
group = rapbase::getUserGroups(session, group),
role = rapbase::getUserRole(session, group),
resh_id = rapbase::getUserReshId(session, group)
)
}

Expand Down
3 changes: 2 additions & 1 deletion R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ getRapPackages <- function() {
#' isRapContext()
#'
isRapContext <- function() {
if (Sys.getenv("R_RAP_INSTANCE") %in% c("DEV", "TEST", "QA", "PRODUCTION")) {
if (Sys.getenv("R_RAP_INSTANCE") %in%
c("DEV", "TEST", "QA", "PRODUCTION", "PRODUCTIONC")) {
return(TRUE)
} else {
return(FALSE)
Expand Down
Loading

0 comments on commit 48039ad

Please sign in to comment.