Skip to content

Commit

Permalink
fix: update Mapping File's modifiedDate after each edit
Browse files Browse the repository at this point in the history
Update a Mapping File's "last modified date" after each edit.

refactor: new Mapping Files must only declare properties that cannot populate automatically
  • Loading branch information
mikecarenzo authored Feb 16, 2024
1 parent c27d7ae commit 0ca0e75
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class UniversalSchemaMappingFileSerializer extends MappingFileSerializer
public deserialize(file: string): MappingFileExport {
const json = JSON.parse(file) as UniversalSchemaMappingFile;
// Parse mapping objects
const mapping_objects = json.mapping_objects.map(
const mapping_objects = (json.mapping_objects ?? []).map(
o => this.toMappingObjectExport(o, json)
);
// Parse mapping file
Expand All @@ -184,11 +184,11 @@ export class UniversalSchemaMappingFileSerializer extends MappingFileSerializer
source_version : meta.mapping_framework_version,
target_framework : `mitre_attack_${ meta.technology_domain }`,
target_version : meta.attack_version,
author : meta.author,
author_contact : meta.contact,
author_organization : meta.organization,
creation_date : new Date(meta.creation_date),
modified_date : new Date(meta.last_update),
author : meta.author ?? null,
author_contact : meta.contact ?? null,
author_organization : meta.organization ?? null,
creation_date : new Date(meta.creation_date ?? Date.now()),
modified_date : new Date(meta.last_update ?? Date.now()),
capability_groups : meta.capability_groups,
mapping_types : meta.mapping_types,
mapping_statuses: {
Expand Down Expand Up @@ -418,15 +418,15 @@ type UniversalSchemaMappingFile = {
technology_domain : string,
mapping_framework : string,
mapping_framework_version : string,
author : string | null,
contact : string | null,
organization : string | null,
creation_date : string,
last_update : string,
author? : string | null,
contact? : string | null,
organization? : string | null,
creation_date? : string,
last_update? : string,
mapping_types : UniversalSchemaMappingTypes,
capability_groups : UniversalSchemaCapabilityGroups
},
mapping_objects : UniversalSchemaMappingObject[]
mapping_objects? : UniversalSchemaMappingObject[]
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class MappingFile {
/**
* The file's last modified date.
*/
public readonly modifiedDate: Date;
public modifiedDate: Date;

/**
* The file's capability groups.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export class MappingFileAuthority {

// Create mapping file
const mappingFile = new MappingFile({
creationDate : file.creation_date ?? new Date(),
modifiedDate : file.modified_date ?? new Date(),
creationDate : file.creation_date,
modifiedDate : file.modified_date,
mappingObjectTemplate
}, id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ export class MappingFileEditor extends EventEmitter<MappingFileEditorEvents> {
public executeDirectives(args: DirectiveArguments) {
// Request autosave
if (args.directives & EditorDirective.Autosave) {
// Update last modified
this.file.modifiedDate = new Date();
// Request autosave
this.requestAutosave();
}
// Update reindex file
Expand Down

0 comments on commit 0ca0e75

Please sign in to comment.