(params: {
logger: Logger;
context: ImpureGraphContext<false, true>;
})
| 68 | }; |
| 69 | |
| 70 | export const seedOrgsAndUsers = async (params: { |
| 71 | logger: Logger; |
| 72 | context: ImpureGraphContext<false, true>; |
| 73 | }): Promise<void> => { |
| 74 | const { logger, context } = params; |
| 75 | |
| 76 | const createdUsers = await ensureUsersAreSeeded(params); |
| 77 | |
| 78 | if (createdUsers.length > 0) { |
| 79 | const orgOwner = createdUsers.find( |
| 80 | ({ shortname }) => shortname === "alice", |
| 81 | )!; |
| 82 | |
| 83 | const sharedOrg = await seedOrg({ ...params, owner: orgOwner }); |
| 84 | |
| 85 | for (const user of createdUsers) { |
| 86 | if ( |
| 87 | extractWebIdFromEntityId(user.entity.metadata.recordId.entityId) !== |
| 88 | orgOwner.accountId |
| 89 | ) { |
| 90 | /** |
| 91 | * For users who AREN'T the org owner, we need to create their full membership, |
| 92 | * including both the permission system membership, and the link entity in the graph. |
| 93 | * |
| 94 | * @todo H-4441 have the Graph handle memberOf link entity creation, as well as permisison handling. |
| 95 | */ |
| 96 | await joinOrg( |
| 97 | context, |
| 98 | /** Only the org owner has permission to add members to the organizations */ |
| 99 | { actorId: orgOwner.accountId }, |
| 100 | { |
| 101 | userEntityId: user.entity.metadata.recordId.entityId, |
| 102 | orgEntityId: sharedOrg.entity.metadata.recordId.entityId, |
| 103 | }, |
| 104 | ); |
| 105 | } else { |
| 106 | /** |
| 107 | * For the org owner, we only need to create the link entity in the graph, |
| 108 | * as the permission system membership is created automatically by the Graph when the org is created. |
| 109 | * |
| 110 | * @todo H-4441 have the Graph handle memberOf link entity creation, as well as permisison handling. |
| 111 | */ |
| 112 | await createOrgMembershipLinkEntity( |
| 113 | context, |
| 114 | { |
| 115 | actorId: user.accountId, |
| 116 | }, |
| 117 | { |
| 118 | orgEntityId: sharedOrg.entity.metadata.recordId.entityId, |
| 119 | userEntityId: user.entity.metadata.recordId.entityId, |
| 120 | }, |
| 121 | ); |
| 122 | } |
| 123 | |
| 124 | logger.info( |
| 125 | `User with shortname = "${user.shortname}" joined org with shortname = '${sharedOrg.shortname}'`, |
| 126 | ); |
| 127 |
no test coverage detected