forked from r-geoflow/geoflow-shiny
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.R
168 lines (148 loc) · 5.29 KB
/
server.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# Define server logic required
#==========================================================================================
server <- function(input, output, session) {
onStop(function(){
resetAuthSessionVariables(session)
})
if(appConfig$auth){
auth_info <- reactiveVal(NULL)
if(appConfig$auth_ui){
#auth with UI
credentials <- authLoginServer(
id = "login",
config = appConfig,
log_out = reactive(logout_init())
)
# call the logout module with reactive trigger to hide/show
logout_init <- shinyauthr::logoutServer(
id = "logout",
active = reactive(credentials()$user_auth)
)
observe({
if (credentials()$user_auth) {
info = credentials()$auth_info
info$logged <- credentials()$user_auth
auth_info(info)
if(!is.null(auth_info())){
initAuthSessionVariables(session, auth_info())
INFO("Load configuration editor module")
config_editor_server("config_editor", auth_info, parent.session = session)
INFO("Load configuration list module")
config_list_server("config_list", auth_info, parent.session = session)
}
shinyjs::removeClass(selector = "body", class = "sidebar-collapse")
shinyjs::show(selector = "header")
} else {
shinyjs::addClass(selector = "body", class = "sidebar-collapse")
shinyjs::hide(selector = "header")
}
})
}else{
#auth without UI
shinyjs::removeClass(selector = "body", class = "sidebar-collapse")
shinyjs::show(selector = "header")
#JWT auth
observe({
jwt_profile <- decodeJWT(appConfig$auth_jwt)
#D4Science JWT Auth - setting interaction with D4Science StorageHub
if(startsWith(jwt_profile$iss, "https://accounts.d4science.org")){
AUTH_API <- try(d4storagehub4R::StoragehubManager$new(token = jwt_profile$access$access_token, token_type = "jwt"))
if (is(AUTH_API, "StoragehubManager")) {
assign("AUTH_API", AUTH_API, envir = GEOFLOW_SHINY_ENV)
auth_info(list(
endpoint = list(auth_url = "https://api.d4science.org/workspace", auth_type = "d4science"),
backend = NA,
service = NA,
user = AUTH_API$getUserProfile()$username,
token = jwt_profile$access$access_token
))
if(!is.null(auth_info())){
INFO("Set-up geoflow-shiny in auth mode (no UI, token based)")
initAuthSessionVariables(session, auth_info())
INFO("Load configuration editor module")
config_editor_server("config_editor", auth_info, parent.session = session)
INFO("Load configuration list module")
config_list_server("config_list", auth_info, parent.session = session)
}
}
}
})
}
}else{
#anonymous usage
INFO("Set-up geoflow-shiny in anonymous mode")
INFO("Load configuration editor module")
config_editor_server("config_editor", parent.session = session)
INFO("Load configuration list module")
config_list_server("config_list", parent.session = session)
shinyjs::removeClass(selector = "body", class = "sidebar-collapse")
shinyjs::show(selector = "header")
}
output$side_ui <- renderUI({
if(appConfig$auth){
if(appConfig$auth_ui){
req(credentials()$user_auth)
sidebarMenu(
id = "geoflow-tabs",
menuItem(
text = "Configuration",
tabName = "config",
menuSubItem(text = "Configuration editor", tabName = "config_editor"),
menuSubItem(text = "List of configurations", tabName = "config_list"),
startExpanded = TRUE
)
)
}else{
sidebarMenu(
id = "geoflow-tabs",
menuItem(
text = "Configuration",
tabName = "config",
menuSubItem(text = "Configuration editor", tabName = "config_editor"),
menuSubItem(text = "List of configurations", tabName = "config_list"),
startExpanded = TRUE
)
)
}
}else{
sidebarMenu(
id = "geoflow-tabs",
menuItem(
text = "Configuration",
tabName = "config",
menuSubItem(text = "Configuration editor", tabName = "config_editor"),
menuSubItem(text = "List of configurations", tabName = "config_list")
)
)
}
})
output$main_ui <- renderUI({
if(appConfig$auth){
if(appConfig$auth_ui){
req(credentials()$user_auth)
tabItems(
config_editor_ui("config_editor"),
config_list_ui("config_list")
)
}else{
tabItems(
config_editor_ui("config_editor"),
config_list_ui("config_list")
)
}
}else{
tabItems(
config_editor_ui("config_editor"),
config_list_ui("config_list")
)
}
})
#module page management
session$userData$module <- reactiveVal(NULL)
observe({
#Update moduleUrl
moduleUrl <- gsub('_', '-', input$`geoflow-tabs`)
session$userData$module(moduleUrl)
updateModuleUrl(session, moduleUrl)
})
}