Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Epic/feat/admin tools2 #2410

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions services/workflows-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"@nestjs/serve-static": "3.0.1",
"@nestjs/testing": "^9.3.12",
"@prisma/client": "4.16.2",
"@sendgrid/mail": "^8.1.3",
"@sentry/cli": "^2.17.5",
"@sentry/integrations": "^7.52.1",
"@sentry/node": "^7.52.1",
Expand Down
17 changes: 16 additions & 1 deletion services/workflows-service/src/user/dtos/user-create.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsArray, IsString } from 'class-validator';
import { IsArray, IsString, IsOptional, IsBoolean } from 'class-validator';
import type { InputJsonValue } from '../../types';

class CreateOptions {
@ApiProperty({
required: false,
type: Boolean,
default: false,
})
@IsBoolean()
@IsOptional()
sendWelcomeEmail?: boolean;
}

export class UserCreateDto {
@ApiProperty({
required: true,
Expand Down Expand Up @@ -53,4 +64,8 @@ export class UserCreateDto {
// @Type(() => WorkflowCreateNestedManyWithoutUsersInput)
// @IsOptional()
// workflows?: WorkflowCreateNestedManyWithoutUsersInput;

@ApiProperty({ required: false, type: CreateOptions })
@IsOptional()
options?: CreateOptions;
}
68 changes: 65 additions & 3 deletions services/workflows-service/src/user/user.controller.internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import { ProjectIds } from '@/common/decorators/project-ids.decorator';
import type { TProjectId, TProjectIds } from '@/types';
import { CurrentProject } from '@/common/decorators/current-project.decorator';
import { UserStatus } from '@prisma/client';
import sgMail from '@sendgrid/mail';
import { env } from '@/env';
import { AppLoggerService } from '@/common/app-logger/app-logger.service';

@swagger.ApiExcludeController()
@common.Controller('internal/users')
@swagger.ApiExcludeController()
export class UserControllerInternal {
constructor(protected readonly service: UserService) {}
constructor(protected readonly service: UserService, private logger: AppLoggerService) {}

@common.Get()
@swagger.ApiQuery({ name: 'projectId', type: String })
Expand Down Expand Up @@ -50,9 +53,9 @@ export class UserControllerInternal {
@common.Body() userCreatInfo: UserCreateDto,
@CurrentProject() currentProjectId: TProjectId,
) {
const { projectIds, ...userInfo } = userCreatInfo;
const { projectIds, options, ...userInfo } = userCreatInfo;

return this.service.create(
const createdUser = await this.service.create(
{
data: userInfo,
select: {
Expand All @@ -67,5 +70,64 @@ export class UserControllerInternal {
},
projectIds?.[0] || currentProjectId,
);

if (!options?.sendWelcomeEmail) {
return createdUser;
}

const message: sgMail.MailDataRequired = {
to: createdUser.email,
from: '[email protected]',
subject: "Your Ballerine's Case Management System Credentials",
text: `
Dear ${userInfo.firstName} ${userInfo.lastName},

Welcome to the team! We are excited to have you on our system. To get you started, we have created your account for our Case Management System, which you will need to access to manage your tasks and collaborate with the team.

To access your account:

URL: ${env.BACKOFFICE_CORS_ORIGIN}
Email: ${userInfo.email}
Password: ${userInfo.password}

If you encounter any issues accessing your account or have any questions, please do not hesitate to reach out to Ballerine's team.

Best regards,
Ballerine's Team`,
html: `
<body>
<p>Dear ${userInfo.firstName} ${userInfo.lastName},</p>

<p>Welcome to the team! We are excited to have you on our system. To get you started, we have created your account for our Case Management System, which you will need to access to manage your tasks and collaborate with the team.</p>

<p><strong>To access your account:</strong></p>
<ul>
<li><strong>URL:</strong> ${env.BACKOFFICE_CORS_ORIGIN}</li>
<li><strong>Email:</strong> ${userInfo.email}</li>
<li><strong>Password:</strong> ${userInfo.password}</li>
</ul>

<p>If you encounter any issues accessing your account or have any questions, please do not hesitate to reach out to Ballerine's team.</p>

<p>Best regards,<br>
Ballerine's Team</p>
</body>`,
};

if (!process.env.EMAIL_API_TOKEN) {
this.logger.warn('SendGrid API key not provided. Email will not be not send ');
this.logger.log('Email:', message);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing sensitive information from logs to enhance security. Logging the entire email content could expose user details.

- this.logger.log('Email:', message);
+ this.logger.log('Email sending initiated to:', message.to);

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
this.logger.log('Email:', message);
this.logger.log('Email sending initiated to:', message.to);


return createdUser;
}

try {
sgMail.setApiKey(process.env.EMAIL_API_TOKEN);
await sgMail.send(message);
} catch (error) {
this.logger.error(`Error Sending mail with Sendgrid: ${error}`);
}

return createdUser;
}
}
Loading