mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 18:41:14 +00:00
feat(core): Email recipients on resource shared (#8408)
This commit is contained in:
@@ -40,6 +40,8 @@ import { WorkflowRequest } from './workflow.request';
|
||||
import { EnterpriseWorkflowService } from './workflow.service.ee';
|
||||
import { WorkflowExecutionService } from './workflowExecution.service';
|
||||
import { WorkflowSharingService } from './workflowSharing.service';
|
||||
import { UserManagementMailer } from '@/UserManagement/email';
|
||||
import { UrlService } from '@/services/url.service';
|
||||
|
||||
@Service()
|
||||
@Authorized()
|
||||
@@ -62,6 +64,8 @@ export class WorkflowsController {
|
||||
private readonly workflowSharingService: WorkflowSharingService,
|
||||
private readonly sharedWorkflowRepository: SharedWorkflowRepository,
|
||||
private readonly userRepository: UserRepository,
|
||||
private readonly mailer: UserManagementMailer,
|
||||
private readonly urlService: UrlService,
|
||||
) {}
|
||||
|
||||
@Post('/')
|
||||
@@ -401,5 +405,36 @@ export class WorkflowsController {
|
||||
});
|
||||
|
||||
void this.internalHooks.onWorkflowSharingUpdate(workflowId, req.user.id, shareWithIds);
|
||||
|
||||
const recipients = await this.userRepository.getEmailsByIds(newShareeIds);
|
||||
|
||||
if (recipients.length === 0) return;
|
||||
|
||||
try {
|
||||
await this.mailer.notifyWorkflowShared({
|
||||
recipientEmails: recipients.map(({ email }) => email),
|
||||
workflowName: workflow.name,
|
||||
workflowId,
|
||||
sharerFirstName: req.user.firstName,
|
||||
baseUrl: this.urlService.getInstanceBaseUrl(),
|
||||
});
|
||||
} catch (error) {
|
||||
void this.internalHooks.onEmailFailed({
|
||||
user: req.user,
|
||||
message_type: 'Workflow shared',
|
||||
public_api: false,
|
||||
});
|
||||
if (error instanceof Error) {
|
||||
throw new InternalServerError(`Please contact your administrator: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.info('Sent workflow shared email successfully', { sharerId: req.user.id });
|
||||
|
||||
void this.internalHooks.onUserTransactionalEmail({
|
||||
user_id: req.user.id,
|
||||
message_type: 'Workflow shared',
|
||||
public_api: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user