Skip to content

Commit

Permalink
feat(cli): add external hooks for when members are added or deleted (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy authored and ivov committed Sep 6, 2022
1 parent bfb42aa commit 8367639
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/UserManagement/routes/me.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function meNamespace(this: N8nApp): void {
user_id: req.user.id,
fields_changed: updatedkeys,
});
await this.externalHooks.run('user.profile.update', [currentEmail, req.body]);
await this.externalHooks.run('user.profile.update', [currentEmail, sanitizeUser(user)]);

return sanitizeUser(user);
},
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/src/UserManagement/routes/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ export function usersNamespace(this: N8nApp): void {
}),
);

await this.externalHooks.run('user.invited', [usersToSetUp]);

Logger.debug(
usersPendingSetup.length > 1
? `Sent ${usersPendingSetup.length} invite emails successfully`
Expand Down Expand Up @@ -363,6 +365,9 @@ export function usersNamespace(this: N8nApp): void {
user_id: invitee.id,
});

await this.externalHooks.run('user.profile.update', [invitee.email, sanitizeUser(invitee)]);
await this.externalHooks.run('user.password.update', [invitee.email, invitee.password]);

return sanitizeUser(updatedUser);
}),
);
Expand Down Expand Up @@ -478,6 +483,8 @@ export function usersNamespace(this: N8nApp): void {

void InternalHooksManager.getInstance().onUserDeletion(req.user.id, telemetryData, false);

await this.externalHooks.run('user.deleted', [sanitizeUser(userToDelete)]);

return { success: true };
}),
);
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/test/integration/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ export async function initTestServer({

if (!endpointGroups) return testServer.app;

if (endpointGroups.includes('credentials') || endpointGroups.includes('me')) {
if (
endpointGroups.includes('credentials') ||
endpointGroups.includes('me') ||
endpointGroups.includes('users')
) {
testServer.externalHooks = ExternalHooks();
}

Expand Down

0 comments on commit 8367639

Please sign in to comment.