Skip to content

Commit 9df686f

Browse files
IOT-1486: Added email in use error text to updating user (#225)
* Changed vm package to isolated-vm * Deleted old using from vm2 * Updated all vulnerable packages * Updated the last debrick packages * Added datatarget name and id to error message when failing * Changed validation types for gatewayId * Added email in use error text to updating user * Fixed kombit signout flow * Updated github action node version
1 parent e8e0307 commit 9df686f

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/controllers/user-management/user.controller.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import {
22
BadRequestException,
33
Body,
44
Controller,
5+
ForbiddenException,
56
Get,
67
InternalServerErrorException,
8+
Logger,
79
NotFoundException,
810
Param,
911
ParseIntPipe,
@@ -12,10 +14,7 @@ import {
1214
Query,
1315
Req,
1416
UseGuards,
15-
ForbiddenException,
16-
UnauthorizedException,
1717
} from "@nestjs/common";
18-
import { Logger } from "@nestjs/common";
1918
import {
2019
ApiBearerAuth,
2120
ApiForbiddenResponse,
@@ -34,8 +33,8 @@ import { UpdateUserDto } from "@dto/user-management/update-user.dto";
3433
import { UserResponseDto } from "@dto/user-response.dto";
3534
import { ErrorCodes } from "@entities/enum/error-codes.enum";
3635
import {
37-
checkIfUserIsGlobalAdmin,
3836
checkIfUserHasAccessToOrganization,
37+
checkIfUserIsGlobalAdmin,
3938
OrganizationAccessScope,
4039
} from "@helpers/security-helper";
4140
import { UserService } from "@services/user-management/user.service";
@@ -171,6 +170,12 @@ export class UserController {
171170
return user;
172171
} catch (err) {
173172
AuditLog.fail(ActionType.UPDATE, User.name, req.user.userId, id);
173+
if (
174+
err instanceof QueryFailedError &&
175+
err.message.startsWith("duplicate key value violates unique constraint")
176+
) {
177+
throw new BadRequestException(ErrorCodes.EmailAlreadyInUse);
178+
}
174179
throw err;
175180
}
176181
}

src/services/user-management/user.service.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {
22
BadRequestException,
3+
forwardRef,
34
Inject,
45
Injectable,
56
Logger,
6-
forwardRef,
77
} from "@nestjs/common";
88
import { InjectRepository } from "@nestjs/typeorm";
99
import * as bcrypt from "bcryptjs";
@@ -22,9 +22,7 @@ import { Profile } from "passport-saml";
2222
import { ListAllUsersMinimalResponseDto } from "@dto/list-all-users-minimal-response.dto";
2323
import { ListAllEntitiesDto } from "@dto/list-all-entities.dto";
2424
import { CreateNewKombitUserDto } from "@dto/user-management/create-new-kombit-user.dto";
25-
import * as nodemailer from "nodemailer";
2625
import { Organization } from "@entities/organization.entity";
27-
import SMTPTransport from "nodemailer/lib/smtp-transport";
2826
import { PermissionType } from "@enum/permission-type.enum";
2927
import { ConfigService } from "@nestjs/config";
3028
import { isPermissionType } from "@helpers/security-helper";
@@ -200,11 +198,8 @@ export class UserService {
200198
private async setPasswordHash(mappedUser: User, password: string) {
201199
this.checkPassword(password);
202200
// Hash password with bcrpyt
203-
// this.logger.verbose("Generating salt");
204201
const salt = await bcrypt.genSalt(10);
205-
// this.logger.verbose("Generating hash");
206202
mappedUser.passwordHash = await bcrypt.hash(password, salt);
207-
// this.logger.verbose(`Generated hash: '${mappedUser.passwordHash}'`);
208203
}
209204

210205
private checkPassword(password: string) {

0 commit comments

Comments
 (0)