Skip to content

Commit

Permalink
Fix/467 (#506)
Browse files Browse the repository at this point in the history
* update revoke/deprecate logic

* code smell

* update changelog

* minor update
  • Loading branch information
clemiller authored Oct 3, 2023
1 parent 8f80b4c commit 264a93e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
31 changes: 9 additions & 22 deletions app/src/app/components/object-status/object-status.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class ObjectStatusComponent implements OnInit {
this.objects = data.data;
this.object = this.objects.find(object => object.stixID === this.editorService.stixId);
if (this.object) {
if (this.object.workflow && this.object.workflow.state) {
if (this.object.workflow?.state) {
this.statusControl.setValue(this.object.workflow.state);
}
this.revoked = this.object.revoked;
Expand Down Expand Up @@ -155,32 +155,18 @@ export class ObjectStatusComponent implements OnInit {
complete: () => { revokedSubscription.unsubscribe(); }
});
} else {
// deprecate the 'revoked-by' relationship
let revokedRelationships = this.relationships.filter(relationship => relationship.relationship_type == 'revoked-by');
for (let relationship of revokedRelationships) {
let other_obj: any;
if (relationship.source_object.stix.id == this.object.stixID) other_obj = relationship.target_object.stix;
else other_obj = relationship.source_object.stix;

if (!this.isDeprecatedOrRevoked(other_obj)) {
relationship.deprecated = true;
relationship.save(this.restAPIService);
}
// unrevoke object, deprecate the 'revoked-by' relationship
// this is the only case in which a 'revoked-by' relationship is deprecated
let revokedRelationship = this.relationships.find(r => r.relationship_type == 'revoked-by' && r.source_ref == this.object.stixID);
if (revokedRelationship) {
revokedRelationship.deprecated = true;
revokedRelationship.save(this.restAPIService);
}
// un-revoke object
this.object.revoked = false;
this.save();
}
}

/**
* Check if the given object is deprecated or revoked
* @param object source or target object of a relationship
*/
private isDeprecatedOrRevoked(object: any) {
return ('x_mitre_deprecated' in object && object.x_mitre_deprecated) || ('revoked' in object && object.revoked);
}

/**
* Handle the selection for deprecating or un-deprecating an object
* @param event deprecate selection
Expand Down Expand Up @@ -225,7 +211,8 @@ export class ObjectStatusComponent implements OnInit {

// update relationships with the object
for (let relationship of this.relationships) {
if (!relationship.deprecated && relationship.relationship_type != 'subtechnique-of') {
// do not deprecate 'subtechnique-of' or 'revoked-by' relationships
if (!relationship.deprecated && !['subtechnique-of', 'revoked-by'].includes(relationship.relationship_type)) {
relationship.deprecated = true;
saves.push(relationship.save(this.restAPIService));
}
Expand Down
7 changes: 5 additions & 2 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@

## Changes Staged on Develop

#### New Features in x.x.x
- Added ability to create and edit Asset objects.
#### New Features in 2.1.0
- Added the ability to create, view, and edit Asset objects.

#### Fixes in 2.1.0
- Fixed an issue where revoking or deprecating an object would deprecate all `revoked-by` relationships with the object. See [frontend#467](https://github.com/center-for-threat-informed-defense/attack-workbench-frontend/issues/467).

## 21 September 2023

Expand Down

0 comments on commit 264a93e

Please sign in to comment.