-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #444 from internxt/feat/access-logs
[PB-3334] Feat/access logs
- Loading branch information
Showing
19 changed files
with
2,362 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
'use strict'; | ||
|
||
const tableName = 'workspace_logs'; | ||
const indexName = 'workspace_id_workspace_logs_index'; | ||
const indexName2 = 'created_at_workspace_logs_index'; | ||
const indexName3 = 'platform_workspace_logs_index'; | ||
const indexName4 = 'creator_workspace_logs_index'; | ||
|
||
/** @type {import('sequelize-cli').Migration} */ | ||
module.exports = { | ||
async up(queryInterface, Sequelize) { | ||
await queryInterface.createTable(tableName, { | ||
id: { | ||
type: Sequelize.DataTypes.UUID, | ||
primaryKey: true, | ||
defaultValue: Sequelize.DataTypes.UUIDV4, | ||
}, | ||
workspace_id: { | ||
type: Sequelize.DataTypes.UUID, | ||
allowNull: false, | ||
references: { | ||
model: 'workspaces', | ||
key: 'id', | ||
}, | ||
onDelete: 'CASCADE', | ||
}, | ||
creator: { | ||
type: Sequelize.STRING(36), | ||
allowNull: false, | ||
references: { | ||
model: 'users', | ||
key: 'uuid', | ||
}, | ||
onDelete: 'CASCADE', | ||
}, | ||
type: { | ||
type: Sequelize.ENUM( | ||
'login', | ||
'changed-password', | ||
'logout', | ||
'share-file', | ||
'share-folder', | ||
'delete-file', | ||
'delete-folder', | ||
), | ||
allowNull: false, | ||
}, | ||
platform: { | ||
type: Sequelize.ENUM( | ||
'web', | ||
'mobile', | ||
'desktop', | ||
), | ||
allowNull: false, | ||
}, | ||
entity_id: { | ||
type: Sequelize.DataTypes.UUID, | ||
allowNull: true, | ||
}, | ||
created_at: { | ||
type: Sequelize.DataTypes.DATE, | ||
allowNull: false, | ||
defaultValue: Sequelize.NOW, | ||
}, | ||
updated_at: { | ||
type: Sequelize.DataTypes.DATE, | ||
allowNull: false, | ||
defaultValue: Sequelize.NOW, | ||
}, | ||
}); | ||
await queryInterface.addIndex(tableName, { | ||
fields: ['workspace_id'], | ||
name: indexName, | ||
}); | ||
await queryInterface.addIndex(tableName, { | ||
fields: ['created_at'], | ||
name: indexName2, | ||
}); | ||
await queryInterface.addIndex(tableName, { | ||
fields: ['platform'], | ||
name: indexName3, | ||
}); | ||
await queryInterface.addIndex(tableName, { | ||
fields: ['creator'], | ||
name: indexName4, | ||
}); | ||
}, | ||
|
||
async down(queryInterface) { | ||
await queryInterface.removeIndex(tableName, indexName); | ||
await queryInterface.removeIndex(tableName, indexName2); | ||
await queryInterface.removeIndex(tableName, indexName3); | ||
await queryInterface.removeIndex(tableName, indexName4); | ||
await queryInterface.dropTable(tableName); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/modules/workspaces/attributes/workspace-logs.attributes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export enum WorkspaceLogType { | ||
Login = 'login', | ||
ChangedPassword = 'changed-password', | ||
Logout = 'logout', | ||
ShareFile = 'share-file', | ||
ShareFolder = 'share-folder', | ||
DeleteFile = 'delete-file', | ||
DeleteFolder = 'delete-folder', | ||
} | ||
|
||
export enum WorkspaceLogGlobalActionType { | ||
Share = 'share', | ||
Delete = 'delete', | ||
DeleteAll = 'delete-all', | ||
} | ||
|
||
export enum WorkspaceLogPlatform { | ||
Web = 'web', | ||
Mobile = 'mobile', | ||
Desktop = 'desktop', | ||
} | ||
|
||
export interface WorkspaceLogAttributes { | ||
id: string; | ||
workspaceId: string; | ||
creator: string; | ||
type: WorkspaceLogType; | ||
platform: WorkspaceLogPlatform; | ||
entityId?: string; | ||
user?: any; | ||
workspace?: any; | ||
file?: any; | ||
folder?: any; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/modules/workspaces/decorators/workspace-log-action.decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { applyDecorators, SetMetadata, UseInterceptors } from '@nestjs/common'; | ||
import { | ||
WorkspaceLogGlobalActionType, | ||
WorkspaceLogType, | ||
} from '../attributes/workspace-logs.attributes'; | ||
import { WorkspacesLogsInterceptor } from './../interceptors/workspaces-logs.interceptor'; | ||
|
||
export const WorkspaceLogAction = ( | ||
action: WorkspaceLogType | WorkspaceLogGlobalActionType, | ||
) => | ||
applyDecorators( | ||
SetMetadata('workspaceLogAction', action), | ||
UseInterceptors(WorkspacesLogsInterceptor), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { | ||
WorkspaceLogAttributes, | ||
WorkspaceLogPlatform, | ||
WorkspaceLogType, | ||
} from '../attributes/workspace-logs.attributes'; | ||
|
||
export class WorkspaceLog implements WorkspaceLogAttributes { | ||
id: string; | ||
workspaceId: string; | ||
creator: string; | ||
type: WorkspaceLogType; | ||
platform: WorkspaceLogPlatform; | ||
entityId?: string; | ||
user?: any; | ||
workspace?: any; | ||
file?: any; | ||
folder?: any; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
|
||
constructor({ | ||
id, | ||
workspaceId, | ||
creator, | ||
type, | ||
platform, | ||
entityId, | ||
user, | ||
workspace, | ||
file, | ||
folder, | ||
createdAt, | ||
updatedAt, | ||
}: WorkspaceLogAttributes) { | ||
this.id = id; | ||
this.workspaceId = workspaceId; | ||
this.creator = creator; | ||
this.type = type; | ||
this.platform = platform; | ||
this.entityId = entityId; | ||
this.user = user; | ||
this.workspace = workspace; | ||
this.file = file; | ||
this.folder = folder; | ||
this.createdAt = createdAt; | ||
this.updatedAt = updatedAt; | ||
} | ||
|
||
static build(user: WorkspaceLogAttributes): WorkspaceLog { | ||
return new WorkspaceLog(user); | ||
} | ||
|
||
toJSON() { | ||
return { | ||
id: this.id, | ||
workspaceId: this.workspaceId, | ||
creator: this.creator, | ||
type: this.type, | ||
platform: this.platform, | ||
entityId: this.entityId, | ||
createdAt: this.createdAt, | ||
updatedAt: this.updatedAt, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { ApiPropertyOptional } from '@nestjs/swagger'; | ||
import { | ||
ArrayNotEmpty, | ||
IsArray, | ||
IsBoolean, | ||
IsEnum, | ||
IsInt, | ||
IsOptional, | ||
IsString, | ||
Min, | ||
Max, | ||
} from 'class-validator'; | ||
import { OrderBy } from './../../../common/order.type'; | ||
import { WorkspaceLogType } from '../attributes/workspace-logs.attributes'; | ||
import { Transform, Type } from 'class-transformer'; | ||
|
||
export class GetWorkspaceLogsDto { | ||
@IsOptional() | ||
@IsArray() | ||
@ArrayNotEmpty() | ||
@IsEnum(WorkspaceLogType, { each: true }) | ||
activity?: WorkspaceLogType[]; | ||
|
||
@ApiPropertyOptional({ | ||
description: 'Order by', | ||
example: 'name:asc', | ||
}) | ||
@IsOptional() | ||
@IsString() | ||
orderBy?: OrderBy; | ||
|
||
@IsOptional() | ||
@IsInt() | ||
@Min(1) | ||
@Max(25) | ||
@Type(() => Number) | ||
limit?: number; | ||
|
||
@IsOptional() | ||
@IsInt() | ||
@Min(0) | ||
@Type(() => Number) | ||
offset?: number; | ||
|
||
@IsOptional() | ||
@IsString() | ||
member?: string; | ||
|
||
@IsOptional() | ||
@IsInt() | ||
@Min(0) | ||
@Max(90) | ||
@Type(() => Number) | ||
lastDays?: number; | ||
|
||
@IsOptional() | ||
@Transform(({ value }) => value === 'true') | ||
@IsBoolean() | ||
summary?: boolean = true; | ||
} |
Oops, something went wrong.