fix(core): Prevent calling internal hook email event if emailing is disabled (#8462)

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
Iván Ovejero
2024-01-29 16:15:30 +01:00
committed by GitHub
parent c9b3649b7e
commit 9e93980957
10 changed files with 597 additions and 568 deletions

View File

@@ -39,7 +39,6 @@ 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()
@@ -63,7 +62,6 @@ export class WorkflowsController {
private readonly userRepository: UserRepository,
private readonly license: License,
private readonly mailer: UserManagementMailer,
private readonly urlService: UrlService,
) {}
@Post('/')
@@ -403,35 +401,10 @@ 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,
await this.mailer.notifyWorkflowShared({
sharer: req.user,
newShareeIds,
workflow,
});
}
}