Skip to content

Commit

Permalink
Merge branch 'SIMSBIOHUB-428' of github.com:bcgov/biohubbc-platform i…
Browse files Browse the repository at this point in the history
…nto SIMSBIOHUB-428
  • Loading branch information
curtisupshall committed Jan 12, 2024
2 parents c64ff61 + f501103 commit 04a96c1
Show file tree
Hide file tree
Showing 8 changed files with 984 additions and 752 deletions.
1,693 changes: 967 additions & 726 deletions api/package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export function patchSecurityRulesOnSubmissionFeatures(): RequestHandler {

const submissionFeatureIds: number[] = req.body.submissionFeatureIds;
const applyRuleIds: number[] = req.body.applyRuleIds;
const removeRuleIds: number[] = req.body.applyRuleIds;
const removeRuleIds: number[] = req.body.removeRuleIds;

try {
await connection.open();
Expand Down
3 changes: 3 additions & 0 deletions api/src/repositories/security-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ export class SecurityRepository extends BaseRepository {
submissionFeatureIds: number[],
securityRuleIds: number[]
): Promise<SubmissionFeatureSecurityRecord[]> {
defaultLog.debug({ label: 'applySecurityRulesToSubmissionFeatures', submissionFeatureIds, securityRuleIds });

const queryValues = submissionFeatureIds.flatMap((submissionFeatureId) => {
return securityRuleIds.flatMap((securityRuleId) => `(${submissionFeatureId}, ${securityRuleId}, 'NOW()')`);
});
Expand Down Expand Up @@ -413,6 +415,7 @@ export class SecurityRepository extends BaseRepository {
removeRuleIds: number[]
): Promise<SubmissionFeatureSecurityRecord[]> {
defaultLog.debug({ label: 'removeSecurityRulesFromSubmissionFeatures', submissionFeatureIds, removeRuleIds });

const queryBuilder = getKnex()
.queryBuilder()
.delete()
Expand Down
2 changes: 2 additions & 0 deletions api/src/services/security-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ export class SecurityService extends DBService {
applyRuleIds: number[],
removeRuleIds: number[]
): Promise<void> {
defaultLog.debug({ label: 'patchSecurityRulesOnSubmissionFeatures', applyRuleIds, removeRuleIds });

if (!submissionFeatureIds.length) {
return;
}
Expand Down
13 changes: 1 addition & 12 deletions app/src/components/security/SecurityRuleActionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,7 @@ const SecurityRuleActionCard = (props: ISecurityRuleActionCardProps) => {
justifyContent: 'space-between',
background: grey[100]
}}>
<SecurityRuleCard
{...rest}
// TODO remove this
// actionContent={
// props.action === 'apply'
// ? <FormHelperText sx={(theme) => ({ color: theme.palette.info.dark })}>Will be applied to all features</FormHelperText>
// : (props.action === 'remove'
// ? <FormHelperText sx={(theme) => ({ color: theme.palette.error.main })}>Will be removed from all features</FormHelperText>
// : <></>
// )
// }
/>
<SecurityRuleCard {...rest} />
{props.action === 'apply' ? (
<IconButton onClick={() => onRemove()} aria-label="Remove security rule">
<Icon path={mdiClose} size={1} />
Expand Down
13 changes: 6 additions & 7 deletions app/src/components/security/SecurityRuleCard.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Box, Typography } from '@mui/material';
import { ReactNode } from 'react';
import { Stack } from '@mui/system';

export interface ISecurityRuleCardProps {
key?: string | number;
title: string;
category: string;
description: string;
featureMembers?: string[];
actionContent?: ReactNode;
}

const SecurityRuleCard = (props: ISecurityRuleCardProps) => {
return (
<Box>
Expand Down Expand Up @@ -41,15 +41,14 @@ const SecurityRuleCard = (props: ISecurityRuleCardProps) => {
}}>
{props.description}
</Typography>
{props.actionContent}
{props.featureMembers?.length && (
<Box component="ul" pl={4} mb={0} mt={1}>
{props.featureMembers && props.featureMembers?.length && (
<Stack component="ul" mt={1} pl={0} mb={0} display="flex" flexDirection="row" gap={2}>
{props.featureMembers.map((featureMember) => (
<Typography key={featureMember} variant="body2" color="textSecondary" component="li">
<Typography variant="body2" color="textSecondary" sx={{ display: 'block' }} component="li">
{featureMember}
</Typography>
))}
</Box>
</Stack>
)}
</Box>
);
Expand Down
8 changes: 3 additions & 5 deletions app/src/components/security/SecurityRuleForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useSubmissionContext } from 'hooks/useContext';
import { IPatchFeatureSecurityRules } from 'interfaces/useSecurityApi.interface';
import { useMemo, useState } from 'react';
import { TransitionGroup } from 'react-transition-group';
import { alphabetizeObjects } from 'utils/Utils';
import { alphabetizeObjects, pluralize as p } from 'utils/Utils';
import SecurityRuleActionCard from './SecurityRuleActionCard';
import SecurityRuleCard from './SecurityRuleCard';

Expand Down Expand Up @@ -99,9 +99,6 @@ const SecurityRuleForm = () => {
);
}, [initialAppliedSecurityRules, submissionFeatureGroupsDataLoader.data]);

console.log({ groupedAppliedSecurityRules });
console.log({ test: submissionFeatureGroupsDataLoader.data });

const { previosulyUnappliedRules } = useMemo(
function () {
const previouslyAppliedRules: ISecurityRuleAndCategory[] = [];
Expand Down Expand Up @@ -289,7 +286,8 @@ const SecurityRuleForm = () => {
category={group.securityRule.category_name}
description={group.securityRule.description}
featureMembers={group.appliedFeatureGroups.map(
(featureGroup) => `${featureGroup.displayName} (${featureGroup.numFeatures})`
(featureGroup) =>
`${p(featureGroup.numFeatures, featureGroup.displayName)} (${featureGroup.numFeatures})`
)}
onRemove={() => toggleStageRemove(group.securityRule)}
/>
Expand Down
2 changes: 1 addition & 1 deletion app/src/constants/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const ApplySecurityRulesI18N = {
.filter(Boolean)
.join(' and ');

return `Successfully ${appliedRemoved} to ${featureCount} ${p(featureCount, 'feature')}.`;
return `Successfully ${appliedRemoved} for ${featureCount} ${p(featureCount, 'feature')}.`;
},

applySecurityRulesErrorTitle: 'Error Applying Security',
Expand Down

0 comments on commit 04a96c1

Please sign in to comment.