Skip to content

Commit efd1e16

Browse files
committed
Merge branch 'nickmelis-issues/269' into develop
2 parents 1f9822a + ad51452 commit efd1e16

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@
4040
@Controller
4141
public class IndexController extends BaseController {
4242

43+
/**
44+
* Allows users on a ShinyProxy deployment <b>with only one app defined</b> to be redirected straight
45+
* to the only existing app, without going through the Index page.
46+
*/
47+
private static final String PROXY_LANDING_PAGE_SINGLE_APP_OPTION = "SingleApp";
48+
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 = "/";
59+
4360
@Inject
4461
private ShinyProxySpecProvider shinyProxySpecProvider;
4562

@@ -58,11 +75,25 @@ public void init() {
5875

5976
@RequestMapping("/")
6077
private Object index(ModelMap map, HttpServletRequest request) {
61-
if (!landingPage.equals("/")) return new RedirectView(landingPage);
78+
if (!landingPage.equals(PROXY_LANDING_PAGE_INDEX_OPTION)
79+
&& !landingPage.equals(PROXY_LANDING_PAGE_SINGLE_APP_OPTION)
80+
&& !landingPage.equals(PROXY_LANDING_PAGE_FIRST_APP_OPTION)) {
81+
return new RedirectView(landingPage, true);
82+
}
83+
84+
List<ProxySpec> apps = proxyService.getUserSpecs();
85+
86+
// If set to `FirstApp`, redirect to the first app available to the logged-in user
87+
if (!apps.isEmpty() && landingPage.equals(PROXY_LANDING_PAGE_FIRST_APP_OPTION)) {
88+
return new RedirectView("/app/" + apps.get(0).getId(), true);
89+
}
90+
// If set to `SingleApp` and only one app is available to the logged-in user, redirect to it
91+
if (apps.size() == 1 && landingPage.equals(PROXY_LANDING_PAGE_SINGLE_APP_OPTION)) {
92+
return new RedirectView("/app/" + apps.get(0).getId(), true);
93+
}
6294

6395
prepareMap(map, request);
6496

65-
List<ProxySpec> apps = proxyService.getUserSpecs();
6697
map.put("apps", apps);
6798

6899
// app logos

0 commit comments

Comments
 (0)