Skip to content

Commit b0a323c

Browse files
Merge remote-tracking branch 'stage' into 'master'
2 parents 7a2c754 + 2546eeb commit b0a323c

22 files changed

+248
-99
lines changed

package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"cookie-parser": "^1.4.5",
6363
"crypto-js": "^4.2.0",
6464
"dayjs": "^1.11.13",
65+
"helmet": "^8.1.0",
6566
"kafkajs": "^2.2.4",
6667
"lodash": "^4.17.20",
6768
"mqtt": "^4.3.7",

src/auth/api-key.strategy.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export class ApiKeyStrategy extends PassportStrategy(HeaderAPIKeyStrategy, ApiKe
2626
if (!apiKeyDb) {
2727
throw new UnauthorizedException(ErrorCodes.ApiKeyAuthFailed);
2828
}
29+
if (apiKeyDb.expiresOn < new Date()) {
30+
throw new UnauthorizedException(ErrorCodes.ApiKeyExpired);
31+
}
2932

3033
// Get the permissions and the UserID from the API Key instead of the user
3134
const permissions = await this.permissionService.findPermissionGroupedByLevelForApiKey(apiKeyDb.id);

src/controllers/admin-controller/iot-device-payload-decoder-data-target-connection.controller.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { IoTDeviceService } from "@services/device-management/iot-device.service
4141
import { AuditLog } from "@services/audit-log.service";
4242
import { ActionType } from "@entities/audit-log-entry";
4343
import { ApiAuth } from "@auth/swagger-auth-decorator";
44+
import { AppendCopiedDeviceDto } from "@dto/append-copied-device.dto";
4445

4546
@ApiTags("IoT-Device, PayloadDecoder and DataTarget Connection")
4647
@Controller("iot-device-payload-decoder-data-target-connection")
@@ -205,6 +206,33 @@ export class IoTDevicePayloadDecoderDataTargetConnectionController {
205206
}
206207
}
207208

209+
@Put("appendCopiedDevice/:id")
210+
@ApplicationAdmin()
211+
@ApiNotFoundResponse({
212+
description: "If the id of the entity doesn't exist",
213+
})
214+
@ApiBadRequestResponse({
215+
description: "If one or more of the id's are invalid references.",
216+
})
217+
async appendCopiedDevice(
218+
@Req() req: AuthenticatedRequest,
219+
@Param("id", new ParseIntPipe()) id: number,
220+
@Body() dto: AppendCopiedDeviceDto
221+
): Promise<IoTDevicePayloadDecoderDataTargetConnection> {
222+
try {
223+
const newIotDevice = await this.iotDeviceService.findOne(dto.deviceId);
224+
checkIfUserHasAccessToApplication(req, newIotDevice.application.id, ApplicationAccessScope.Write);
225+
226+
const result = await this.service.appendCopiedDevice(id, newIotDevice, req.user.userId);
227+
228+
AuditLog.success(ActionType.UPDATE, IoTDevicePayloadDecoderDataTargetConnection.name, req.user.userId, result.id);
229+
return result;
230+
} catch (err) {
231+
AuditLog.fail(ActionType.UPDATE, IoTDevicePayloadDecoderDataTargetConnection.name, req.user.userId, id);
232+
throw err;
233+
}
234+
}
235+
208236
@Delete(":id")
209237
@ApplicationAdmin()
210238
@ApiNotFoundResponse({

src/controllers/api-key/api-key.controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
} from "@nestjs/common";
2828
import {
2929
ApiBadRequestResponse,
30+
ApiBearerAuth,
3031
ApiForbiddenResponse,
3132
ApiNotFoundResponse,
3233
ApiOperation,
@@ -38,10 +39,9 @@ import { AuditLog } from "@services/audit-log.service";
3839
import { OrganizationService } from "@services/user-management/organization.service";
3940
import { UpdateApiKeyDto } from "@dto/api-key/update-api-key.dto";
4041
import { checkIfUserHasAccessToOrganization, OrganizationAccessScope } from "@helpers/security-helper";
41-
import { ApiAuth } from "@auth/swagger-auth-decorator";
4242

4343
@UseGuards(JwtAuthGuard, RolesGuard)
44-
@ApiAuth()
44+
@ApiBearerAuth()
4545
@UserAdmin()
4646
@ApiForbiddenResponse()
4747
@ApiUnauthorizedResponse()

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ import {
1414
UseGuards,
1515
} from "@nestjs/common";
1616
import {
17+
ApiBearerAuth,
1718
ApiForbiddenResponse,
1819
ApiNotFoundResponse,
1920
ApiOperation,
2021
ApiTags,
2122
ApiUnauthorizedResponse,
2223
} from "@nestjs/swagger";
23-
24-
import { JwtAuthGuard } from "@auth/jwt-auth.guard";
2524
import { ApplicationAdmin, GatewayAdmin, GlobalAdmin, Read, UserAdmin } from "@auth/roles.decorator";
2625
import { RolesGuard } from "@auth/roles.guard";
2726
import { DeleteResponseDto } from "@dto/delete-application-response.dto";
@@ -38,21 +37,21 @@ import { OrganizationService } from "@services/user-management/organization.serv
3837
import { AuditLog } from "@services/audit-log.service";
3938
import { ActionType } from "@entities/audit-log-entry";
4039
import { ListAllEntitiesDto } from "@dto/list-all-entities.dto";
41-
import { ApiAuth } from "@auth/swagger-auth-decorator";
4240
import { checkIfUserHasAccessToOrganization, OrganizationAccessScope } from "@helpers/security-helper";
43-
import { PermissionType } from "@enum/permission-type.enum";
41+
import { ComposeAuthGuard } from "@auth/compose-auth.guard";
4442

45-
@UseGuards(JwtAuthGuard, RolesGuard)
46-
@ApiAuth()
43+
@UseGuards(ComposeAuthGuard, RolesGuard)
44+
@ApiBearerAuth()
4745
@ApiForbiddenResponse()
4846
@ApiUnauthorizedResponse()
4947
@ApiTags("Organization")
5048
@Controller("organization")
5149
@GlobalAdmin()
5250
export class OrganizationController {
53-
constructor(private organizationService: OrganizationService) {}
5451
private readonly logger = new Logger(OrganizationController.name);
5552

53+
constructor(private organizationService: OrganizationService) {}
54+
5655
@Post()
5756
@ApiOperation({ summary: "Create a new Organization" })
5857
async create(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
UseGuards,
1515
} from "@nestjs/common";
1616
import {
17+
ApiBearerAuth,
1718
ApiForbiddenResponse,
1819
ApiNotFoundResponse,
1920
ApiOperation,
@@ -49,11 +50,10 @@ import { PermissionRequestAcceptUser } from "@dto/user-management/add-user-to-pe
4950
import { OrganizationService } from "@services/user-management/organization.service";
5051
import { Organization } from "@entities/organization.entity";
5152
import { User } from "@entities/user.entity";
52-
import { ApiAuth } from "@auth/swagger-auth-decorator";
5353
import { ListAllPermissionsSlimResponseDto } from "@dto/list-all-permissions-slim-response.dto";
5454

5555
@UseGuards(JwtAuthGuard, RolesGuard)
56-
@ApiAuth()
56+
@ApiBearerAuth()
5757
@ApiForbiddenResponse()
5858
@ApiUnauthorizedResponse()
5959
@ApiTags("Permission")

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
Req,
1616
UseGuards,
1717
} from "@nestjs/common";
18-
import { ApiForbiddenResponse, ApiOperation, ApiTags, ApiUnauthorizedResponse } from "@nestjs/swagger";
18+
import { ApiBearerAuth, ApiForbiddenResponse, ApiOperation, ApiTags, ApiUnauthorizedResponse } from "@nestjs/swagger";
1919
import { QueryFailedError } from "typeorm";
2020

2121
import { JwtAuthGuard } from "@auth/jwt-auth.guard";
@@ -41,20 +41,19 @@ import { ListAllEntitiesDto } from "@dto/list-all-entities.dto";
4141
import { OrganizationService } from "@services/user-management/organization.service";
4242
import { Organization } from "@entities/organization.entity";
4343
import { RejectUserDto } from "@dto/user-management/reject-user.dto";
44-
import { ApiAuth } from "@auth/swagger-auth-decorator";
4544

4645
@UseGuards(JwtAuthGuard, RolesGuard)
4746
@UserAdmin()
48-
@ApiAuth()
47+
@ApiBearerAuth()
4948
@ApiForbiddenResponse()
5049
@ApiUnauthorizedResponse()
5150
@ApiTags("User Management")
5251
@Controller("user")
5352
export class UserController {
54-
constructor(private userService: UserService, private organizationService: OrganizationService) {}
55-
5653
private readonly logger = new Logger(UserController.name);
5754

55+
constructor(private userService: UserService, private organizationService: OrganizationService) {}
56+
5857
@Get("minimal")
5958
@ApiOperation({ summary: "Get all id,names of users" })
6059
async findAllMinimal(): Promise<ListAllUsersMinimalResponseDto> {

src/entities/api-key.entity.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ export class ApiKey extends DbBaseEntity {
2323
})
2424
@JoinColumn()
2525
systemUser: User;
26+
27+
@Column({ nullable: true })
28+
expiresOn?: Date;
2629
}

src/entities/dto/api-key/create-api-key.dto.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { ApiProperty } from "@nestjs/swagger";
22
import { ArrayNotEmpty, ArrayUnique, IsArray, IsString, Length } from "class-validator";
3+
import { IsSwaggerOptional } from "@helpers/optional-validator";
4+
import { ValidateDate } from "@helpers/date.validator";
35

46
export class CreateApiKeyDto {
57
@ApiProperty({ required: true })
@@ -18,4 +20,8 @@ export class CreateApiKeyDto {
1820
@ArrayNotEmpty()
1921
@ArrayUnique()
2022
permissionIds: number[];
23+
24+
@IsSwaggerOptional()
25+
@ValidateDate()
26+
expiresOn?: Date;
2127
}

0 commit comments

Comments
 (0)