Skip to content

Commit 068392d

Browse files
authored
Merge branch 'main' into secrets
2 parents 27c3809 + 5aa644e commit 068392d

File tree

78 files changed

+3613
-169
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+3613
-169
lines changed

backend/src/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { ThrottlerModule, ThrottlerGuard } from '@nestjs/throttler';
4040
import { SharedJobsModule } from './entities/shared-jobs/shared-jobs.module.js';
4141
import { TableCategoriesModule } from './entities/table-categories/table-categories.module.js';
4242
import { UserSecretModule } from './entities/user-secret/user-secret.module.js';
43+
import { SignInAuditModule } from './entities/user-sign-in-audit/sign-in-audit.module.js';
4344

4445
@Module({
4546
imports: [
@@ -83,6 +84,7 @@ import { UserSecretModule } from './entities/user-secret/user-secret.module.js';
8384
SharedJobsModule,
8485
TableCategoriesModule,
8586
UserSecretModule,
87+
SignInAuditModule,
8688
],
8789
controllers: [AppController],
8890
providers: [

backend/src/common/application/global-database-context.interface.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ import { UserSecretEntity } from '../../entities/user-secret/user-secret.entity.
5252
import { IUserSecretRepository } from '../../entities/user-secret/repository/user-secret-repository.interface.js';
5353
import { SecretAccessLogEntity } from '../../entities/secret-access-log/secret-access-log.entity.js';
5454
import { ISecretAccessLogRepository } from '../../entities/secret-access-log/repository/secret-access-log-repository.interface.js';
55+
import { SignInAuditEntity } from '../../entities/user-sign-in-audit/sign-in-audit.entity.js';
56+
import { ISignInAuditRepository } from '../../entities/user-sign-in-audit/repository/sign-in-audit-repository.interface.js';
5557

5658
export interface IGlobalDatabaseContext extends IDatabaseContext {
5759
userRepository: Repository<UserEntity> & IUserRepository;
@@ -89,4 +91,5 @@ export interface IGlobalDatabaseContext extends IDatabaseContext {
8991
tableCategoriesRepository: Repository<TableCategoriesEntity> & ITableCategoriesCustomRepository;
9092
userSecretRepository: Repository<UserSecretEntity> & IUserSecretRepository;
9193
secretAccessLogRepository: Repository<SecretAccessLogEntity> & ISecretAccessLogRepository;
94+
signInAuditRepository: Repository<SignInAuditEntity> & ISignInAuditRepository;
9295
}

backend/src/common/application/global-database-context.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ import { userSecretRepositoryExtension } from '../../entities/user-secret/reposi
9696
import { SecretAccessLogEntity } from '../../entities/secret-access-log/secret-access-log.entity.js';
9797
import { ISecretAccessLogRepository } from '../../entities/secret-access-log/repository/secret-access-log-repository.interface.js';
9898
import { secretAccessLogRepositoryExtension } from '../../entities/secret-access-log/repository/secret-access-log-repository.extension.js';
99+
import { SignInAuditEntity } from '../../entities/user-sign-in-audit/sign-in-audit.entity.js';
100+
import { ISignInAuditRepository } from '../../entities/user-sign-in-audit/repository/sign-in-audit-repository.interface.js';
101+
import { signInAuditCustomRepositoryExtension } from '../../entities/user-sign-in-audit/repository/sign-in-audit-custom-repository-extension.js';
99102

100103
@Injectable({ scope: Scope.REQUEST })
101104
export class GlobalDatabaseContext implements IGlobalDatabaseContext {
@@ -136,6 +139,7 @@ export class GlobalDatabaseContext implements IGlobalDatabaseContext {
136139
private _tableCategoriesRepository: Repository<TableCategoriesEntity> & ITableCategoriesCustomRepository;
137140
private _userSecretRepository: Repository<UserSecretEntity> & IUserSecretRepository;
138141
private _secretAccessLogRepository: Repository<SecretAccessLogEntity> & ISecretAccessLogRepository;
142+
private _signInAuditRepository: Repository<SignInAuditEntity> & ISignInAuditRepository;
139143

140144
public constructor(
141145
@Inject(BaseType.DATA_SOURCE)
@@ -230,6 +234,9 @@ export class GlobalDatabaseContext implements IGlobalDatabaseContext {
230234
this._secretAccessLogRepository = this.appDataSource
231235
.getRepository(SecretAccessLogEntity)
232236
.extend(secretAccessLogRepositoryExtension);
237+
this._signInAuditRepository = this.appDataSource
238+
.getRepository(SignInAuditEntity)
239+
.extend(signInAuditCustomRepositoryExtension);
233240
}
234241

235242
public get userRepository(): Repository<UserEntity> & IUserRepository {
@@ -372,6 +379,10 @@ export class GlobalDatabaseContext implements IGlobalDatabaseContext {
372379
return this._secretAccessLogRepository;
373380
}
374381

382+
public get signInAuditRepository(): Repository<SignInAuditEntity> & ISignInAuditRepository {
383+
return this._signInAuditRepository;
384+
}
385+
375386
public startTransaction(): Promise<void> {
376387
this._queryRunner = this.appDataSource.createQueryRunner();
377388
this._queryRunner.startTransaction();

backend/src/common/data-injection.tokens.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,5 @@ export enum UseCaseType {
178178
UPDATE_SECRET = 'UPDATE_SECRET',
179179
DELETE_SECRET = 'DELETE_SECRET',
180180
GET_SECRET_AUDIT_LOG = 'GET_SECRET_AUDIT_LOG',
181+
FIND_SIGN_IN_AUDIT_LOGS = 'FIND_SIGN_IN_AUDIT_LOGS',
181182
}

backend/src/entities/connection/connection.controller.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ import {
8383
import { TokenValidationResult } from './use-cases/validate-connection-token.use.case.js';
8484
import { isTestConnectionUtil } from './utils/is-test-connection-util.js';
8585
import { SkipThrottle } from '@nestjs/throttler';
86+
import { isRedisConnectionUrl } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/create-data-access-object.js';
8687

8788
@UseInterceptors(SentryInterceptor)
8889
@Controller()
@@ -243,7 +244,11 @@ export class ConnectionController {
243244
@UserId() userId: string,
244245
@MasterPassword() masterPwd: string,
245246
): Promise<CreatedConnectionDTO> {
246-
if (!createConnectionDto.password && !isConnectionTypeAgent(createConnectionDto.type)) {
247+
if (
248+
!createConnectionDto.password &&
249+
!isConnectionTypeAgent(createConnectionDto.type) &&
250+
!isRedisConnectionUrl(createConnectionDto.host)
251+
) {
247252
throw new BadRequestException(Messages.PASSWORD_MISSING);
248253
}
249254
if (createConnectionDto.masterEncryption && !masterPwd) {
@@ -709,6 +714,10 @@ export class ConnectionController {
709714
return errors;
710715
}
711716

717+
if (isRedisConnectionUrl(connectionData.host)) {
718+
return errors;
719+
}
720+
712721
if (!connectionData.username && connectionData.type !== ConnectionTypesEnum.redis)
713722
errors.push(Messages.USERNAME_MISSING);
714723

backend/src/entities/connection/use-cases/test-connection.use.case.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { getRepository } from 'typeorm';
33
import AbstractUseCase from '../../../common/abstract-use.case.js';
44
import { IGlobalDatabaseContext } from '../../../common/application/global-database-context.interface.js';
55
import { BaseType } from '../../../common/data-injection.tokens.js';
6-
import { getDataAccessObject } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/create-data-access-object.js';
6+
import {
7+
getDataAccessObject,
8+
isRedisConnectionUrl,
9+
} from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/create-data-access-object.js';
710
import { Messages } from '../../../exceptions/text/messages.js';
811
import { processExceptionMessage } from '../../../exceptions/utils/process-exception-message.js';
912
import { isConnectionTypeAgent, slackPostMessage } from '../../../helpers/index.js';
@@ -96,7 +99,8 @@ export class TestConnectionUseCase
9699
if (
97100
!connectionData.password &&
98101
(connectionData.host !== toUpdate.host || connectionData.port !== toUpdate.port) &&
99-
!isConnectionTypeAgent(connectionData.type)
102+
!isConnectionTypeAgent(connectionData.type) &&
103+
!isRedisConnectionUrl(connectionData.host)
100104
) {
101105
return {
102106
result: false,
@@ -125,7 +129,7 @@ export class TestConnectionUseCase
125129
};
126130
}
127131
} else {
128-
if (!connectionData.password) {
132+
if (!connectionData.password && !isConnectionTypeAgent(connectionData.type) && !isRedisConnectionUrl(connectionData.host)) {
129133
return {
130134
result: false,
131135
message: Messages.PASSWORD_MISSING,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { SignInMethodEnum } from '../enums/sign-in-method.enum.js';
2+
import { SignInStatusEnum } from '../enums/sign-in-status.enum.js';
3+
4+
export class CreateSignInAuditRecordDs {
5+
email: string;
6+
userId?: string;
7+
status: SignInStatusEnum;
8+
signInMethod: SignInMethodEnum;
9+
ipAddress?: string;
10+
userAgent?: string;
11+
failureReason?: string;
12+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { SignInMethodEnum } from '../enums/sign-in-method.enum.js';
2+
import { SignInStatusEnum } from '../enums/sign-in-status.enum.js';
3+
4+
export class FindSignInAuditLogsDs {
5+
userId: string;
6+
companyId: string;
7+
query: {
8+
order?: string;
9+
page?: number;
10+
perPage?: number;
11+
dateFrom?: string;
12+
dateTo?: string;
13+
email?: string;
14+
status?: SignInStatusEnum;
15+
signInMethod?: SignInMethodEnum;
16+
};
17+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import { PaginationDs } from '../../table/application/data-structures/pagination.ds.js';
3+
import { FoundSignInAuditRecordDs } from './found-sign-in-audit-record.ds.js';
4+
5+
export class FoundSignInAuditLogsDs {
6+
@ApiProperty({ isArray: true, type: FoundSignInAuditRecordDs })
7+
logs: Array<FoundSignInAuditRecordDs>;
8+
9+
@ApiProperty({ type: PaginationDs })
10+
pagination: PaginationDs;
11+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import { SignInMethodEnum } from '../enums/sign-in-method.enum.js';
3+
import { SignInStatusEnum } from '../enums/sign-in-status.enum.js';
4+
5+
export class FoundSignInAuditRecordDs {
6+
@ApiProperty()
7+
id: string;
8+
9+
@ApiProperty()
10+
email: string;
11+
12+
@ApiProperty({ enum: SignInStatusEnum })
13+
status: SignInStatusEnum;
14+
15+
@ApiProperty({ enum: SignInMethodEnum })
16+
signInMethod: SignInMethodEnum;
17+
18+
@ApiProperty()
19+
ipAddress: string;
20+
21+
@ApiProperty()
22+
userAgent: string;
23+
24+
@ApiProperty()
25+
failureReason: string;
26+
27+
@ApiProperty()
28+
createdAt: Date;
29+
30+
@ApiProperty()
31+
userId: string;
32+
}

0 commit comments

Comments
 (0)