Skip to content

Commit

Permalink
Merge pull request #1800 from gchq/feature/get-model-msro-info
Browse files Browse the repository at this point in the history
Add msro info script
  • Loading branch information
JR40159 authored Feb 5, 2025
2 parents c41e5ef + 0a37193 commit 413c19c
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions backend/src/scripts/listDetailsOfMSROs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import authentication from '../connectors/authentication/index.js'
import ModelModel from '../models/Model.js'
import log from '../services/log.js'
import { connectToMongoose, disconnectFromMongoose } from '../utils/database.js'

async function script() {
await connectToMongoose()
const models = await ModelModel.find({ collaborators: { $elemMatch: { roles: 'msro' } } })
const msroInformation: {
[x: string]: { email?: string; models: number }
} = {}

for (const model of models) {
const modelMSROs = (
await Promise.all(
model.collaborators
.filter((collaborator) => collaborator.roles.includes('msro'))
.map((collaborator) => collaborator.entity)
.map(async (entity) => {
return await authentication.getEntityMembers(entity)
}),
)
).flat()

for (const entity of modelMSROs) {
if (msroInformation[entity]) {
msroInformation[entity].models++
} else {
msroInformation[entity] = {
email: (await authentication.getUserInformation(entity)).email,
models: 1,
}
}
}
}
log.info(msroInformation)
setTimeout(disconnectFromMongoose, 50)
}

script()

0 comments on commit 413c19c

Please sign in to comment.