From 2ae133d0c0c8a525744f2ad123a781488f177102 Mon Sep 17 00:00:00 2001 From: araddcc002 Date: Tue, 20 Aug 2024 07:32:42 +0000 Subject: [PATCH 1/3] =?UTF-8?q?updated=20config=20and=20audit=20for=20crea?= =?UTF-8?q?te=20model=20card=C2=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/connectors/audit/Base.ts | 2 +- backend/src/connectors/audit/silly.ts | 2 +- backend/src/connectors/audit/stdout.ts | 4 ++-- backend/src/routes/v2/model/modelcard/postFromSchema.ts | 5 +++-- backend/src/routes/v2/model/modelcard/postFromTemplate.ts | 5 +++-- .../helm/bailo/templates/bailo/bailo.configmap.yaml | 4 ++-- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/backend/src/connectors/audit/Base.ts b/backend/src/connectors/audit/Base.ts index 45b07376c..227dedd2d 100644 --- a/backend/src/connectors/audit/Base.ts +++ b/backend/src/connectors/audit/Base.ts @@ -128,7 +128,7 @@ export abstract class BaseAuditConnector { abstract onUpdateModel(req: Request, model: ModelDoc) abstract onSearchModel(req: Request, models: ModelSearchResult[]) - abstract onCreateModelCard(req: Request, modelId: string, modelCard: ModelCardInterface) + abstract onCreateModelCard(req: Request, model: ModelDoc, modelCard: ModelCardInterface) abstract onViewModelCard(req: Request, modelId: string, modelCard: ModelCardInterface) abstract onUpdateModelCard(req: Request, modelId: string, modelCard: ModelCardInterface) abstract onViewModelCardRevisions(req: Request, modelId: string, modelCards: ModelCardInterface[]) diff --git a/backend/src/connectors/audit/silly.ts b/backend/src/connectors/audit/silly.ts index e29d6f640..b22b520c1 100644 --- a/backend/src/connectors/audit/silly.ts +++ b/backend/src/connectors/audit/silly.ts @@ -23,7 +23,7 @@ export class SillyAuditConnector extends BaseAuditConnector { onViewModel(_req: Request, _model: ModelDoc) {} onUpdateModel(_req: Request, _model: ModelDoc) {} onSearchModel(_req: Request, _models: ModelSearchResult[]) {} - onCreateModelCard(_req: Request, _modelId: string, _modelCard: ModelCardInterface) {} + onCreateModelCard(_req: Request, _model: ModelDoc, _modelCard: ModelCardInterface) {} onViewModelCard(_req: Request, _modelId: string, _modelCard: ModelCardInterface) {} onUpdateModelCard(_req: Request, _modelId: string, _modelCard: ModelCardInterface) {} onViewModelCardRevisions(_req: Request, _modelId: string, _modelCards: ModelCardInterface[]) {} diff --git a/backend/src/connectors/audit/stdout.ts b/backend/src/connectors/audit/stdout.ts index 25e42b636..8069ee049 100644 --- a/backend/src/connectors/audit/stdout.ts +++ b/backend/src/connectors/audit/stdout.ts @@ -52,9 +52,9 @@ export class StdoutAuditConnector extends BaseAuditConnector { req.log.info(event, req.audit.description) } - onCreateModelCard(req: Request, modelId: string, modelCard: ModelCardInterface) { + onCreateModelCard(req: Request, model: ModelDoc, modelCard: ModelCardInterface) { this.checkEventType(AuditInfo.CreateModelCard, req) - const event = this.generateEvent(req, { modelId, version: modelCard.version }) + const event = this.generateEvent(req, { model, version: modelCard.version }) req.log.info(event, req.audit.description) } diff --git a/backend/src/routes/v2/model/modelcard/postFromSchema.ts b/backend/src/routes/v2/model/modelcard/postFromSchema.ts index 91495c7f9..9547b93be 100644 --- a/backend/src/routes/v2/model/modelcard/postFromSchema.ts +++ b/backend/src/routes/v2/model/modelcard/postFromSchema.ts @@ -5,7 +5,7 @@ import { z } from 'zod' import { AuditInfo } from '../../../../connectors/audit/Base.js' import audit from '../../../../connectors/audit/index.js' import { ModelCardRevisionInterface } from '../../../../models/ModelCardRevision.js' -import { createModelCardFromSchema } from '../../../../services/model.js' +import { createModelCardFromSchema, getModelById } from '../../../../services/model.js' import { modelCardRevisionInterfaceSchema, registerPath } from '../../../../services/specification.js' import { parse } from '../../../../utils/validate.js' @@ -56,8 +56,9 @@ export const postFromSchema = [ } = parse(req, postFromSchemaSchema) const modelCard = await createModelCardFromSchema(req.user, modelId, schemaId) + const model = await getModelById(req.user, modelId) - await audit.onCreateModelCard(req, modelId, modelCard) + await audit.onCreateModelCard(req, model, modelCard) return res.json({ card: modelCard, diff --git a/backend/src/routes/v2/model/modelcard/postFromTemplate.ts b/backend/src/routes/v2/model/modelcard/postFromTemplate.ts index 270dab20b..bdce5efa2 100644 --- a/backend/src/routes/v2/model/modelcard/postFromTemplate.ts +++ b/backend/src/routes/v2/model/modelcard/postFromTemplate.ts @@ -5,7 +5,7 @@ import { z } from 'zod' import { AuditInfo } from '../../../../connectors/audit/Base.js' import audit from '../../../../connectors/audit/index.js' import { ModelCardRevisionInterface } from '../../../../models/ModelCardRevision.js' -import { createModelCardFromTemplate } from '../../../../services/model.js' +import { createModelCardFromTemplate, getModelById } from '../../../../services/model.js' import { modelCardRevisionInterfaceSchema, registerPath } from '../../../../services/specification.js' import { parse } from '../../../../utils/validate.js' @@ -56,8 +56,9 @@ export const postFromTemplate = [ } = parse(req, postFromTemplateSchema) const modelCard = await createModelCardFromTemplate(req.user, modelId, templateId) + const model = await getModelById(req.user, modelId) - await audit.onCreateModelCard(req, modelId, modelCard) + await audit.onCreateModelCard(req, model, modelCard) return res.json({ card: modelCard, diff --git a/infrastructure/helm/bailo/templates/bailo/bailo.configmap.yaml b/infrastructure/helm/bailo/templates/bailo/bailo.configmap.yaml index 8f6395331..cff3acc45 100644 --- a/infrastructure/helm/bailo/templates/bailo/bailo.configmap.yaml +++ b/infrastructure/helm/bailo/templates/bailo/bailo.configmap.yaml @@ -138,8 +138,8 @@ data: // Show announcement banner at the bottom of the screen announcement: { enabled: {{ .Values.config.ui.announcement.enabled }}, - text: {{ .Values.config.ui.announcement.text }}, - startTimestamp: {{ .Values.config.ui.announcement.startTimestamp }} + text: '{{ .Values.config.ui.announcement.text }}', + startTimestamp: '{{ .Values.config.ui.announcement.startTimestamp }}', }, // Contact details for the support team From b8f955690cab277a28c556c3244398c313cc2100 Mon Sep 17 00:00:00 2001 From: araddcc002 Date: Tue, 20 Aug 2024 08:17:51 +0000 Subject: [PATCH 2/3] fixed builds --- .../__snapshots__/postFromSchema.spec.ts.snap | 16 ---------- .../postFromTemplate.spec.ts.snap | 10 ++++++- .../postRequestExport.spec.ts.snap | 30 ------------------- .../model/modelcard/postFromSchema.spec.ts | 1 + .../model/modelcard/postFromTemplate.spec.ts | 1 + 5 files changed, 11 insertions(+), 47 deletions(-) delete mode 100644 backend/test/routes/model/modelcard/__snapshots__/postRequestExport.spec.ts.snap diff --git a/backend/test/routes/model/modelcard/__snapshots__/postFromSchema.spec.ts.snap b/backend/test/routes/model/modelcard/__snapshots__/postFromSchema.spec.ts.snap index c58ac3aea..95fa43ac5 100644 --- a/backend/test/routes/model/modelcard/__snapshots__/postFromSchema.spec.ts.snap +++ b/backend/test/routes/model/modelcard/__snapshots__/postFromSchema.spec.ts.snap @@ -1,13 +1,5 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`routes > model > postModel > schema > 200 > ok 1`] = ` -{ - "card": { - "_id": "test", - }, -} -`; - exports[`routes > model > postModel > schema > 400 > no description 1`] = ` { "error": { @@ -30,11 +22,3 @@ exports[`routes > model > postModel > schema > 400 > no description 1`] = ` }, } `; - -exports[`routes > model > postModel > schema > audit > expected call 1`] = `"example"`; - -exports[`routes > model > postModel > schema > audit > expected call 2`] = ` -{ - "_id": "test", -} -`; diff --git a/backend/test/routes/model/modelcard/__snapshots__/postFromTemplate.spec.ts.snap b/backend/test/routes/model/modelcard/__snapshots__/postFromTemplate.spec.ts.snap index 0e989cc9b..78451ed37 100644 --- a/backend/test/routes/model/modelcard/__snapshots__/postFromTemplate.spec.ts.snap +++ b/backend/test/routes/model/modelcard/__snapshots__/postFromTemplate.spec.ts.snap @@ -31,7 +31,15 @@ exports[`routes > model > postModel > template > 400 > no model template ID prov } `; -exports[`routes > model > postModel > template > audit > expected call 1`] = `"example"`; +exports[`routes > model > postModel > template > audit > expected call 1`] = ` +{ + "settings": { + "mirror": { + "sourceModelId": "", + }, + }, +} +`; exports[`routes > model > postModel > template > audit > expected call 2`] = ` { diff --git a/backend/test/routes/model/modelcard/__snapshots__/postRequestExport.spec.ts.snap b/backend/test/routes/model/modelcard/__snapshots__/postRequestExport.spec.ts.snap deleted file mode 100644 index 44c9655ec..000000000 --- a/backend/test/routes/model/modelcard/__snapshots__/postRequestExport.spec.ts.snap +++ /dev/null @@ -1,30 +0,0 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html - -exports[`routes > model > modelcard > postRequestExport > 200 > ok 1`] = ` -{ - "message": "Successfully exported model cards", -} -`; - -exports[`routes > model > modelcard > postRequestExport > 400 > no description 1`] = ` -{ - "error": { - "context": { - "errors": [ - { - "code": "invalid_type", - "expected": "boolean", - "message": "Required", - "path": [ - "body", - "disclaimerAgreement", - ], - "received": "undefined", - }, - ], - }, - "message": "Path: body.disclaimerAgreement - Message: Required", - "name": "Bailo Error", - }, -} -`; diff --git a/backend/test/routes/model/modelcard/postFromSchema.spec.ts b/backend/test/routes/model/modelcard/postFromSchema.spec.ts index fb39c30b4..f3b7c9608 100644 --- a/backend/test/routes/model/modelcard/postFromSchema.spec.ts +++ b/backend/test/routes/model/modelcard/postFromSchema.spec.ts @@ -15,6 +15,7 @@ vi.mock('../../../../src/services/model.js', async () => { return { ...actual, createModelCardFromSchema: vi.fn(() => ({ _id: 'test' })), + getModelById: vi.fn(() => ({ settings: { mirror: { sourceModelId: '' } } })), } }) diff --git a/backend/test/routes/model/modelcard/postFromTemplate.spec.ts b/backend/test/routes/model/modelcard/postFromTemplate.spec.ts index b4e51d91a..9cb91970e 100644 --- a/backend/test/routes/model/modelcard/postFromTemplate.spec.ts +++ b/backend/test/routes/model/modelcard/postFromTemplate.spec.ts @@ -15,6 +15,7 @@ vi.mock('../../../../src/services/model.js', async () => { return { ...actual, createModelCardFromTemplate: vi.fn(() => ({ _id: 'test' })), + getModelById: vi.fn(() => ({ settings: { mirror: { sourceModelId: '' } } })), } }) From 58ee0379deba30eb5816600459d7e95e00cb8490 Mon Sep 17 00:00:00 2001 From: araddcc002 Date: Wed, 21 Aug 2024 07:06:00 +0000 Subject: [PATCH 3/3] updated spec for postFromSchema test --- .../__snapshots__/postFromSchema.spec.ts.snap | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/backend/test/routes/model/modelcard/__snapshots__/postFromSchema.spec.ts.snap b/backend/test/routes/model/modelcard/__snapshots__/postFromSchema.spec.ts.snap index 95fa43ac5..51ae6508b 100644 --- a/backend/test/routes/model/modelcard/__snapshots__/postFromSchema.spec.ts.snap +++ b/backend/test/routes/model/modelcard/__snapshots__/postFromSchema.spec.ts.snap @@ -1,5 +1,13 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +exports[`routes > model > postModel > schema > 200 > ok 1`] = ` +{ + "card": { + "_id": "test", + }, +} +`; + exports[`routes > model > postModel > schema > 400 > no description 1`] = ` { "error": { @@ -22,3 +30,19 @@ exports[`routes > model > postModel > schema > 400 > no description 1`] = ` }, } `; + +exports[`routes > model > postModel > schema > audit > expected call 1`] = ` +{ + "settings": { + "mirror": { + "sourceModelId": "", + }, + }, +} +`; + +exports[`routes > model > postModel > schema > audit > expected call 2`] = ` +{ + "_id": "test", +} +`;