Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NOT_PRESENT operator for CPE and PURL #1053

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,8 @@
"is": "is",
"is_not": "is not",
"matches": "matches",
"no_match": "does not match"
"no_match": "does not match",
"not_present": "not present"
},
"policy_violation": {
"fails": "Violation Failures",
Expand Down
53 changes: 48 additions & 5 deletions src/views/policy/PolicyCondition.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
v-else-if="
subject !== 'COORDINATES' &&
subject !== 'VERSION_DISTANCE' &&
subject !== 'CPE' &&
subject !== 'PACKAGE_URL' &&
!isSubjectSelectable
"
id="input-value"
Expand All @@ -51,6 +53,32 @@
:debounce-events="'keyup'"
/>

<b-input-group-form-input
v-else-if="
(subject === 'CPE' && operator !== 'NOT_PRESENT') ||
(subject === 'PACKAGE_URL' && operator !== 'NOT_PRESENT')
"
id="input-value"
required="true"
type="text"
v-model="value"
lazy="true"
v-debounce:750ms="saveCondition"
:tooltip="valueInputTooltip()"
:debounce-events="'keyup'"
/>

<template
v-else-if="
(subject === 'CPE' && operator === 'NOT_PRESENT') ||
(subject === 'PACKAGE_URL' && operator === 'NOT_PRESENT')
"
>
<div style="display: none">
{{ saveCondition() }}
</div>
</template>

<b-input-group v-else-if="subject === 'COORDINATES'">
<b-form-input
id="input-value-coordinates-group"
Expand Down Expand Up @@ -223,6 +251,11 @@ export default {
{ value: 'MATCHES', text: this.$t('operator.matches') },
{ value: 'NO_MATCH', text: this.$t('operator.no_match') },
],
regexOperatorsCpePurl: [
{ value: 'MATCHES', text: this.$t('operator.matches') },
{ value: 'NOT_PRESENT', text: this.$t('operator.not_present') },
{ value: 'NO_MATCH', text: this.$t('operator.no_match') },
],
numericOperators: [
{ value: 'NUMERIC_GREATER_THAN', text: '>' },
{ value: 'NUMERIC_LESS_THAN', text: '<' },
Expand Down Expand Up @@ -336,10 +369,10 @@ export default {
this.retrieveLicenseGroups();
break;
case 'PACKAGE_URL':
this.operators = this.regexOperators;
this.operators = this.regexOperatorsCpePurl;
break;
case 'CPE':
this.operators = this.regexOperators;
this.operators = this.regexOperatorsCpePurl;
break;
case 'SWID_TAGID':
this.operators = this.regexOperators;
Expand Down Expand Up @@ -418,7 +451,15 @@ export default {
},
saveCondition: function () {
let dynamicValue = this.createDynamicValue();
if (!this.subject || !this.operator || !dynamicValue) {
if (
!this.subject ||
!this.operator ||
(!dynamicValue &&
!(
(this.subject === 'CPE' && this.operator === 'NOT_PRESENT') ||
(this.subject === 'PACKAGE_URL' && this.operator === 'NOT_PRESENT')
))
) {
return;
}
if (this.uuid) {
Expand All @@ -428,7 +469,8 @@ export default {
uuid: this.uuid,
subject: this.subject,
operator: this.subject === 'COMPONENT_HASH' ? 'IS' : this.operator,
value: dynamicValue,
value:
this.operator === 'NOT_PRESENT' ? 'NOT_PRESENT' : dynamicValue,
})
.then((response) => {
this.uuid = response.data.uuid;
Expand All @@ -446,7 +488,8 @@ export default {
.put(url, {
subject: this.subject,
operator: this.subject === 'COMPONENT_HASH' ? 'IS' : this.operator,
value: dynamicValue,
value:
this.operator === 'NOT_PRESENT' ? 'NOT_PRESENT' : dynamicValue,
})
.then((response) => {
this.uuid = response.data.uuid;
Expand Down
Loading