Skip to content

Commit 16823c3

Browse files
author
Adam Tuttle
committed
Resolves #99, show dashboard without the ?dashboard queryparam
1 parent ca682a1 commit 16823c3

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

core/api.cfc

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,24 @@
5353
</cfif>
5454
</cfif>
5555
<cfif !isUnhandledPathRequest(arguments.targetPath)>
56-
<!--- if browsing to root of api, redirect to dashboard --->
57-
<cfif NOT application._taffy.settings.disableDashboard AND NOT structKeyExists(url,application._taffy.settings.endpointURLParam) AND NOT structKeyExists(form,application._taffy.settings.endpointURLParam) AND len(cgi.path_info) lte 1 and len(cgi.query_string) eq 0 and listLast(cgi.script_name, "/") eq "index.cfm">
58-
<cfset local.basePath = listDeleteAt(cgi.script_name,listLen(cgi.script_name,"/"),"/") />
59-
<cflocation url="#local.basePath#/?#application._taffy.settings.dashboardKey#" addtoken="false" />
56+
<!--- if browsing to root of api, show dashboard --->
57+
<cfif
58+
NOT structKeyExists(url,application._taffy.settings.endpointURLParam)
59+
AND NOT structKeyExists(form,application._taffy.settings.endpointURLParam)
60+
AND len(cgi.path_info) lte 1
61+
AND listLast(cgi.script_name, "/") eq "index.cfm">
62+
<cfif NOT application._taffy.settings.disableDashboard>
63+
<cfset requestStartEvent() />
64+
<cfinclude template="dashboard.cfm" />
65+
<cfabort />
66+
<cfelse>
67+
<cfif len(application._taffy.settings.disabledDashboardRedirect)>
68+
<cflocation url="#application._taffy.settings.disabledDashboardRedirect#" addtoken="false" />
69+
<cfabort />
70+
<cfelse>
71+
<cfset throwError(403, "Forbidden") />
72+
</cfif>
73+
</cfif>
6074
</cfif>
6175
<cfelse>
6276
<!--- allow pass-thru for selected paths --->
@@ -300,6 +314,7 @@
300314
<cfset local.defaultConfig.representationClass = "taffy.core.nativeJsonRepresentation" />
301315
<cfset local.defaultConfig.dashboardKey = "dashboard" />
302316
<cfset local.defaultConfig.disableDashboard = false />
317+
<cfset local.defaultConfig.disabledDashboardRedirect = "" />
303318
<cfset local.defaultConfig.unhandledPaths = "/flex2gateway" />
304319
<cfset local.defaultConfig.allowCrossDomain = false />
305320
<cfset local.defaultConfig.useEtags = false />

tests/tests/TestCore.cfc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,41 @@
452452
debug(local.result);
453453
assertEquals(200,val(local.result.statusCode));
454454
}
455+
456+
function allows_dashboard_when_enabled(){
457+
var restore = application._taffy.settings.disableDashboard;
458+
application._taffy.settings.disableDashboard = false;
459+
local.result = apiCall("get", "/", "");
460+
debug(local.result);
461+
assertEquals(200, val(local.result.statusCode));
462+
463+
application._taffy.settings.disableDashboard = restore;
464+
}
465+
466+
function returns_403_at_root_when_dashboard_disabled_with_no_redirect(){
467+
var restore = application._taffy.settings.disableDashboard;
468+
application._taffy.settings.disableDashboard = true;
469+
local.result = apiCall("get", "/", "");
470+
debug(local.result);
471+
assertEquals(403, val(local.result.statusCode));
472+
473+
application._taffy.settings.disableDashboard = restore;
474+
}
475+
476+
function returns_302_at_root_when_dashboard_disabled_with_redirect(){
477+
var restore1 = application._taffy.settings.disableDashboard;
478+
var restore2 = application._taffy.settings.disabledDashboardRedirect;
479+
application._taffy.settings.disableDashboard = true;
480+
application._taffy.settings.disabledDashboardRedirect = 'http://google.com';
481+
local.result = apiCall("get", "/", "");
482+
debug(local.result);
483+
assertEquals(302, val(local.result.statusCode));
484+
assertTrue(structKeyExists(local.result.responseHEader, "location"));
485+
assertEquals(application._taffy.settings.disabledDashboardRedirect, local.result.responseHeader.location);
486+
487+
application._taffy.settings.disableDashboard = restore1;
488+
application._taffy.settings.disabledDashboardRedirect = restore2;
489+
}
455490
</cfscript>
456491

457492

0 commit comments

Comments
 (0)