Skip to content

Commit

Permalink
Added rules when the the option of broker service is disabled in back…
Browse files Browse the repository at this point in the history
…end (#175)

Co-authored-by: Wilian Gabriel <wilian.silva@zup.com.br>
  • Loading branch information
lucasbrunozup and wiliansilvazup authored Dec 7, 2020
1 parent 7cd0d6b commit e01eb94
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 21 deletions.
27 changes: 15 additions & 12 deletions horusec-manager/src/components/SideMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { authTypes } from 'helpers/enums/authTypes';
const SideMenu: React.FC = () => {
const history = useHistory();
const { t } = useTranslation();
const { authType } = getCurrentConfig();
const { authType, disabledBroker } = getCurrentConfig();

const [selectedRoute, setSelectedRoute] = useState<InternalRoute>();
const [selectedSubRoute, setSelectedSubRoute] = useState<InternalRoute>();
Expand Down Expand Up @@ -90,6 +90,7 @@ const SideMenu: React.FC = () => {
path: '/home/webhooks',
type: 'route',
roles: ['admin'],
rule: () => !disabledBroker,
},
];

Expand Down Expand Up @@ -119,17 +120,19 @@ const SideMenu: React.FC = () => {

const renderRoute = (route: InternalRoute, index: number) => {
if (route.roles.includes(userRoleInCurrentCompany())) {
return (
<Styled.RouteItem
key={index}
isActive={route.path === selectedRoute?.path}
onClick={() => handleSelectedRoute(route)}
>
<Icon name={route.icon} size="15" />

<Styled.RouteName>{route.name}</Styled.RouteName>
</Styled.RouteItem>
);
if (!route?.rule || (route?.rule && route?.rule())) {
return (
<Styled.RouteItem
key={index}
isActive={route.path === selectedRoute?.path}
onClick={() => handleSelectedRoute(route)}
>
<Icon name={route.icon} size="15" />

<Styled.RouteName>{route.name}</Styled.RouteName>
</Styled.RouteItem>
);
}
}
};

Expand Down
3 changes: 2 additions & 1 deletion horusec-manager/src/config/i18n/enUS.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
"INVALID_CONFIRM_PASS": "Passwords are not the same.",
"SUBMIT": "Register",
"CONFIRM": "Ok, I got it.",
"SUCCESS_CREATE_ACCOUNT": "An e-mail has been sent to verify your account.",
"SUCCESS_CREATE_ACCOUNT": "Your Horusec account has been successfully created!",
"SUCCESS_CREATE_ACCOUNT_WITH_CONFIRM": "An e-mail has been sent to verify your account.",
"OLD_PASS": "Old Password"
},

Expand Down
3 changes: 2 additions & 1 deletion horusec-manager/src/config/i18n/ptBR.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
"INVALID_CONFIRM_PASS": "As senhas não são iguais.",
"SUBMIT": "Cadastrar",
"CONFIRM": "Ok, entendi.",
"SUCCESS_CREATE_ACCOUNT": "Foi enviado um email para verificação da sua conta.",
"SUCCESS_CREATE_ACCOUNT": "Sua conta Horusec foi criada com sucesso!",
"SUCCESS_CREATE_ACCOUNT_WITH_CONFIRM": "Foi enviado um email para verificação da sua conta.",
"OLD_PASS": "Antiga senha"
},

Expand Down
1 change: 1 addition & 0 deletions horusec-manager/src/helpers/interfaces/HorusecConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@

export interface HorusecConfig {
applicationAdminEnable: boolean;
disabledBroker: boolean;
authType: 'horusec' | 'keycloak' | 'ldap';
}
1 change: 1 addition & 0 deletions horusec-manager/src/helpers/interfaces/InternalRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface InternalRoute {
icon: string;
path?: string;
roles?: string[];
rule?(): boolean;
subRoutes?: InternalRoute[];
type: 'route' | 'subRoute';
}
1 change: 1 addition & 0 deletions horusec-manager/src/helpers/localStorage/horusecConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { HorusecConfig } from 'helpers/interfaces/HorusecConfig';
const initialValues: HorusecConfig = {
authType: null,
applicationAdminEnable: false,
disabledBroker: false,
};

const getCurrentConfig = (): HorusecConfig => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ import {
hasUpperCase,
} from 'helpers/validators';
import { CreateAccountContext } from 'contexts/CreateAccount';
import { getCurrentConfig } from 'helpers/localStorage/horusecConfig';

function PasswordForm() {
const { t } = useTranslation();
const { disabledBroker } = getCurrentConfig();
const history = useHistory();
const {
password,
Expand Down Expand Up @@ -146,7 +148,11 @@ function PasswordForm() {
<Dialog
isVisible={successDialogVisible}
confirmText={t('CREATE_ACCOUNT_SCREEN.CONFIRM')}
message={t('CREATE_ACCOUNT_SCREEN.SUCCESS_CREATE_ACCOUNT')}
message={
disabledBroker
? t('CREATE_ACCOUNT_SCREEN.SUCCESS_CREATE_ACCOUNT')
: t('CREATE_ACCOUNT_SCREEN.SUCCESS_CREATE_ACCOUNT_WITH_CONFIRM')
}
onConfirm={() => history.push('/auth')}
roundedButton
/>
Expand Down
14 changes: 9 additions & 5 deletions horusec-manager/src/pages/External/Auth/Horusec/Login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import { useHistory, useRouteMatch } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { Field } from 'helpers/interfaces/Field';
import useAuth from 'helpers/hooks/useAuth';
import { getCurrentConfig } from 'helpers/localStorage/horusecConfig';

function LoginScreen() {
const { t } = useTranslation();
const history = useHistory();
const { path } = useRouteMatch();
const { login, loginInProgress } = useAuth();
const { disabledBroker } = getCurrentConfig();

const [email, setEmail] = useState<Field>({ value: '', isValid: false });
const [password, setPassword] = useState<Field>({
Expand Down Expand Up @@ -64,11 +66,13 @@ function LoginScreen() {
invalidMessage={t('LOGIN_SCREEN.INVALID_PASS')}
/>

<Styled.ForgotPass
onClick={() => history.push(`${path}/recovery-password`)}
>
{t('LOGIN_SCREEN.FORGOT_PASS')}
</Styled.ForgotPass>
{!disabledBroker ? (
<Styled.ForgotPass
onClick={() => history.push(`${path}/recovery-password`)}
>
{t('LOGIN_SCREEN.FORGOT_PASS')}
</Styled.ForgotPass>
) : null}

<Styled.Submit
isDisabled={!password.isValid || !email.isValid}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { useTheme } from 'styled-components';
import accountService from 'services/account';
import useAuth from 'helpers/hooks/useAuth';
import { useHistory } from 'react-router-dom';
import { getCurrentConfig } from 'helpers/localStorage/horusecConfig';

interface Props {
isVisible: boolean;
Expand All @@ -45,6 +46,7 @@ const EditAccount: React.FC<Props> = ({ isVisible, onCancel, onConfirm }) => {
const { showSuccessFlash } = useFlashMessage();
const { logout } = useAuth();
const history = useHistory();
const { disabledBroker } = getCurrentConfig();

const [isLoading, setLoading] = useState(false);
const [successDialogIsOpen, setSuccessDialogIsOpen] = useState(false);
Expand Down Expand Up @@ -76,7 +78,7 @@ const EditAccount: React.FC<Props> = ({ isVisible, onCancel, onConfirm }) => {
accountService
.update(nameOfUser.value, emailOfUser.value)
.then(() => {
if (emailOfUser.value !== currentUser.email) {
if (emailOfUser.value !== currentUser.email && !disabledBroker) {
setSuccessDialogIsOpen(true);
}

Expand Down

0 comments on commit e01eb94

Please sign in to comment.