Skip to content

Commit

Permalink
Merge branch 'dataset_security_feature' of https://github.com/bcgov/b…
Browse files Browse the repository at this point in the history
…iohubbc-platform into dataset_security_feature
  • Loading branch information
NickPhura committed Dec 20, 2023
2 parents cd0d41b + 0cbf52f commit e755672
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
31 changes: 25 additions & 6 deletions app/src/components/security/SecuritiesDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import EditDialog from 'components/dialog/EditDialog';
import { ApplySecurityRulesI18N } from 'constants/i18n';
import { ISecurityRule } from 'hooks/api/useSecurityApi';
import { useApi } from 'hooks/useApi';
import { useDialogContext } from 'hooks/useContext';
import { useDialogContext, useSubmissionContext } from 'hooks/useContext';
import useDataLoader from 'hooks/useDataLoader';
import SecurityRuleForm, { ISecurityRuleFormikProps, SecurityRuleFormYupSchema } from './SecurityRuleForm';

interface ISecuritiesDialogProps {
Expand All @@ -16,12 +17,30 @@ const SecuritiesDialog = (props: ISecuritiesDialogProps) => {
const dialogContext = useDialogContext();
const api = useApi();

Check warning on line 18 in app/src/components/security/SecuritiesDialog.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/security/SecuritiesDialog.tsx#L16-L18

Added lines #L16 - L18 were not covered by tests

const submissionFeatureRulesDataLoader = useDataLoader(api.security.getSecurityRulesForSubmissions);
submissionFeatureRulesDataLoader.load(props.features);

Check warning on line 21 in app/src/components/security/SecuritiesDialog.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/security/SecuritiesDialog.tsx#L20-L21

Added lines #L20 - L21 were not covered by tests

const submissionContext = useSubmissionContext();

Check warning on line 23 in app/src/components/security/SecuritiesDialog.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/security/SecuritiesDialog.tsx#L23

Added line #L23 was not covered by tests
const securityRules = submissionContext.securityRulesDataLoader.data || [];

const initialAppliedSecurityRules: ISecurityRule[] = !submissionFeatureRulesDataLoader.data?.length
? []
: securityRules.filter((securityRule) => {
return submissionFeatureRulesDataLoader.data?.some(
(securityRecord) => securityRule.security_rule_id === securityRecord.security_rule_id

Check warning on line 30 in app/src/components/security/SecuritiesDialog.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/security/SecuritiesDialog.tsx#L29-L30

Added lines #L29 - L30 were not covered by tests
);
});

const handleSubmit = async (rules: ISecurityRule[]) => {
try {
await api.submissions.applySubmissionFeatureRules(
props.features,
rules.map((item) => item.security_rule_id)
);
await api.submissions

Check warning on line 36 in app/src/components/security/SecuritiesDialog.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/security/SecuritiesDialog.tsx#L34-L36

Added lines #L34 - L36 were not covered by tests
.applySubmissionFeatureRules(
props.features,
rules.map((item) => item.security_rule_id)

Check warning on line 39 in app/src/components/security/SecuritiesDialog.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/security/SecuritiesDialog.tsx#L39

Added line #L39 was not covered by tests
)
.then(() => {
submissionFeatureRulesDataLoader.refresh(props.features);

Check warning on line 42 in app/src/components/security/SecuritiesDialog.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/security/SecuritiesDialog.tsx#L42

Added line #L42 was not covered by tests
});

dialogContext.setSnackbar({

Check warning on line 45 in app/src/components/security/SecuritiesDialog.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/security/SecuritiesDialog.tsx#L45

Added line #L45 was not covered by tests
snackbarMessage: (
Expand Down Expand Up @@ -54,7 +73,7 @@ const SecuritiesDialog = (props: ISecuritiesDialogProps) => {
onSave={(values: ISecurityRuleFormikProps) => handleSubmit(values.rules)}

Check warning on line 73 in app/src/components/security/SecuritiesDialog.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/security/SecuritiesDialog.tsx#L73

Added line #L73 was not covered by tests
component={{
element: <SecurityRuleForm features={props.features} />,
initialValues: { rules: [] },
initialValues: { rules: initialAppliedSecurityRules },
validationSchema: SecurityRuleFormYupSchema
}}
/>
Expand Down
15 changes: 4 additions & 11 deletions app/src/components/security/SecurityRuleForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import Box from '@mui/material/Box';
import TextField from '@mui/material/TextField';
import { useFormikContext } from 'formik';
import { ISecurityRule } from 'hooks/api/useSecurityApi';
import { useApi } from 'hooks/useApi';
import { useSubmissionContext } from 'hooks/useContext';
import useDataLoader from 'hooks/useDataLoader';
import { useState } from 'react';
import { TransitionGroup } from 'react-transition-group';
import { alphabetizeObjects } from 'utils/Utils';
Expand All @@ -29,18 +27,13 @@ export const SecurityRuleFormYupSchema = yup.object().shape({
});

const SecurityRuleForm = (props: ISecurityRuleFormProps) => {
const api = useApi();
const submissionContext = useSubmissionContext();

const { handleSubmit, errors, values, setFieldValue } = useFormikContext<ISecurityRuleFormikProps>();
const { handleSubmit, errors, values, setFieldValue, initialValues } = useFormikContext<ISecurityRuleFormikProps>();
const [searchText, setSearchText] = useState('');

Check warning on line 31 in app/src/components/security/SecurityRuleForm.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/security/SecurityRuleForm.tsx#L29-L31

Added lines #L29 - L31 were not covered by tests

const submissionContext = useSubmissionContext();

Check warning on line 33 in app/src/components/security/SecurityRuleForm.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/security/SecurityRuleForm.tsx#L33

Added line #L33 was not covered by tests
const securityRules = submissionContext.securityRulesDataLoader.data || [];

const submissionFeatureRulesDataLoader = useDataLoader(api.security.getSecurityRulesForSubmissions);
submissionFeatureRulesDataLoader.load(props.features);

const showSecuredBanner = Boolean(submissionFeatureRulesDataLoader.data?.length);
const hasOneOrMoreRulesPreviouslyApplied = Boolean(initialValues.rules.length);

Check warning on line 36 in app/src/components/security/SecurityRuleForm.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/security/SecurityRuleForm.tsx#L36

Added line #L36 was not covered by tests

const handleAdd = (selected: ISecurityRule) => {
setFieldValue(`rules[${values.rules.length}]`, selected);

Check warning on line 39 in app/src/components/security/SecurityRuleForm.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/components/security/SecurityRuleForm.tsx#L38-L39

Added lines #L38 - L39 were not covered by tests
Expand All @@ -63,7 +56,7 @@ const SecurityRuleForm = (props: ISecurityRuleFormProps) => {
}}>
Specify reasons why this information should be secured.
</Typography>
{showSecuredBanner && (
{hasOneOrMoreRulesPreviouslyApplied && (
<Box mt={3}>
<Alert severity="info" variant="standard">
<AlertTitle>Security Applied</AlertTitle>
Expand Down

0 comments on commit e755672

Please sign in to comment.