Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const initialPolicy: Policy = {
SORT_lifecycleStage: '', // For internal use only.
SORT_enforcement: false, // For internal use only.
policyVersion: '',
serverPolicySections: [],
policySections: [
{
sectionName: 'Policy Section 1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ function preFormatNestedPolicyFields(policy: Policy): Policy {
}

const clientPolicy = cloneDeep(policy);
clientPolicy.serverPolicySections = policy.policySections;
// itreating through each value in a policy group in a policy section to parse value string
policy.policySections.forEach((policySection, sectionIdx) => {
const { policyGroups } = policySection;
Expand Down Expand Up @@ -420,21 +421,30 @@ function postFormatNestedPolicyFields(policy: Policy): Policy {
}

const serverPolicy = cloneDeep(policy);
// itereating through each value in a policy group in a policy section to format to a flat value string
policy.policySections.forEach((policySection, sectionIdx) => {
const { policyGroups } = policySection;
policyGroups.forEach((policyGroup, groupIdx) => {
const { values } = policyGroup;
values.forEach((value, valueIdx) => {
serverPolicy.policySections[sectionIdx].policyGroups[groupIdx].values[valueIdx] = {
value: formatValueStr(value as ValueObj, policyGroup.fieldName),
};
if (policy.criteriaLocked) {
serverPolicy.policySections = policy.serverPolicySections;
} else {
// itereating through each value in a policy group in a policy section to format to a flat value string
policy.policySections.forEach((policySection, sectionIdx) => {
const { policyGroups } = policySection;
policyGroups.forEach((policyGroup, groupIdx) => {
const { values } = policyGroup;
values.forEach((value, valueIdx) => {
serverPolicy.policySections[sectionIdx].policyGroups[groupIdx].values[
valueIdx
] = {
value: formatValueStr(value as ValueObj, policyGroup.fieldName),
};
});
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
delete serverPolicy.policySections[sectionIdx].policyGroups[groupIdx].fieldKey;
});
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
delete serverPolicy.policySections[sectionIdx].policyGroups[groupIdx].fieldKey;
});
});
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
delete serverPolicy.serverPolicySections;
return serverPolicy;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ export const policyConfigurationDescriptor: Descriptor[] = [
shortName: 'Exposed node port',
negatedName: `Exposed node port doesn't match`,
category: policyCriteriaCategories.NETWORKING,
type: 'number',
type: 'text',
placeholder: '22',
canBooleanLogic: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ import {
} from '@patternfly/react-core';

import { fetchAlert } from 'services/AlertsService';
import { preFormatPolicyFields } from 'Containers/Policies/Wizard/Form/utils';
import useFeatureFlagEnabled from 'hooks/useFeatureFlagEnabled';
import { knownBackendFlags } from 'utils/featureFlags';
import PolicyDetailContent from '../../Policies/PatternFly/Detail/PolicyDetailContent';
import { getClientWizardPolicy } from '../../Policies/PatternFly/policies.utils';
import DeploymentDetails from './DeploymentDetails';
import PolicyDetails from './PolicyDetails';
import EnforcementDetails from './EnforcementDetails';
import { Alert } from '../types/violationTypes';
import ViolationNotFoundPage from '../ViolationNotFoundPage';
Expand All @@ -30,7 +27,6 @@ function ViolationDetailsPage(): ReactElement {
const [isFetchingSelectedAlert, setIsFetchingSelectedAlert] = useState(false);

const { alertId } = useParams();
const isPoliciesPFEnabled = useFeatureFlagEnabled(knownBackendFlags.ROX_POLICIES_PATTERNFLY);

function handleTabClick(_, tabIndex) {
setActiveTabKey(tabIndex);
Expand Down Expand Up @@ -111,17 +107,13 @@ function ViolationDetailsPage(): ReactElement {
)}
<Tab eventKey={3} title={<TabTitleText>Policy</TabTitleText>}>
<PageSection variant="default">
{isPoliciesPFEnabled ? (
<>
<Title headingLevel="h3" className="pf-u-mb-md">
Policy overview
</Title>
<Divider component="div" className="pf-u-pb-md" />
<PolicyDetailContent policy={policy} />
</>
) : (
<PolicyDetails policy={preFormatPolicyFields(alert.policy)} />
)}
<>
<Title headingLevel="h3" className="pf-u-mb-md">
Policy overview
</Title>
<Divider component="div" className="pf-u-pb-md" />
<PolicyDetailContent policy={getClientWizardPolicy(policy)} />
</>
</PageSection>
</Tab>
</Tabs>
Expand Down
1 change: 1 addition & 0 deletions ui/apps/platform/src/types/policy.proto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export type Policy = {
SORT_lifecycleStage: string; // For internal use only.
SORT_enforcement: boolean; // For internal use only.
policyVersion: string;
serverPolicySections: PolicySection[]; // For internal use only.
policySections: PolicySection[];
mitreAttackVectors: PolicyMitreAttackVector[];
readonly criteriaLocked: boolean; // If true, the policy's criteria fields are rendered read-only.
Expand Down