-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1800 from gchq/feature/get-model-msro-info
Add msro info script
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,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() |