From 900e414680e6a990cd892ea9bcbc7e34336ec44f Mon Sep 17 00:00:00 2001 From: Brian Do Date: Mon, 31 Aug 2020 16:30:00 -0700 Subject: [PATCH] [AFP-2121] Configure Permissions Message (#82) * add field in config to configure permissions message on queue and history tabs * revert changes to docker compose * remove permission import, change permission check back to 'read' * revert changes to docker compose * add default permissions message in Config.ts Co-authored-by: Brian Do --- .circleci/config.yml | 4 ---- src/lib/Config.ts | 4 ++++ src/lib/Runner.ts | 1 + src/static/current-state/components/App.tsx | 1 + .../components/tabs/HistoryTab.tsx | 3 ++- .../components/tabs/QueueTab.tsx | 7 +++--- .../current-state/components/tabs/index.tsx | 24 ++++++++++++++++--- src/types.ts | 2 ++ 8 files changed, 34 insertions(+), 12 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3f4b404b..ff406801 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,10 +7,6 @@ jobs: working_directory: ~/repo steps: - checkout - - restore_cache: - keys: - - v1-dependencies-{{ checksum "yarn.lock" }} - - v1-dependencies- - run: yarn - save_cache: paths: diff --git a/src/lib/Config.ts b/src/lib/Config.ts index 6a294d31..30225b88 100644 --- a/src/lib/Config.ts +++ b/src/lib/Config.ts @@ -17,6 +17,10 @@ const getConfig = (): Config | null => { configValid = false; } + if (!config.permissionsMessage) { + config.permissionsMessage = 'Contact an admin for permission to view this information'; + } + if (!configValid) { throw new Error('Config is invalid'); } diff --git a/src/lib/Runner.ts b/src/lib/Runner.ts index 173c27a2..c6cdf0ff 100644 --- a/src/lib/Runner.ts +++ b/src/lib/Runner.ts @@ -647,6 +647,7 @@ export class Runner { bitbucketBaseUrl: `https://bitbucket.org/${this.config.repoConfig.repoOwner}/${ this.config.repoConfig.repoName }`, + permissionsMessage: this.config.permissionsMessage, }; }; } diff --git a/src/static/current-state/components/App.tsx b/src/static/current-state/components/App.tsx index 692111cb..31759be9 100644 --- a/src/static/current-state/components/App.tsx +++ b/src/static/current-state/components/App.tsx @@ -34,6 +34,7 @@ export const App: React.FunctionComponent = () => ( loggedInUser={loggedInUser} paused={data.pauseState !== null} bannerMessageState={data.bannerMessageState} + permissionsMessage={data.permissionsMessage} /> )} diff --git a/src/static/current-state/components/tabs/HistoryTab.tsx b/src/static/current-state/components/tabs/HistoryTab.tsx index 3cbbeac6..b416286e 100644 --- a/src/static/current-state/components/tabs/HistoryTab.tsx +++ b/src/static/current-state/components/tabs/HistoryTab.tsx @@ -34,6 +34,7 @@ import { Section } from '../Section'; export type HistoryTabProps = { bitbucketBaseUrl: string; loggedInUser: ISessionUser; + permissionsMessage: string; }; type HistoryState = { @@ -64,7 +65,7 @@ export class HistoryTab extends React.Component { {this.props.loggedInUser.permission === 'read' - ? 'Contact an admin for permission to view this information' + ? this.props.permissionsMessage : 'Empty...'} diff --git a/src/static/current-state/components/tabs/QueueTab.tsx b/src/static/current-state/components/tabs/QueueTab.tsx index 13b2b069..1785c35b 100644 --- a/src/static/current-state/components/tabs/QueueTab.tsx +++ b/src/static/current-state/components/tabs/QueueTab.tsx @@ -7,10 +7,11 @@ export type QueueTabProps = { bitbucketBaseUrl: string; loggedInUser: ISessionUser; queue: IStatusUpdate[]; + permissionsMessage: string; }; export const QueueTab: React.FunctionComponent = props => { - const { bitbucketBaseUrl, loggedInUser, queue } = props; + const { bitbucketBaseUrl, loggedInUser, queue, permissionsMessage } = props; return (
= props => { renderEmpty={() => ( - {loggedInUser.permission === 'read' - ? 'Contact an admin for permission to view this information' - : 'Queue is empty...'} + {loggedInUser.permission === 'read' ? permissionsMessage : 'Queue is empty...'} )} diff --git a/src/static/current-state/components/tabs/index.tsx b/src/static/current-state/components/tabs/index.tsx index 8d6c86c2..461caa0b 100644 --- a/src/static/current-state/components/tabs/index.tsx +++ b/src/static/current-state/components/tabs/index.tsx @@ -84,6 +84,7 @@ export type TabsProps = { loggedInUser: ISessionUser; paused: boolean; bannerMessageState: IMessageState | null; + permissionsMessage: string; }; type TabsState = { @@ -112,7 +113,15 @@ export class Tabs extends React.Component { render() { const { selected } = this.state; - const { users, bitbucketBaseUrl, queue, loggedInUser, paused, bannerMessageState } = this.props; + const { + users, + bitbucketBaseUrl, + queue, + loggedInUser, + paused, + bannerMessageState, + permissionsMessage, + } = this.props; return (
@@ -126,10 +135,19 @@ export class Tabs extends React.Component { /> ) : null} {selected === 1 ? ( - + ) : null} {selected === 2 ? ( - + ) : null}
); diff --git a/src/types.ts b/src/types.ts index f22df429..fdba3ffa 100644 --- a/src/types.ts +++ b/src/types.ts @@ -75,6 +75,7 @@ export type Config = { prSettings: PullRequestSettings; deployment: DeploymentConfig; maxConcurrentBuilds?: number; + permissionsMessage: string; sequelize?: any; easterEgg?: any; }; @@ -87,4 +88,5 @@ export type RunnerState = { users: UserState[]; bannerMessageState: IMessageState | null; bitbucketBaseUrl: string; + permissionsMessage: string; };