Skip to content

Commit

Permalink
Merge pull request #312 from multiflexi/attr_desc
Browse files Browse the repository at this point in the history
Attribute description - CWE
  • Loading branch information
Progress1 authored Jun 26, 2024
2 parents bdfd098 + beedecb commit 99957d1
Show file tree
Hide file tree
Showing 8 changed files with 921 additions and 270 deletions.
32 changes: 32 additions & 0 deletions src/core/migrations/versions/90249a322ae1_add_value_descriptipn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Add value description to report item attribute table
Revision ID: 90249a322ae1
Revises: 57d784d699d9
Create Date: 2024-02-25 19:00:13.825003
"""

from alembic import op
import sqlalchemy as sa
from sqlalchemy.engine.reflection import Inspector


# revision identifiers, used by Alembic.
revision = "90249a322ae1"
down_revision = "57d784d699d9"
branch_labels = None
depends_on = None


def upgrade():
conn = op.get_bind()
inspector = Inspector.from_engine(conn)
if "value_description" not in [column["name"] for column in inspector.get_columns("report_item_attribute")]:
op.add_column("report_item_attribute", sa.Column("value_description", sa.String(), nullable=True))


def downgrade():
conn = op.get_bind()
inspector = Inspector.from_engine(conn)
if "value_description" in [column["name"] for column in inspector.get_columns("report_item_attribute")]:
op.drop_column("report_item_attribute", "value_description")
687 changes: 542 additions & 145 deletions src/core/model/report_item.py

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion src/gui/src/components/analyze/NewReportItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ export default {
for (let k = 0; k < this.attribute_groups[i].attribute_group_items[j].values.length; k++) {
let value = this.attribute_groups[i].attribute_group_items[j].values[k].value
let value_description = this.attribute_groups[i].attribute_group_items[j].values[k].value_description
if (this.attribute_groups[i].attribute_group_items[j].attribute_group_item.attribute.type === 'CPE') {
value = value.replace("*", "%")
} else if (this.attribute_groups[i].attribute_group_items[j].attribute_group_item.attribute.type === 'BOOLEAN') {
Expand All @@ -448,6 +449,7 @@ export default {
this.report_item.attributes.push({
id: -1,
value: value,
value_description: value_description,
attribute_group_item_id: this.attribute_groups[i].attribute_group_items[j].attribute_group_item.id
})
}
Expand Down Expand Up @@ -649,6 +651,7 @@ export default {
if (data.attributes[k].attribute_group_item_id === this.selected_type.attribute_groups[i].attribute_group_items[j].id) {
let value = data.attributes[k].value
let value_description = data.attributes[k].value_description
if (this.selected_type.attribute_groups[i].attribute_group_items[j].attribute.type === 'CPE') {
value = value.replace("%", "*")
} else if (this.selected_type.attribute_groups[i].attribute_group_items[j].attribute.type === 'BOOLEAN') {
Expand All @@ -664,6 +667,7 @@ export default {
id: data.attributes[k].id,
index: values.length,
value: value,
value_description: value_description,
binary_mime_type: data.attributes[k].binary_mime_type,
binary_size: data.attributes[k].binary_size,
binary_description: data.attributes[k].binary_description,
Expand All @@ -690,6 +694,7 @@ export default {
id: data.remote_report_items[l].attributes[k].id,
index: values.length,
value: value,
value_description: value_description,
last_updated: data.remote_report_items[l].attributes[k].last_updated,
binary_mime_type: data.remote_report_items[l].attributes[k].binary_mime_type,
binary_size: data.remote_report_items[l].attributes[k].binary_size,
Expand Down Expand Up @@ -858,4 +863,4 @@ export default {
this.$root.$off('report-item-updated', this.report_item_updated);
}
}
</script>
</script>
203 changes: 95 additions & 108 deletions src/gui/src/components/common/EnumSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,27 @@
<v-btn v-bind="UI.BUTTON.CLOSE_ICON" @click="cancel">
<v-icon>{{ UI.ICON.CLOSE }}</v-icon>
</v-btn>
<v-toolbar-title>{{$t('attribute.select_enum')}}</v-toolbar-title>
<v-toolbar-title>{{ $t('attribute.select_enum') }}</v-toolbar-title>
</v-toolbar>

<v-card>
<v-card-text>
<v-data-table
:headers="headers"
:items="attribute_enums"
:server-items-length="attribute_enums_total_count"
@update:options="updateOptions"
:items-per-page="25"
class="elevation-1 enum_selector"
:page.sync="current_page"
@click:row="clickRow"
:footer-props="{
showFirstLastPage: true,
itemsPerPageOptions: [25, 50, 100],
showCurrentPage: true
}"

>
<v-data-table :headers="headers" :items="attribute_enums"
:server-items-length="attribute_enums_total_count" @update:options="updateOptions"
:items-per-page="25" class="elevation-1 enum_selector" :page.sync="current_page"
@click:row="clickRow" :footer-props="{
showFirstLastPage: true,
itemsPerPageOptions: [25, 50, 100],
showCurrentPage: true
}">
<template v-slot:top>
<v-toolbar flat>
<v-toolbar-title>{{$t('attribute.attribute_constants')}}</v-toolbar-title>
<v-divider
class="mx-4"
inset
vertical
></v-divider>
<v-toolbar-title>{{ $t('attribute.attribute_constants') }}</v-toolbar-title>
<v-divider class="mx-4" inset vertical></v-divider>
<v-spacer></v-spacer>
<v-text-field
v-model="search"
append-icon="mdi-magnify"
:label="$t('attribute.search')"
v-on:keyup="filterSearch"
single-line
hide-details
></v-text-field>
<v-text-field v-model="search" append-icon="mdi-magnify"
:label="$t('attribute.search')" v-on:keyup="filterSearch" single-line
hide-details></v-text-field>
</v-toolbar>
</template>

Expand All @@ -59,92 +42,96 @@
</template>

<script>
import {getAttributeEnums} from "@/api/analyze";
import {getCPEAttributeEnums} from "@/api/assets";
import { getAttributeEnums } from "@/api/analyze";
import { getCPEAttributeEnums } from "@/api/assets";
export default {
name: "EnumSelector",
props: {
attribute_id: Number,
value_index: Number,
cpe_only: Boolean
},
data: () => ({
visible: false,
search: "",
headers: [
{
text: 'Value',
align: 'left',
sortable: false,
value: 'value',
},
{text: 'Description', value: 'description', sortable: false},
],
current_page: 1,
current_page_size: 25,
attribute_enums: [],
attribute_enums_total_count: 0
}),
methods: {
show() {
this.updateAttributeEnums()
this.visible = true;
export default {
name: "EnumSelector",
props: {
attribute_id: Number,
value_index: Number,
cpe_only: Boolean
},
data: () => ({
visible: false,
search: "",
headers: [
{
text: 'Value',
align: 'left',
sortable: false,
value: 'value',
},
cancel() {
this.visible = false
{
text: 'Description',
value: 'description',
sortable: false
},
],
current_page: 1,
current_page_size: 25,
attribute_enums: [],
attribute_enums_total_count: 0
}),
methods: {
show() {
this.updateAttributeEnums()
this.visible = true;
},
filterSearch() {
clearTimeout(this.timeout);
cancel() {
this.visible = false
},
let self = this
this.timeout = setTimeout(function () {
self.current_page = 1
self.updateAttributeEnums()
}, 300);
},
filterSearch() {
clearTimeout(this.timeout);
clickRow(event, row) {
this.$emit('enum-selected', {index: this.value_index, value: row.item.value})
this.visible = false
},
let self = this
this.timeout = setTimeout(function () {
self.current_page = 1
self.updateAttributeEnums()
}, 300);
},
updateAttributeEnums() {
if (this.cpe_only === true) {
getCPEAttributeEnums({
search: this.search,
offset: (this.current_page - 1) * this.current_page_size,
limit: this.current_page_size
}).then((response) => {
this.processResponse(response)
})
} else {
getAttributeEnums({
attribute_id: this.attribute_id,
search: this.search,
offset: (this.current_page - 1) * this.current_page_size,
limit: this.current_page_size
}).then((response) => {
this.processResponse(response)
})
}
},
clickRow(event, row) {
this.$emit('enum-selected', { index: this.value_index, value: row.item.value, value_description: row.item.description })
this.visible = false
},
processResponse(response) {
this.attribute_enums = []
this.attribute_enums_total_count = response.data.total_count
for (let i = 0; i < response.data.items.length; i++) {
this.attribute_enums.push(response.data.items[i])
}
},
updateAttributeEnums() {
if (this.cpe_only === true) {
getCPEAttributeEnums({
search: this.search,
offset: (this.current_page - 1) * this.current_page_size,
limit: this.current_page_size
}).then((response) => {
this.processResponse(response)
})
} else {
getAttributeEnums({
attribute_id: this.attribute_id,
search: this.search,
offset: (this.current_page - 1) * this.current_page_size,
limit: this.current_page_size
}).then((response) => {
this.processResponse(response)
})
}
},
updateOptions(options) {
this.current_page = options.page
this.current_page_size = options.itemsPerPage
this.updateAttributeEnums()
processResponse(response) {
this.attribute_enums = []
this.attribute_enums_total_count = response.data.total_count
for (let i = 0; i < response.data.items.length; i++) {
this.attribute_enums.push(response.data.items[i])
}
},
updateOptions(options) {
this.current_page = options.page
this.current_page_size = options.itemsPerPage
this.updateAttributeEnums()
}
}
</script>
}
</script>
5 changes: 5 additions & 0 deletions src/gui/src/components/common/attribute/AttributeCWE.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
:class="getLockedStyle(index)" :disabled="values[index].locked || !canModify"
@fo="firstOne(index)">
</v-text-field>
<v-text-field v-model="values[index].value_description" dense :label="$t('attribute.description')"
@focus="onFocus(index)" @blur="onBlur(index)" @keyup="onKeyUp(index)"
:class="getLockedStyle(index)" :disabled="values[index].locked || !canModify"
@fo="firstOne(index)">
</v-text-field>
</template>
</AttributeValueLayout>

Expand Down
Loading

0 comments on commit 99957d1

Please sign in to comment.