Skip to content

Commit 0a680a6

Browse files
committed
issues/449 Addressing PR comments
1 parent ca624e3 commit 0a680a6

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/main/java/eu/openanalytics/shinyproxy/controllers/IndexController.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,21 @@
4141
@Controller
4242
public class IndexController extends BaseController {
4343

44-
private static final String PROXY_LANDING_PAGE_AUTO_OPTION = "auto";
44+
/**
45+
* Allows users on a ShinyProxy deployment <b>with only one app defined</b> to be redirected straight
46+
* to the only existing app, without going through the Index page.
47+
*/
48+
private static final String PROXY_LANDING_PAGE_SINGLE_APP_OPTION = "SingleApp";
49+
/**
50+
* Allows users on any ShinyProxy deployment to be redirected straight to the first available app,
51+
* without going through the Index page.
52+
*/
53+
private static final String PROXY_LANDING_PAGE_FIRST_APP_OPTION = "FirstApp";
54+
55+
/**
56+
* Redirects users on a ShinyProxy deployment to the index page.
57+
*/
58+
private static final String PROXY_LANDING_PAGE_INDEX_OPTION = "/";
4559

4660
@Inject
4761
private ShinyProxySpecProvider shinyProxySpecProvider;
@@ -59,7 +73,10 @@ public void init() {
5973
@RequestMapping("/")
6074
private Object index(ModelMap map, HttpServletRequest request) {
6175
String landingPage = environment.getProperty("proxy.landing-page", "/");
62-
if (!landingPage.equals("/") && !landingPage.equals(PROXY_LANDING_PAGE_AUTO_OPTION)) {
76+
77+
if (!landingPage.equals(PROXY_LANDING_PAGE_INDEX_OPTION)
78+
&& !landingPage.equals(PROXY_LANDING_PAGE_SINGLE_APP_OPTION)
79+
&& !landingPage.equals(PROXY_LANDING_PAGE_FIRST_APP_OPTION)) {
6380
return new RedirectView(landingPage);
6481
}
6582

@@ -68,10 +85,14 @@ private Object index(ModelMap map, HttpServletRequest request) {
6885
ProxySpec[] apps = proxyService.getProxySpecs(null, false).toArray(new ProxySpec[0]);
6986
map.put("apps", apps);
7087

71-
// If set to `auto`, redirect to the first available app in the list
72-
// See https://github.com/openanalytics/shinyproxy/issues/269
73-
if (apps.length > 0 && landingPage.equals(PROXY_LANDING_PAGE_AUTO_OPTION))
88+
// If set to `FirstApp`, redirect to the first app available to the logged-in user
89+
if (apps.length > 0 && landingPage.equals(PROXY_LANDING_PAGE_FIRST_APP_OPTION)) {
90+
return new RedirectView("/app/" + apps[0].getId());
91+
}
92+
// If set to `SingleApp` and only one app is available to the logged-in user, redirect to it
93+
if (apps.length == 1 && landingPage.equals(PROXY_LANDING_PAGE_SINGLE_APP_OPTION)) {
7494
return new RedirectView("/app/" + apps[0].getId());
95+
}
7596

7697
Map<ProxySpec, String> appLogos = new HashMap<>();
7798
map.put("appLogos", appLogos);

0 commit comments

Comments
 (0)