-
-
Notifications
You must be signed in to change notification settings - Fork 342
Add EvidenceStore for tracking activity evidence (#496) #501
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
Open
sawankshrma
wants to merge
5
commits into
devsecopsmaturitymodel:main
Choose a base branch
from
sawankshrma:team_evidence
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+227
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1be4dff
add evidence data model in the new EvidenceStore
sawankshrma 656d972
implement loading team evidence from YAML and localStorage
sawankshrma 1169c45
Changed -addEvidenceData- from skip-on-duplicate to replace-on-duplic…
sawankshrma 82e7bc1
new uuid types
sawankshrma 402c5ab
fix: check teamEvidenceFile instead of teamProgressFile
sawankshrma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,197 @@ | ||
| import { YamlService } from '../service/yaml-loader/yaml-loader.service'; | ||
| import { ActivityId, EvidenceId } from './types'; | ||
|
|
||
| export interface EvidenceAttachment { | ||
| type: string; // e.g. 'document', 'image', 'link' | ||
| externalLink: string; // URL | ||
| } | ||
|
|
||
| export interface EvidenceEntry { | ||
| id: EvidenceId; // stable UUID for this entry | ||
| teams: string[]; | ||
| title: string; | ||
| evidenceRecorded: string; // ISO date string | ||
| reviewer?: string; | ||
| description: string; | ||
| attachment?: EvidenceAttachment[]; | ||
| } | ||
|
|
||
| export type EvidenceData = Record<ActivityId, EvidenceEntry[]>; | ||
|
|
||
| const LOCALSTORAGE_KEY: string = 'evidence'; | ||
|
|
||
| export class EvidenceStore { | ||
| private yamlService: YamlService = new YamlService(); | ||
| private _evidence: EvidenceData = {}; | ||
|
|
||
| // ─── Lifecycle ──────────────────────────────────────────── | ||
|
|
||
| public initFromLocalStorage(): void { | ||
| const stored = this.retrieveStoredEvidence(); | ||
| if (stored) { | ||
| this.addEvidenceData(stored); | ||
| } | ||
| } | ||
|
|
||
| // ─── Accessors ──────────────────────────────────────────── | ||
|
|
||
| public getEvidenceData(): EvidenceData { | ||
| return this._evidence; | ||
| } | ||
|
|
||
| public getEvidence(activityUuid: ActivityId): EvidenceEntry[] { | ||
| return this._evidence[activityUuid] || []; | ||
| } | ||
|
|
||
| public hasEvidence(activityUuid: ActivityId): boolean { | ||
| return (this._evidence[activityUuid]?.length || 0) > 0; | ||
| } | ||
|
|
||
| public getEvidenceCount(activityUuid: ActivityId): number { | ||
| return this._evidence[activityUuid]?.length ?? 0; | ||
| } | ||
|
|
||
| public getTotalEvidenceCount(): number { | ||
| let count = 0; | ||
| for (const uuid in this._evidence) { | ||
| count += this._evidence[uuid].length; | ||
| } | ||
| return count; | ||
| } | ||
|
|
||
| public getActivityUuidsWithEvidence(): ActivityId[] { | ||
| return Object.keys(this._evidence).filter(uuid => this._evidence[uuid].length > 0); | ||
| } | ||
|
|
||
| // ─── Mutators ──────────────────────────────────────────── | ||
|
|
||
| public addEvidenceData(newEvidence: EvidenceData): void { | ||
| if (!newEvidence) return; | ||
|
|
||
| for (const activityUuid in newEvidence) { | ||
| if (!this._evidence[activityUuid]) { | ||
| this._evidence[activityUuid] = []; | ||
| } | ||
|
|
||
| const newEntries = newEvidence[activityUuid]; | ||
| if (Array.isArray(newEntries)) { | ||
| for (const entry of newEntries) { | ||
| const existingIndex = this._evidence[activityUuid].findIndex(e => e.id === entry.id); | ||
| if (existingIndex !== -1) { | ||
| this._evidence[activityUuid][existingIndex] = entry; | ||
| } else { | ||
| this._evidence[activityUuid].push(entry); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public replaceEvidenceData(data: EvidenceData): void { | ||
| this._evidence = data; | ||
| this.saveToLocalStorage(); | ||
| } | ||
|
|
||
| public addEvidence(activityUuid: ActivityId, entry: EvidenceEntry): void { | ||
| if (!this._evidence[activityUuid]) { | ||
| this._evidence[activityUuid] = []; | ||
| } | ||
| this._evidence[activityUuid].push(entry); | ||
| this.saveToLocalStorage(); | ||
| } | ||
|
|
||
| public updateEvidence( | ||
| activityUuid: ActivityId, | ||
| entryId: EvidenceId, | ||
| updatedEntry: Partial<EvidenceEntry> | ||
| ): void { | ||
| const entries = this._evidence[activityUuid]; | ||
| if (!entries) { | ||
| console.warn(`No evidence found for activity ${activityUuid}`); | ||
| return; | ||
| } | ||
| const index = entries.findIndex(e => e.id === entryId); | ||
| if (index === -1) { | ||
| console.warn(`Cannot find evidence with id ${entryId} for activity ${activityUuid}`); | ||
| return; | ||
| } | ||
| // Immutable update for Angular change detection | ||
| entries[index] = { ...entries[index], ...updatedEntry }; | ||
| this.saveToLocalStorage(); | ||
| } | ||
|
|
||
| public deleteEvidence(activityUuid: ActivityId, entryId: EvidenceId): void { | ||
| const entries = this._evidence[activityUuid]; | ||
| if (!entries) { | ||
| console.warn(`No evidence found for activity ${activityUuid}`); | ||
| return; | ||
| } | ||
| const index = entries.findIndex(e => e.id === entryId); | ||
| if (index === -1) { | ||
| console.warn(`Cannot find evidence with id ${entryId} for activity ${activityUuid}`); | ||
| return; | ||
| } | ||
| entries.splice(index, 1); | ||
|
|
||
| if (entries.length === 0) { | ||
| delete this._evidence[activityUuid]; | ||
| } | ||
| this.saveToLocalStorage(); | ||
| } | ||
|
|
||
| public renameTeam(oldName: string, newName: string): void { | ||
| console.log(`Renaming team '${oldName}' to '${newName}' in evidence store`); | ||
| for (const uuid in this._evidence) { | ||
| this._evidence[uuid].forEach(entry => { | ||
| entry.teams = entry.teams.map(t => (t === oldName ? newName : t)); | ||
| }); | ||
| } | ||
| this.saveToLocalStorage(); | ||
| } | ||
|
|
||
| // ─── Serialization ────────────────────────────────────── | ||
|
|
||
| public asYamlString(): string { | ||
| return this.yamlService.stringify({ evidence: this._evidence }); | ||
| } | ||
|
|
||
| public saveToLocalStorage(): void { | ||
| const yamlStr = this.asYamlString(); | ||
| localStorage.setItem(LOCALSTORAGE_KEY, yamlStr); | ||
| } | ||
|
|
||
| public deleteBrowserStoredEvidence(): void { | ||
| console.log('Deleting evidence from browser storage'); | ||
| localStorage.removeItem(LOCALSTORAGE_KEY); | ||
| } | ||
|
|
||
| public retrieveStoredEvidenceYaml(): string | null { | ||
| return localStorage.getItem(LOCALSTORAGE_KEY); | ||
| } | ||
|
|
||
| public retrieveStoredEvidence(): EvidenceData | null { | ||
| const yamlStr = this.retrieveStoredEvidenceYaml(); | ||
| if (!yamlStr) return null; | ||
|
|
||
| const parsed = this.yamlService.parse(yamlStr); | ||
| return parsed?.evidence ?? null; | ||
| } | ||
|
|
||
| // ─── Helpers ───────────────────────────────────────────── | ||
|
|
||
| private isDuplicateEntry(activityUuid: ActivityId, entry: EvidenceEntry): boolean { | ||
| const existing = this._evidence[activityUuid]; | ||
| if (!existing) return false; | ||
| return existing.some(e => e.id === entry.id); | ||
| } | ||
|
|
||
| public static todayDateString(): string { | ||
| const now = new Date(); | ||
| return now.toISOString().substring(0, 10); | ||
| } | ||
|
|
||
| // to be used when creating new evidence entries to ensure they have a stable UUID | ||
| public static generateId(): string { | ||
| return crypto.randomUUID?.() ?? `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Export team evidence from the browser, and replace this file | ||
| evidence: |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.