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 11 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 { LegacyLogger } 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: LegacyLogger,
useValue: createMock<LegacyLogger>(),
},
],
}).compile();

Expand Down
9 changes: 7 additions & 2 deletions apps/server/src/modules/class/service/class.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Injectable, InternalServerErrorException } from '@nestjs/common';
import { EntityId } from '@shared/domain/types';
import { LegacyLogger } from '@src/core/logger';
WojciechGrancow marked this conversation as resolved.
Show resolved Hide resolved
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: LegacyLogger) {
this.logger.setContext(ClassService.name);
}

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

// FIXME There is no usage of this method
public async deleteUserDataFromClasses(userId: EntityId): Promise<number> {
this.logger.log({ action: 'Deleting data from Classes for user ', userId });

if (!userId) {
throw new InternalServerErrorException('User id is missing');
}
Expand All @@ -35,6 +39,7 @@ export class ClassService {
});

await this.classesRepo.updateMany(updatedClasses);
this.logger.log({ action: 'Deleted data from Classes for user ', userId });
WojciechGrancow marked this conversation as resolved.
Show resolved Hide resolved

return updatedClasses.length;
}
Expand Down
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 { LegacyLogger } 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: LegacyLogger,
useValue: createMock<LegacyLogger>(),
},
],
}).compile();

Expand Down
11 changes: 10 additions & 1 deletion apps/server/src/modules/files/service/files.service.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { Injectable } from '@nestjs/common';
import { EntityId } from '@shared/domain/types';
import { LegacyLogger } from '@src/core/logger';
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: LegacyLogger) {
this.logger.setContext(FilesService.name);
}

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

async removeUserPermissionsToAnyFiles(userId: EntityId): Promise<number> {
this.logger.log({ action: 'Deleting Permissions To Any Files for user ', userId });
const entities = await this.repo.findByPermissionRefId(userId);

if (entities.length === 0) {
Expand All @@ -22,6 +26,8 @@ export class FilesService {

await this.repo.save(entities);

this.logger.log({ action: 'Deleted Permissions To Any Files for user ', userId });
WojciechGrancow marked this conversation as resolved.
Show resolved Hide resolved

return entities.length;
}

Expand All @@ -30,6 +36,7 @@ export class FilesService {
}

async markFilesOwnedByUserForDeletion(userId: EntityId): Promise<number> {
this.logger.log({ action: 'Marking Files For Deletion Owned By user ', userId });
const entities = await this.repo.findByOwnerUserId(userId);

if (entities.length === 0) {
Expand All @@ -40,6 +47,8 @@ export class FilesService {

await this.repo.save(entities);

this.logger.log({ action: 'Marked Files For Deletion Owned By user ', userId });
WojciechGrancow marked this conversation as resolved.
Show resolved Hide resolved

return entities.length;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { CourseRepo, UserRepo } from '@shared/repo';
import { courseFactory, setupEntities, userFactory } from '@shared/testing';
import { CourseService } from './course.service';
import { LegacyLogger } from '@src/core/logger';

Check failure on line 7 in apps/server/src/modules/learnroom/service/course.service.spec.ts

View workflow job for this annotation

GitHub Actions / nest_lint

`@src/core/logger` import should occur before import of `./course.service`
WojciechGrancow marked this conversation as resolved.
Show resolved Hide resolved

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

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

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

public async deleteUserDataFromCourse(userId: EntityId): Promise<number> {
this.logger.log({ action: 'Deleting data from Courses for user ', userId });
const [courses, count] = await this.repo.findAllByUserId(userId);

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

await this.repo.save(courses);
this.logger.log({ action: 'Deleting data from Courses for user ', userId });
WojciechGrancow marked this conversation as resolved.
Show resolved Hide resolved

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 { LegacyLogger } 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: LegacyLogger,
useValue: createMock<LegacyLogger>(),
},
],
}).compile();
courseGroupRepo = module.get(CourseGroupRepo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import { Injectable } from '@nestjs/common';
import { CourseGroup } from '@shared/domain/entity';
import { Counted, EntityId } from '@shared/domain/types';
import { CourseGroupRepo } from '@shared/repo';
import { LegacyLogger } from '@src/core/logger';

@Injectable()
export class CourseGroupService {
constructor(private readonly repo: CourseGroupRepo) {}
constructor(private readonly repo: CourseGroupRepo, private readonly logger: LegacyLogger) {
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 +17,13 @@ export class CourseGroupService {
}

public async deleteUserDataFromCourseGroup(userId: EntityId): Promise<number> {
this.logger.log({ action: 'Deleting data from CourseGroup for user ', userId });
const [courseGroups, count] = await this.repo.findByUserId(userId);

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

await this.repo.save(courseGroups);
this.logger.log({ action: 'Deleted data from CourseGroup for user ', userId });
WojciechGrancow marked this conversation as resolved.
Show resolved Hide resolved

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 { LegacyLogger } 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: LegacyLogger,
useValue: createMock<LegacyLogger>(),
},
],
}).compile();
dashboardService = module.get(DashboardService);
Expand Down
10 changes: 8 additions & 2 deletions apps/server/src/modules/learnroom/service/dashboard.service.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import { Inject, Injectable } from '@nestjs/common';
import { EntityId } from '@shared/domain/types';
import { IDashboardRepo, DashboardElementRepo } from '@shared/repo';
import { LegacyLogger } 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: LegacyLogger
) {
this.logger.setContext(DashboardService.name);
}

async deleteDashboardByUserId(userId: EntityId): Promise<number> {
this.logger.log({ action: 'Deleting dasboard for userId - ', userId });
const usersDashboard = await this.dashboardRepo.getUsersDashboard(userId);
await this.dashboardElementRepo.deleteByDashboardId(usersDashboard.id);
const result = await this.dashboardRepo.deleteDashboardByUserId(userId);
this.logger.log({ action: 'Deleted dasboard for userId - ', userId });
WojciechGrancow marked this conversation as resolved.
Show resolved Hide resolved

return result;
}
Expand Down
5 changes: 5 additions & 0 deletions apps/server/src/modules/lesson/service/lesson.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FilesStorageClientAdapterService } from '@modules/files-storage-client'
import { Test, TestingModule } from '@nestjs/testing';
import { ComponentProperties, ComponentType } from '@shared/domain/entity';
import { lessonFactory, setupEntities } from '@shared/testing';
import { LegacyLogger } from '@src/core/logger';
import { LessonRepo } from '../repository';
import { LessonService } from './lesson.service';

Expand All @@ -26,6 +27,10 @@ describe('LessonService', () => {
provide: FilesStorageClientAdapterService,
useValue: createMock<FilesStorageClientAdapterService>(),
},
{
provide: LegacyLogger,
useValue: createMock<LegacyLogger>(),
},
],
}).compile();
lessonService = module.get(LessonService);
Expand Down
11 changes: 9 additions & 2 deletions apps/server/src/modules/lesson/service/lesson.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import { Injectable } from '@nestjs/common';
import { ComponentProperties, LessonEntity } from '@shared/domain/entity';
import { Counted, EntityId } from '@shared/domain/types';
import { AuthorizationLoaderService } from '@src/modules/authorization';
import { LegacyLogger } from '@src/core/logger';
import { LessonRepo } from '../repository';

@Injectable()
export class LessonService implements AuthorizationLoaderService {
constructor(
private readonly lessonRepo: LessonRepo,
private readonly filesStorageClientAdapterService: FilesStorageClientAdapterService
) {}
private readonly filesStorageClientAdapterService: FilesStorageClientAdapterService,
private readonly logger: LegacyLogger
) {
this.logger.setContext(LessonService.name);
}

async deleteLesson(lesson: LessonEntity): Promise<void> {
await this.filesStorageClientAdapterService.deleteFilesOfParent(lesson.id);
Expand All @@ -33,6 +37,7 @@ export class LessonService implements AuthorizationLoaderService {
}

async deleteUserDataFromLessons(userId: EntityId): Promise<number> {
this.logger.log({ action: 'Deleting User Data From Lesson for user ', userId });
const lessons = await this.lessonRepo.findByUserId(userId);

const updatedLessons = lessons.map((lesson: LessonEntity) => {
Expand All @@ -47,6 +52,8 @@ export class LessonService implements AuthorizationLoaderService {

await this.lessonRepo.save(updatedLessons);

this.logger.log({ action: 'Deleted User Data From Lesson for user ', userId });
WojciechGrancow marked this conversation as resolved.
Show resolved Hide resolved

return updatedLessons.length;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { IFindOptions } from '@shared/domain/interface';

import { LtiToolDO, Page, Pseudonym, UserDO } from '@shared/domain/domainobject';
import { externalToolFactory, ltiToolDOFactory, pseudonymFactory, userDoFactory } from '@shared/testing/factory';
import { LegacyLogger } from '@src/core/logger';
import { PseudonymSearchQuery } from '../domain';
import { ExternalToolPseudonymRepo, PseudonymsRepo } from '../repo';
import { PseudonymService } from './pseudonym.service';
Expand All @@ -30,6 +31,10 @@ describe('PseudonymService', () => {
provide: ExternalToolPseudonymRepo,
useValue: createMock<ExternalToolPseudonymRepo>(),
},
{
provide: LegacyLogger,
useValue: createMock<LegacyLogger>(),
},
],
}).compile();

Expand Down
10 changes: 8 additions & 2 deletions apps/server/src/modules/pseudonym/service/pseudonym.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ import { Injectable, InternalServerErrorException } from '@nestjs/common';
import { LtiToolDO, Page, Pseudonym, UserDO } from '@shared/domain/domainobject';
import { IFindOptions } from '@shared/domain/interface';
import { v4 as uuidv4 } from 'uuid';
import { LegacyLogger } from '@src/core/logger';
import { PseudonymSearchQuery } from '../domain';
import { ExternalToolPseudonymRepo, PseudonymsRepo } from '../repo';

@Injectable()
export class PseudonymService {
constructor(
private readonly pseudonymRepo: PseudonymsRepo,
private readonly externalToolPseudonymRepo: ExternalToolPseudonymRepo
) {}
private readonly externalToolPseudonymRepo: ExternalToolPseudonymRepo,
private readonly logger: LegacyLogger
) {
this.logger.setContext(PseudonymService.name);
}

public async findByUserAndToolOrThrow(user: UserDO, tool: ExternalTool | LtiToolDO): Promise<Pseudonym> {
if (!user.id || !tool.id) {
Expand Down Expand Up @@ -73,6 +77,7 @@ export class PseudonymService {
}

public async deleteByUserId(userId: string): Promise<number> {
this.logger.log({ action: 'Deleting Pseudonyms for user ', userId });
if (!userId) {
throw new InternalServerErrorException('User id is missing');
}
Expand All @@ -81,6 +86,7 @@ export class PseudonymService {
this.deletePseudonymsByUserId(userId),
this.deleteExternalToolPseudonymsByUserId(userId),
]);
this.logger.log({ action: 'Deleted Pseudonyms for user ', userId });
WojciechGrancow marked this conversation as resolved.
Show resolved Hide resolved

return deletedPseudonyms + deletedExternalToolPseudonyms;
}
Expand Down
Loading
Loading