-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* substitutes tokens in urls [anonymous experience] * adds profile to state and reducers * substitutes token for authenticated user * autogenerates password in the postbody
- Loading branch information
Charles Wahome
committed
Nov 13, 2019
1 parent
25e9a2b
commit 65ba338
Showing
16 changed files
with
1,728 additions
and
1,436 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { IAction } from '../../../types/action'; | ||
import { LOGOUT_SUCCESS, PROFILE_REQUEST_SUCCESS } from '../redux-constants'; | ||
|
||
export function profile(state = null, action: IAction): any { | ||
switch (action.type) { | ||
case LOGOUT_SUCCESS: | ||
return null; | ||
case PROFILE_REQUEST_SUCCESS: | ||
return action.response; | ||
default: | ||
return state; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { IQuery } from '../../types/query-runner'; | ||
import { IToken } from '../../types/sidebar'; | ||
import { getTokens } from '../views/sidebar/sample-queries/tokens'; | ||
|
||
/* | ||
* Given a token, go through each of the possible replacement scenarios and find which value to | ||
* replace the token with. | ||
* Order: Authenticated user values, demo tenant replacament values, default replacement values. | ||
*/ | ||
export function getTokenSubstituteValue(token: IToken, isAuthenticated: boolean) { | ||
const priorityOrder = []; // Desc | ||
if (isAuthenticated) { | ||
priorityOrder.push(token.authenticatedUserValueFn); | ||
priorityOrder.push(token.authenticatedUserValue); | ||
} else { | ||
priorityOrder.push(token.demoTenantValueFn); | ||
priorityOrder.push(token.demoTenantValue); | ||
} | ||
|
||
priorityOrder.push(token.defaultValueFn); | ||
priorityOrder.push(token.defaultValue); | ||
|
||
for (const tokenVal of priorityOrder) { | ||
if (!tokenVal) { | ||
continue; | ||
} | ||
if (typeof tokenVal === 'string') { | ||
return tokenVal; | ||
} else if (typeof tokenVal === 'function') { | ||
return tokenVal(); | ||
} | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Given a query, replace all tokens in the request URL and the POST body with their | ||
* values. When a token is found, use getTokenSubstituteValue() to find the right | ||
* value to substitute based on the session. | ||
*/ | ||
|
||
export function substituteTokens(query: IQuery, profile: object) { | ||
type QueryFields = keyof IQuery; | ||
const tokens = getTokens(profile); | ||
const authenticated = !!profile; | ||
for (const token of tokens) { | ||
const queryFieldsToCheck: QueryFields[] = ['sampleBody', 'sampleUrl']; | ||
|
||
for (const queryField of queryFieldsToCheck) { | ||
if (!query[queryField]) { | ||
continue; | ||
} | ||
|
||
if ((query[queryField] as string).indexOf(`{${token.placeholder}}`) !== -1) { | ||
const substitutedValue = getTokenSubstituteValue(token, authenticated); | ||
if (!substitutedValue) { | ||
continue; | ||
} | ||
query[queryField] = (query[queryField] as string).replace(`{${token.placeholder}}`, substitutedValue); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.