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

BC-6082 Add Logger to KNL-Module #4668

Merged
merged 25 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
64830b3
add logger to registrationPin deleteService
WojciechGrancow Dec 29, 2023
a5bae20
add logger to dashboardModule deleteService
WojciechGrancow Dec 29, 2023
8a9247a
add logger to classModule deleteService
WojciechGrancow Dec 29, 2023
b8df859
add logger to courseGroupService for delete method
WojciechGrancow Dec 29, 2023
72627f8
add logger to courseService for delete method
WojciechGrancow Dec 29, 2023
59740db
add logger to FilesModule for removePermision and markFordeletion
WojciechGrancow Dec 29, 2023
e596193
add logger to LessonModule for removeUserData from lessons
WojciechGrancow Dec 29, 2023
1d888f9
add logger to pseudonymService and add logger import in course test
WojciechGrancow Jan 2, 2024
45f886b
add logger to teamService in team module
WojciechGrancow Jan 2, 2024
37e31c7
add logger to userService for deleteUsermethod in user module
WojciechGrancow Jan 2, 2024
6f4f906
add logger to RocketChatUser and to RocketChat Services for delete me…
WojciechGrancow Jan 2, 2024
ca57167
Update apps/server/src/modules/learnroom/service/course.service.spec.ts
WojciechGrancow Jan 4, 2024
9b74b29
add additional metadata to logs during deletion user data for services
WojciechGrancow Jan 4, 2024
1dbfedc
fix test
WojciechGrancow Jan 4, 2024
289175d
Merge branch 'main' into BC-6082-add-logger-to-KNL-module
WojciechGrancow Jan 4, 2024
dce0c7b
some fixes
WojciechGrancow Jan 8, 2024
ba666be
Merge branch 'main' into BC-6082-add-logger-to-KNL-module
WojciechGrancow Jan 8, 2024
93393b9
fix after review
WojciechGrancow Jan 10, 2024
5caf15d
Merge branch 'main' into BC-6082-add-logger-to-KNL-module
WojciechGrancow Jan 10, 2024
4c44540
Merge branch 'main' into BC-6082-add-logger-to-KNL-module
WojciechGrancow Jan 10, 2024
391161e
change logger in teams module
WojciechGrancow Jan 10, 2024
f456dfd
Merge branch 'main' into BC-6082-add-logger-to-KNL-module
WojciechGrancow Jan 14, 2024
21c0639
Merge branch 'main' into BC-6082-add-logger-to-KNL-module
sszafGCA Jan 14, 2024
f6e43b8
add import in pseudonym module
WojciechGrancow Jan 14, 2024
8a24e22
Merge branch 'BC-6082-add-logger-to-KNL-module' of https://github.com…
WojciechGrancow Jan 14, 2024
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
2 changes: 2 additions & 0 deletions apps/server/src/modules/class/class.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Module } from '@nestjs/common';
import { LoggerModule } from '@src/core/logger';
import { ClassService } from './service';
import { ClassesRepo } from './repo';

@Module({
imports: [LoggerModule],
providers: [ClassService, ClassesRepo],
exports: [ClassService],
})
Expand Down
5 changes: 5 additions & 0 deletions apps/server/src/modules/class/service/class.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { InternalServerErrorException } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { EntityId } from '@shared/domain/types';
import { setupEntities } from '@shared/testing';
import { Logger } from '@src/core/logger';
import { Class } from '../domain';
import { classFactory } from '../domain/testing';
import { classEntityFactory } from '../entity/testing';
Expand All @@ -24,6 +25,10 @@ describe(ClassService.name, () => {
provide: ClassesRepo,
useValue: createMock<ClassesRepo>(),
},
{
provide: Logger,
useValue: createMock<Logger>(),
},
],
}).compile();

Expand Down
32 changes: 28 additions & 4 deletions apps/server/src/modules/class/service/class.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Injectable, InternalServerErrorException } from '@nestjs/common';
import { EntityId } from '@shared/domain/types';
import { DomainModel, EntityId, StatusModel } from '@shared/domain/types';
import { Logger } from '@src/core/logger';
import { DataDeletionDomainOperationLoggable } from '@shared/common/loggable';
import { Class } from '../domain';
import { ClassesRepo } from '../repo';

@Injectable()
export class ClassService {
constructor(private readonly classesRepo: ClassesRepo) {}
constructor(private readonly classesRepo: ClassesRepo, private readonly logger: Logger) {
this.logger.setContext(ClassService.name);
}

public async findClassesForSchool(schoolId: EntityId): Promise<Class[]> {
const classes: Class[] = await this.classesRepo.findAllBySchoolId(schoolId);
Expand All @@ -19,8 +23,16 @@ export class ClassService {
return classes;
}

// FIXME There is no usage of this method
public async deleteUserDataFromClasses(userId: EntityId): Promise<number> {
this.logger.info(
new DataDeletionDomainOperationLoggable(
'Deleting data from Classes',
DomainModel.CLASS,
userId,
StatusModel.PENDING
)
);

if (!userId) {
throw new InternalServerErrorException('User id is missing');
}
Expand All @@ -34,8 +46,20 @@ export class ClassService {
return domainObject;
});

const numberOfUpdatedClasses = updatedClasses.length;

await this.classesRepo.updateMany(updatedClasses);
this.logger.info(
new DataDeletionDomainOperationLoggable(
'Successfully removed user data from Classes',
DomainModel.CLASS,
userId,
StatusModel.FINISHED,
numberOfUpdatedClasses,
0
)
);

return updatedClasses.length;
return numberOfUpdatedClasses;
}
}
5 changes: 5 additions & 0 deletions apps/server/src/modules/files/service/files.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ObjectId } from '@mikro-orm/mongodb';
import { Test, TestingModule } from '@nestjs/testing';
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { setupEntities } from '@shared/testing';
import { Logger } from '@src/core/logger';
import { FilesService } from './files.service';
import { FilesRepo } from '../repo';
import { fileEntityFactory, filePermissionEntityFactory } from '../entity/testing';
Expand All @@ -20,6 +21,10 @@ describe(FilesService.name, () => {
provide: FilesRepo,
useValue: createMock<FilesRepo>(),
},
{
provide: Logger,
useValue: createMock<Logger>(),
},
],
}).compile();

Expand Down
54 changes: 50 additions & 4 deletions apps/server/src/modules/files/service/files.service.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import { Injectable } from '@nestjs/common';
import { EntityId } from '@shared/domain/types';
import { DomainModel, EntityId, StatusModel } from '@shared/domain/types';
import { Logger } from '@src/core/logger';
import { DataDeletionDomainOperationLoggable } from '@shared/common/loggable';
import { FileEntity } from '../entity';
import { FilesRepo } from '../repo';

@Injectable()
export class FilesService {
constructor(private readonly repo: FilesRepo) {}
constructor(private readonly repo: FilesRepo, private readonly logger: Logger) {
this.logger.setContext(FilesService.name);
}

async findFilesAccessibleOrCreatedByUser(userId: EntityId): Promise<FileEntity[]> {
return this.repo.findByPermissionRefIdOrCreatorId(userId);
}

async removeUserPermissionsOrCreatorReferenceToAnyFiles(userId: EntityId): Promise<number> {
this.logger.info(
new DataDeletionDomainOperationLoggable(
'Deleting user data from Files',
DomainModel.FILE,
userId,
StatusModel.PENDING
)
);
const entities = await this.repo.findByPermissionRefIdOrCreatorId(userId);

if (entities.length === 0) {
Expand All @@ -25,14 +37,35 @@ export class FilesService {

await this.repo.save(entities);

return entities.length;
const numberOfUpdatedFiles = entities.length;

this.logger.info(
new DataDeletionDomainOperationLoggable(
'Successfully removed user data from Files',
DomainModel.FILE,
userId,
StatusModel.FINISHED,
numberOfUpdatedFiles,
0
)
);

return numberOfUpdatedFiles;
}

async findFilesOwnedByUser(userId: EntityId): Promise<FileEntity[]> {
return this.repo.findByOwnerUserId(userId);
}

async markFilesOwnedByUserForDeletion(userId: EntityId): Promise<number> {
this.logger.info(
new DataDeletionDomainOperationLoggable(
'Marking user files to deletion',
DomainModel.FILE,
userId,
StatusModel.PENDING
)
);
const entities = await this.repo.findByOwnerUserId(userId);

if (entities.length === 0) {
Expand All @@ -43,6 +76,19 @@ export class FilesService {

await this.repo.save(entities);

return entities.length;
const numberOfMarkedForDeletionFiles = entities.length;

this.logger.info(
new DataDeletionDomainOperationLoggable(
'Successfully marked user files for deletion',
DomainModel.FILE,
userId,
StatusModel.FINISHED,
numberOfMarkedForDeletionFiles,
0
)
);

return numberOfMarkedForDeletionFiles;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Test, TestingModule } from '@nestjs/testing';
import { Course } from '@shared/domain/entity';
import { CourseRepo, UserRepo } from '@shared/repo';
import { courseFactory, setupEntities, userFactory } from '@shared/testing';
import { Logger } from '@src/core/logger';
import { CourseService } from './course.service';

describe('CourseService', () => {
Expand All @@ -24,6 +25,10 @@ describe('CourseService', () => {
provide: CourseRepo,
useValue: createMock<CourseRepo>(),
},
{
provide: Logger,
useValue: createMock<Logger>(),
},
],
}).compile();
courseRepo = module.get(CourseRepo);
Expand Down
26 changes: 24 additions & 2 deletions apps/server/src/modules/learnroom/service/course.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Injectable } from '@nestjs/common';
import { DataDeletionDomainOperationLoggable } from '@shared/common/loggable';
import { Course } from '@shared/domain/entity';
import { Counted, EntityId } from '@shared/domain/types';
import { Counted, DomainModel, EntityId, StatusModel } from '@shared/domain/types';
import { CourseRepo } from '@shared/repo';
import { Logger } from '@src/core/logger';

@Injectable()
export class CourseService {
constructor(private readonly repo: CourseRepo) {}
constructor(private readonly repo: CourseRepo, private readonly logger: Logger) {
this.logger.setContext(CourseService.name);
}

async findById(courseId: EntityId): Promise<Course> {
return this.repo.findById(courseId);
Expand All @@ -18,11 +22,29 @@ export class CourseService {
}

public async deleteUserDataFromCourse(userId: EntityId): Promise<number> {
this.logger.info(
new DataDeletionDomainOperationLoggable(
'Deleting data from Courses',
DomainModel.COURSE,
userId,
StatusModel.PENDING
)
);
const [courses, count] = await this.repo.findAllByUserId(userId);

courses.forEach((course: Course) => course.removeUser(userId));

await this.repo.save(courses);
this.logger.info(
new DataDeletionDomainOperationLoggable(
'Successfully removed data from Courses',
DomainModel.COURSE,
userId,
StatusModel.FINISHED,
0,
count
)
);

return count;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { Test, TestingModule } from '@nestjs/testing';
import { CourseGroupRepo, UserRepo } from '@shared/repo';
import { courseGroupFactory, setupEntities, userFactory } from '@shared/testing';
import { Logger } from '@src/core/logger';
import { CourseGroupService } from './coursegroup.service';

describe('CourseGroupService', () => {
Expand All @@ -23,6 +24,10 @@ describe('CourseGroupService', () => {
provide: CourseGroupRepo,
useValue: createMock<CourseGroupRepo>(),
},
{
provide: Logger,
useValue: createMock<Logger>(),
},
],
}).compile();
courseGroupRepo = module.get(CourseGroupRepo);
Expand Down
26 changes: 24 additions & 2 deletions apps/server/src/modules/learnroom/service/coursegroup.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Injectable } from '@nestjs/common';
import { DataDeletionDomainOperationLoggable } from '@shared/common/loggable';
import { CourseGroup } from '@shared/domain/entity';
import { Counted, EntityId } from '@shared/domain/types';
import { Counted, DomainModel, EntityId, StatusModel } from '@shared/domain/types';
import { CourseGroupRepo } from '@shared/repo';
import { Logger } from '@src/core/logger';

@Injectable()
export class CourseGroupService {
constructor(private readonly repo: CourseGroupRepo) {}
constructor(private readonly repo: CourseGroupRepo, private readonly logger: Logger) {
this.logger.setContext(CourseGroupService.name);
}

public async findAllCourseGroupsByUserId(userId: EntityId): Promise<Counted<CourseGroup[]>> {
const [courseGroups, count] = await this.repo.findByUserId(userId);
Expand All @@ -14,11 +18,29 @@ export class CourseGroupService {
}

public async deleteUserDataFromCourseGroup(userId: EntityId): Promise<number> {
this.logger.info(
new DataDeletionDomainOperationLoggable(
'Deleting user data from CourseGroup',
DomainModel.COURSEGROUP,
userId,
StatusModel.PENDING
)
);
const [courseGroups, count] = await this.repo.findByUserId(userId);

courseGroups.forEach((courseGroup) => courseGroup.removeStudent(userId));

await this.repo.save(courseGroups);
this.logger.info(
new DataDeletionDomainOperationLoggable(
'Successfully deleted user data from CourseGroup',
DomainModel.COURSEGROUP,
userId,
StatusModel.FINISHED,
count,
0
)
);

return count;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DashboardElementRepo, IDashboardRepo, UserRepo } from '@shared/repo';
import { setupEntities, userFactory } from '@shared/testing';
import { LearnroomMetadata, LearnroomTypes } from '@shared/domain/types';
import { DashboardEntity, GridElement } from '@shared/domain/entity';
import { Logger } from '@src/core/logger';
import { DashboardService } from '.';

const learnroomMock = (id: string, name: string) => {
Expand Down Expand Up @@ -44,6 +45,10 @@ describe(DashboardService.name, () => {
provide: DashboardElementRepo,
useValue: createMock<DashboardElementRepo>(),
},
{
provide: Logger,
useValue: createMock<Logger>(),
},
],
}).compile();
dashboardService = module.get(DashboardService);
Expand Down
29 changes: 26 additions & 3 deletions apps/server/src/modules/learnroom/service/dashboard.service.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
import { Inject, Injectable } from '@nestjs/common';
import { EntityId } from '@shared/domain/types';
import { DataDeletionDomainOperationLoggable } from '@shared/common/loggable';
import { DomainModel, EntityId, StatusModel } from '@shared/domain/types';
import { IDashboardRepo, DashboardElementRepo } from '@shared/repo';
import { Logger } from '@src/core/logger';

@Injectable()
export class DashboardService {
constructor(
@Inject('DASHBOARD_REPO') private readonly dashboardRepo: IDashboardRepo,
private readonly dashboardElementRepo: DashboardElementRepo
) {}
private readonly dashboardElementRepo: DashboardElementRepo,
private readonly logger: Logger
) {
this.logger.setContext(DashboardService.name);
}

async deleteDashboardByUserId(userId: EntityId): Promise<number> {
this.logger.info(
new DataDeletionDomainOperationLoggable(
'Deleting user data from Dashboard',
DomainModel.DASHBOARD,
userId,
StatusModel.PENDING
)
);
const usersDashboard = await this.dashboardRepo.getUsersDashboard(userId);
await this.dashboardElementRepo.deleteByDashboardId(usersDashboard.id);
const result = await this.dashboardRepo.deleteDashboardByUserId(userId);
this.logger.info(
new DataDeletionDomainOperationLoggable(
'Successfully deleted user data from Dashboard',
DomainModel.DASHBOARD,
userId,
StatusModel.FINISHED,
0,
result
)
);

return result;
}
Expand Down
Loading
Loading