pages/index: return 403 error for non МПЛ users role
This commit is contained in:
parent
e92e6a6289
commit
3f384c451f
@ -1,3 +1,4 @@
|
||||
/* eslint-disable sonarjs/no-small-switch */
|
||||
import Button from 'ui/elements/Button';
|
||||
import Result from 'ui/elements/Result';
|
||||
|
||||
@ -5,7 +6,12 @@ function handleRetry() {
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
function openSupport() {
|
||||
window.open('https://support.evoleasing.ru', '_blank').focus();
|
||||
}
|
||||
|
||||
const RetryButton = <Button action={handleRetry} text="Попробовать еще раз" />;
|
||||
const SupportButton = <Button action={openSupport} text="Обратиться в поддержку" />;
|
||||
|
||||
export function CRMError({ error }) {
|
||||
return (
|
||||
@ -17,3 +23,18 @@ export function CRMError({ error }) {
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export function Forbidden() {
|
||||
return <Result status="403" title="Доступ запрещен" extra={SupportButton} />;
|
||||
}
|
||||
|
||||
export function Error({ statusCode, ...props }) {
|
||||
switch (statusCode) {
|
||||
case 403: {
|
||||
return <Forbidden />;
|
||||
}
|
||||
default: {
|
||||
return <CRMError {...props} />;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -467,6 +467,9 @@ query GetSystemUser($domainname: String) {
|
||||
systemuser(domainname: $domainname) {
|
||||
evo_job_titleid
|
||||
businessunitid
|
||||
roles {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -391,7 +391,7 @@ export type GetSystemUserQueryVariables = Exact<{
|
||||
}>;
|
||||
|
||||
|
||||
export type GetSystemUserQuery = { __typename?: 'Query', systemuser: { __typename?: 'systemuser', evo_job_titleid: string | null, businessunitid: string | null } | null };
|
||||
export type GetSystemUserQuery = { __typename?: 'Query', systemuser: { __typename?: 'systemuser', evo_job_titleid: string | null, businessunitid: string | null, roles: Array<{ __typename?: 'role', name: string | null } | null> | null } | null };
|
||||
|
||||
export type CoreAddProductTypesFieldsFragment = { __typename?: 'evo_addproduct_type', evo_graph_price: number | null, label: string | null, value: string | null };
|
||||
|
||||
@ -630,7 +630,7 @@ export const GetRewardConditionsDocument = {"kind":"Document","definitions":[{"k
|
||||
export const GetRewardConditionDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetRewardCondition"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"conditionId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_reward_condition"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_reward_conditionid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"conditionId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_reward_summ"}},{"kind":"Field","name":{"kind":"Name","value":"evo_reduce_reward"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_reward_summ"}},{"kind":"Field","name":{"kind":"Name","value":"evo_agency_agreementidData"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_required_reward"}},{"kind":"Field","name":{"kind":"Name","value":"evo_reward_without_other_agent"}},{"kind":"Field","name":{"kind":"Name","value":"evo_leasingobject_price"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_calc_reward_rules"}}]}}]}}]} as unknown as DocumentNode<GetRewardConditionQuery, GetRewardConditionQueryVariables>;
|
||||
export const GetSotCoefficientTypeDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetSotCoefficientType"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"evo_id"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_sot_coefficient_type"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"evo_id"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_sot_coefficient_typeid"}}]}}]}}]} as unknown as DocumentNode<GetSotCoefficientTypeQuery, GetSotCoefficientTypeQueryVariables>;
|
||||
export const GetCoefficientsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetCoefficients"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"jobTitleId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_coefficients"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}},{"kind":"Argument","name":{"kind":"Name","value":"evo_datefrom_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"lte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_dateto_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"gte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_job_titleid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"jobTitleId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_job_titleid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_sot_coefficient_typeid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_baseproducts"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_baseproductid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_id"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_sot_coefficient"}},{"kind":"Field","name":{"kind":"Name","value":"evo_corfficient_type"}},{"kind":"Field","name":{"kind":"Name","value":"evo_sot_coefficient_typeidData"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_id"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_correction_coefficient"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_period"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_period"}},{"kind":"Field","name":{"kind":"Name","value":"evo_season_type"}},{"kind":"Field","name":{"kind":"Name","value":"evo_graph_type"}},{"kind":"Field","name":{"kind":"Name","value":"evo_businessunits"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_sale_businessunitid"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_risk_delta"}}]}}]}}]} as unknown as DocumentNode<GetCoefficientsQuery, GetCoefficientsQueryVariables>;
|
||||
export const GetSystemUserDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetSystemUser"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"domainname"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"systemuser"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"domainname"},"value":{"kind":"Variable","name":{"kind":"Name","value":"domainname"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_job_titleid"}},{"kind":"Field","name":{"kind":"Name","value":"businessunitid"}}]}}]}}]} as unknown as DocumentNode<GetSystemUserQuery, GetSystemUserQueryVariables>;
|
||||
export const GetSystemUserDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetSystemUser"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"domainname"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"systemuser"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"domainname"},"value":{"kind":"Variable","name":{"kind":"Name","value":"domainname"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_job_titleid"}},{"kind":"Field","name":{"kind":"Name","value":"businessunitid"}},{"kind":"Field","name":{"kind":"Name","value":"roles"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}}]}}]}}]}}]} as unknown as DocumentNode<GetSystemUserQuery, GetSystemUserQueryVariables>;
|
||||
export const GetAddproductTypesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetAddproductTypes"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_types"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}},{"kind":"Argument","name":{"kind":"Name","value":"evo_datefrom_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"lte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_dateto_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"gte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CoreAddProductTypesFields"}},{"kind":"Field","name":{"kind":"Name","value":"evo_product_type"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CoreAddProductTypesFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"evo_addproduct_type"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_graph_price"}},{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_addproduct_typeid"}}]}}]} as unknown as DocumentNode<GetAddproductTypesQuery, GetAddproductTypesQueryVariables>;
|
||||
export const GetAddProductTypeDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetAddProductType"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"addproductTypeId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_type"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_addproduct_typeid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"addproductTypeId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_description"}},{"kind":"Field","name":{"kind":"Name","value":"evo_helpcard_type"}},{"kind":"Field","name":{"kind":"Name","value":"evo_planpayments"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","name":{"kind":"Name","value":"evo_cost_price_telematics_withoutnds"}},{"kind":"Field","name":{"kind":"Name","value":"evo_cost_equipment_withoutnds"}},{"kind":"Field","name":{"kind":"Name","value":"evo_cost_telematics_withoutnds"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_graph_price_withoutnds"}},{"kind":"Field","name":{"kind":"Name","value":"evo_cost_service_provider_withoutnds"}},{"kind":"Field","name":{"kind":"Name","value":"evo_retro_bonus_withoutnds"}},{"kind":"Field","name":{"kind":"Name","value":"evo_evokasko_calc_type"}},{"kind":"Field","name":{"kind":"Name","value":"evo_loss_kv"}},{"kind":"Field","name":{"kind":"Name","value":"evo_price_service_provider_withoutnds"}},{"kind":"Field","name":{"kind":"Name","value":"evo_graph_price"}}]}}]}}]} as unknown as DocumentNode<GetAddProductTypeQuery, GetAddProductTypeQueryVariables>;
|
||||
export const GetRegistrationTypesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetRegistrationTypes"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_types"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}},{"kind":"Argument","name":{"kind":"Name","value":"evo_datefrom_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"lte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_dateto_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"gte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_product_type"},"value":{"kind":"IntValue","value":"100000001"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CoreAddProductTypesFields"}},{"kind":"Field","name":{"kind":"Name","value":"evo_leasingobject_types"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_leasingobject_typeid"}}]}},{"kind":"Field","name":{"kind":"Name","value":"evo_whom_register"}},{"kind":"Field","name":{"kind":"Name","value":"evo_gibdd_region"}},{"kind":"Field","name":{"kind":"Name","value":"evo_pts_type"}},{"kind":"Field","name":{"kind":"Name","value":"evo_accountid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_towtruck"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CoreAddProductTypesFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"evo_addproduct_type"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_graph_price"}},{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_addproduct_typeid"}}]}}]} as unknown as DocumentNode<GetRegistrationTypesQuery, GetRegistrationTypesQueryVariables>;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { getUser } from '@/api/user/query';
|
||||
import initializeApollo from '@/apollo/client';
|
||||
import * as Calculation from '@/Components/Calculation';
|
||||
import { CRMError } from '@/Components/Common/Error';
|
||||
import { Error } from '@/Components/Common/Error';
|
||||
import Output from '@/Components/Output';
|
||||
import { useDefaultReactions } from '@/config/process';
|
||||
import { STALE_TIME } from '@/constants/request';
|
||||
import * as CRMTypes from '@/graphql/crm.types';
|
||||
import * as init from '@/process/init';
|
||||
import { min } from '@/styles/mq';
|
||||
import { dehydrate, QueryClient } from '@tanstack/react-query';
|
||||
@ -36,12 +36,12 @@ const Grid = styled(Box)`
|
||||
}
|
||||
`;
|
||||
|
||||
function Home({ error }) {
|
||||
function Home(props) {
|
||||
init.useMainData();
|
||||
init.useInsuranceData();
|
||||
useDefaultReactions();
|
||||
|
||||
if (error) return <CRMError error={error} />;
|
||||
if (props.statusCode !== 200) return <Error {...props} />;
|
||||
|
||||
return (
|
||||
<Grid>
|
||||
@ -60,21 +60,32 @@ export const getServerSideProps = async ({ req }) => {
|
||||
|
||||
const queryClient = new QueryClient();
|
||||
|
||||
const user = await queryClient.fetchQuery(
|
||||
['user'],
|
||||
({ signal }) =>
|
||||
getUser({
|
||||
headers: {
|
||||
cookie,
|
||||
},
|
||||
signal,
|
||||
}),
|
||||
{ staleTime: STALE_TIME }
|
||||
const user = await queryClient.fetchQuery(['user'], ({ signal }) =>
|
||||
getUser({
|
||||
headers: {
|
||||
cookie,
|
||||
},
|
||||
signal,
|
||||
})
|
||||
);
|
||||
|
||||
const apolloClient = initializeApollo();
|
||||
|
||||
try {
|
||||
const {
|
||||
data: { systemuser },
|
||||
} = await apolloClient.query({
|
||||
query: CRMTypes.GetSystemUserDocument,
|
||||
variables: {
|
||||
domainname: user.domainName,
|
||||
},
|
||||
});
|
||||
|
||||
if (!systemuser.roles.some((x) => x.name === 'МПЛ')) {
|
||||
return {
|
||||
props: { statusCode: 403 },
|
||||
};
|
||||
}
|
||||
const { values, options } = await init.getInitialData(apolloClient, user);
|
||||
|
||||
return {
|
||||
@ -85,12 +96,14 @@ export const getServerSideProps = async ({ req }) => {
|
||||
},
|
||||
initialApolloState: apolloClient.cache.extract(),
|
||||
initialQueryState: dehydrate(queryClient),
|
||||
statusCode: 200,
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
props: {
|
||||
error: JSON.stringify(error),
|
||||
statusCode: 500,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user