Skip to content

Commit

Permalink
Merge branch 'main' of github.com:OWASP/threat-dragon
Browse files Browse the repository at this point in the history
  • Loading branch information
jgadsden committed Aug 18, 2024
2 parents 63152ae + 9d40f8c commit 629c352
Show file tree
Hide file tree
Showing 4 changed files with 326 additions and 11 deletions.
4 changes: 4 additions & 0 deletions td.vue/src/components/GraphMeta.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
<font-awesome-icon icon="plus"></font-awesome-icon>
{{ $t('threats.newThreatByType') }}
</a>
<a href="javascript:void(0)" v-if="!!cellRef" @click="AddThreatByContext()" class="new-threat-by-type m-2">
<font-awesome-icon icon="plus"></font-awesome-icon>
{{ $t('threats.newThreatByContext') }}
</a>
</b-col>
</b-row>
</template>
Expand Down
2 changes: 2 additions & 0 deletions td.vue/src/components/ThreatEditDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ export default {
Object.keys(threatTypes).forEach((type) => {
res.push(this.$t(type));
}, this);
if(!res.includes(this.threat.type))
res.push(this.threat.type);
return res;
},
statuses() {
Expand Down
45 changes: 34 additions & 11 deletions td.vue/src/components/ThreatSuggestDialog.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<template>
<div>
<b-modal
v-if="!!threat"
id="threat-edit"
size="lg"
ok-variant="primary"
Expand Down Expand Up @@ -36,7 +35,7 @@
<b-form-select
id="threat-type"
v-model="threat.type"
:options="threatTypes">
:options="types">
</b-form-select>
</b-form-group>
</b-col>
Expand Down Expand Up @@ -162,6 +161,7 @@ import { CELL_DATA_UPDATED} from '@/store/actions/cell.js';
import tmActions from '@/store/actions/threatmodel.js';
import dataChanged from '@/service/x6/graph/data-changed.js';
import threatModels from '@/service/threats/models/index.js';
import {GetContextSuggestions} from '@/service/threats/oats/context-generator.js';
export default {
name: 'TdThreatSuggest',
computed: {
Expand Down Expand Up @@ -198,31 +198,54 @@ export default {
},
data() {
return {
suggestions:[],
types: [],
threat: {},
index:0
};
},
methods: {
showModal() {
this.modalTitle;
this.threat = createNewTypedThreat(this.modelType,this.cellRef.data.type,this.threatTop+1);
showModal(type) {
this.index = 0;
this.threat.type = this.threatTypes[0];
const tmpThreat = createNewTypedThreat(this.modelType,this.cellRef.data.type,this.threatTop+1);
this.types = [...this.threatTypes];
if(type=='type'){
this.threatTypes.map((t,ind)=>{
console.log(t);
this.suggestions.push({...tmpThreat});
this.suggestions[ind].type=t;
});
} else {
this.suggestions = GetContextSuggestions(this.cellRef.data,this.modelType).map((suggestion)=>{
tmpThreat.title = suggestion.title;
tmpThreat.type = this.$t(suggestion.type);
if(!this.types.includes(tmpThreat.type)&&tmpThreat.type!=='')
this.types.push(tmpThreat.type);
tmpThreat.description = suggestion.description;
tmpThreat.mitigation = suggestion.mitigation;
console.log(tmpThreat);
return {...tmpThreat};
});
}
if(this.suggestions.length)
this.threat = this.suggestions[0];
this.$refs.editModal.show();
},
hideModal(){
this.threat={};
this.suggestions = [];
this.types = [];
this.index=0;
this.$refs.editModal.hide();
},
next(){
this.index++;
if(this.index>=this.threatTypes.length){
this.$refs.editModal.hide();
if(this.index>=this.suggestions.length){
this.hideModal();
this.index=0;
return;
}
this.threat.type = this.threatTypes[this.index];
this.threat = this.suggestions[this.index];
},
acceptSuggestion(){
const objRef = this.cellRef.data;
Expand All @@ -233,7 +256,7 @@ export default {
}
if(objRef.threatFrequency){
Object.keys(objRef.threatFrequency).forEach((k)=>{
if(this.$t(`threats.model.${this.modelType.toLowerCase()}.${k}`)===this.threat.type)
if(this.$t(`threats.model.${this.modelType.toLowerCase()}.${k}`)===this.threat.type&&this.threatTypes.includes(this.threat.type))
objRef.threatFrequency[k]++;
});
}
Expand All @@ -250,7 +273,7 @@ export default {
previous(){
if(this.index>0){
this.index--;
this.threat.type = this.threatTypes[this.index];
this.threat = this.suggestions[this.index];
}
}
}
Expand Down
Loading

0 comments on commit 629c352

Please sign in to comment.