Skip to content

🚩 Visa Tab should be enabled through configuration #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.schema
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ REACT_APP_EGO_CLIENT_ID=ego
# debug namespace, e.g. "app". See https://www.npmjs.com/package/debug
REACT_APP_DEBUG=app
REACT_APP_KEYCLOAK_ENABLED=false
REACT_APP_PASSPORT_ENABLED=false
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

schema file defines the basic configuration variables needed to run this app, mentioned in .readme file

5 changes: 3 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import { provideLoggedInUser } from 'stateProviders';
import BreadCrumb from 'components/BreadCrumb';
import Login from 'components/Login';
import ResourceRoute from 'components/ResourceRoute';
import { VISAS } from 'common/enums';
import RESOURCE_MAP from 'common/RESOURCE_MAP';
import Nav from 'components/Nav';
import NoAccess from 'components/NoAccess';
import { PUBLIC_PATH } from 'common/injectGlobals';
import { PUBLIC_PATH, PASSPORT_ENABLED } from 'common/injectGlobals';

const enhance = compose(provideLoggedInUser);

Expand All @@ -34,7 +35,7 @@ class App extends React.Component<any, any> {
<div css={{ width: 0, flexGrow: 1, display: 'flex', flexDirection: 'column' }}>
<BreadCrumb path={props.location.pathname} />
<Switch>
{Object.keys(RESOURCE_MAP).map((key) => {
{Object.keys(RESOURCE_MAP).filter(key => !(key === VISAS && !PASSPORT_ENABLED)).map((key) => {
const resource = RESOURCE_MAP[key];
return (
<ProtectedRoute
Expand Down
2 changes: 2 additions & 0 deletions src/common/injectGlobals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export const EGO_CLIENT_ID = process.env.REACT_APP_EGO_CLIENT_ID;

export const PUBLIC_PATH = process.env.REACT_APP_PUBLIC_PATH;

export const PASSPORT_ENABLED = process.env.REACT_APP_PASSPORT_ENABLED === 'true' || false;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passport flag disabled by default

export const KEYCLOAK_ENABLED = process.env.REACT_APP_KEYCLOAK_ENABLED === 'true' || false;

export const STATUSES = ['DISABLED', 'APPROVED', 'PENDING', 'REJECTED'];
Expand Down
4 changes: 2 additions & 2 deletions src/components/Login.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @jsxImportSource @emotion/react */
import { API_ROOT, EGO_CLIENT_ID, KEYCLOAK_ENABLED } from 'common/injectGlobals';
import { API_ROOT, EGO_CLIENT_ID, KEYCLOAK_ENABLED, PASSPORT_ENABLED } from 'common/injectGlobals';
import { injectState } from 'freactal';
import { css } from '@emotion/react';
import jwtDecode from 'jwt-decode';
Expand Down Expand Up @@ -182,7 +182,7 @@ class Component extends React.Component<any, any> {
? 'Or login with one of the following services'
: 'Login with one of the following'}
</h3>
{providers.map(({ name, path, Icon }) => {
{providers.filter(provider => PASSPORT_ENABLED || provider.name !== LoginProvider.Passport).map(({ name, path, Icon }) => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored condition as suggested for better readability

return (
<LoginButton
key={name}
Expand Down
3 changes: 3 additions & 0 deletions src/components/Nav/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { injectState } from 'freactal';
import { compose } from 'recompose';
import { Icon } from 'semantic-ui-react';

import { VISAS } from 'common/enums';
import { PASSPORT_ENABLED } from 'common/injectGlobals';
import RESOURCE_MAP from 'common/RESOURCE_MAP';
import UnstyledButton from 'components/UnstyledButton';
import CurrentUserNavItem from './CurrentUserNavItem';
Expand Down Expand Up @@ -73,6 +75,7 @@ const Nav = ({ effects, state }) => {
</div>
<ul css={listStyles}>
{Object.keys(pickBy(RESOURCE_MAP, (r) => r.isParent)).map((key) => {
if(key === VISAS && !PASSPORT_ENABLED) { return null; }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored condition as suggested

const resource = RESOURCE_MAP[key];
return (
<li key={key}>
Expand Down
2 changes: 1 addition & 1 deletion src/services/createVisa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ajax from 'services/ajax';
const BLOCKED_KEYS = ['id', 'createdAt', 'lastLogin', 'groups', 'applications'];

export const createVisa = ({ item }) => {
return ajax.post(`/visa`, _.omit(item, BLOCKED_KEYS)).then(r => {
return ajax.post(`/visas`, _.omit(item, BLOCKED_KEYS)).then(r => {
Copy link
Author

@leoraba leoraba Jul 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixing a typo..

return r.data
});
};