feat(core): Email recipients on resource shared (#8408)

This commit is contained in:
Iván Ovejero
2024-01-23 12:03:59 +01:00
committed by GitHub
parent ae06fdeb62
commit a0a1830696
10 changed files with 194 additions and 3 deletions

View File

@@ -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,
});
}
}