Skip to content

Commit

Permalink
Merge branch 'main' into N21-1207-show-group-members
Browse files Browse the repository at this point in the history
  • Loading branch information
arnegns committed Oct 20, 2023
2 parents 714abe6 + 0ab2dfb commit 385ad0e
Show file tree
Hide file tree
Showing 52 changed files with 157 additions and 144 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Body, Controller, Delete, Get, Param, Patch, Query } from '@nestjs/common';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { EntityNotFoundError, ForbiddenOperationError, ValidationError } from '@shared/common';
import { ICurrentUser } from '@src/modules/authentication';
import { Authenticate, CurrentUser } from '@src/modules/authentication/decorator/auth.decorator';
import { ICurrentUser, Authenticate, CurrentUser } from '@src/modules/authentication';
import { AccountUc } from '../uc/account.uc';
import {
AccountByIdBodyParams,
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/modules/account/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './account.module';
export * from './account-config';
export { AccountService } from './services';
1 change: 1 addition & 0 deletions apps/server/src/modules/account/services/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './account.service';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Body, Controller, HttpCode, HttpStatus, Post, UseGuards } from '@nestjs
import { AuthGuard } from '@nestjs/passport';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { ForbiddenOperationError, ValidationError } from '@shared/common';
import { CurrentUser } from '../decorator/auth.decorator';
import { CurrentUser } from '../decorator';
import type { ICurrentUser, OauthCurrentUser } from '../interface';
import { LoginDto } from '../uc/dto';
import { LoginUc } from '../uc/login.uc';
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/modules/authentication/decorator/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './auth.decorator';
4 changes: 4 additions & 0 deletions apps/server/src/modules/authentication/errors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './brute-force.error';
export * from './ldap-connection.error';
export * from './school-in-migration.error';
export * from './unauthorized.loggable-exception';
4 changes: 2 additions & 2 deletions apps/server/src/modules/authentication/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './interface';
export * from './guard/jwt-auth.guard';
export { ICurrentUser } from './interface';
export { JWT, CurrentUser, Authenticate } from './decorator';
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface CreateJwtPayload {
roles: string[];
systemId?: string; // without this the user needs to change his PW during first login
support?: boolean;
// support UserId is missed see featherJS
}

export interface JwtPayload extends CreateJwtPayload {
Expand Down
24 changes: 0 additions & 24 deletions apps/server/src/modules/authentication/interface/user.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,5 @@
import { EntityId } from '@shared/domain';

export interface IRole {
name: string;

id: string;
}

export interface IResolvedUser {
firstName: string;

lastName: string;

id: string;

createdAt: Date;

updatedAt: Date;

roles: IRole[];

permissions: string[];

schoolId: string;
}

export interface ICurrentUser {
/** authenticated users id */
userId: EntityId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { JwtService } from '@nestjs/jwt';
import { AccountService } from '@src/modules/account/services/account.service';
import { AccountService } from '@src/modules/account';
// invalid import
import { AccountDto } from '@src/modules/account/services/dto';
import { JwtValidationAdapter } from '@src/modules/authentication/strategy/jwt-validation.adapter';
// invalid import, can produce dependency cycles
import type { IServerConfig } from '@src/modules/server';
import { randomUUID } from 'crypto';
import jwt, { JwtPayload } from 'jsonwebtoken';
import { BruteForceError } from '../errors/brute-force.error';
import { UnauthorizedLoggableException } from '../errors/unauthorized.loggable-exception';
import { JwtValidationAdapter } from '../strategy/jwt-validation.adapter';
import { BruteForceError, UnauthorizedLoggableException } from '../errors';
import { CreateJwtPayload } from '../interface/jwt-payload';
import { LoginDto } from '../uc/dto';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '@shared/testing';
import { ICurrentUser } from '@src/modules/authentication';
import { JwtAuthGuard } from '@src/modules/authentication/guard/jwt-auth.guard';
import { ServerTestModule } from '@src/modules/server/server.module';
import { ServerTestModule } from '@src/modules/server';
import { Request } from 'express';
import request from 'supertest';
import { BoardResponse } from '../dto';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '@shared/testing';
import { ICurrentUser } from '@src/modules/authentication';
import { JwtAuthGuard } from '@src/modules/authentication/guard/jwt-auth.guard';
import { ServerTestModule } from '@src/modules/server/server.module';
import { ServerTestModule } from '@src/modules/server';
import { Request } from 'express';
import request from 'supertest';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Body, Controller, ForbiddenException, Get, HttpCode, NotFoundException, Param, Patch } from '@nestjs/common';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { ApiValidationError } from '@shared/common';
import { ICurrentUser } from '@src/modules/authentication';
import { Authenticate, CurrentUser } from '@src/modules/authentication/decorator/auth.decorator';
import { SubmissionsResponse } from '@src/modules/board/controller/dto/submission-item/submissions.response';
import { ICurrentUser, Authenticate, CurrentUser } from '@src/modules/authentication';
import { SubmissionsResponse } from './dto/submission-item/submissions.response';
import { CardUc } from '../uc';
import { ElementUc } from '../uc/element.uc';
import { SubmissionItemUc } from '../uc/submission-item.uc';
Expand Down
3 changes: 1 addition & 2 deletions apps/server/src/modules/board/controller/board.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import {
} from '@nestjs/common';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { ApiValidationError } from '@shared/common';
import { ICurrentUser } from '@src/modules/authentication';
import { Authenticate, CurrentUser } from '@src/modules/authentication/decorator/auth.decorator';
import { ICurrentUser, Authenticate, CurrentUser } from '@src/modules/authentication';
import { BoardUc } from '../uc';
import { BoardResponse, BoardUrlParams, ColumnResponse, RenameBodyParams } from './dto';
import { BoardContextResponse } from './dto/board/board-context.reponse';
Expand Down
3 changes: 1 addition & 2 deletions apps/server/src/modules/board/controller/card.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import {
} from '@nestjs/common';
import { ApiExtraModels, ApiOperation, ApiResponse, ApiTags, getSchemaPath } from '@nestjs/swagger';
import { ApiValidationError } from '@shared/common';
import { ICurrentUser } from '@src/modules/authentication';
import { Authenticate, CurrentUser } from '@src/modules/authentication/decorator/auth.decorator';
import { ICurrentUser, Authenticate, CurrentUser } from '@src/modules/authentication';
import { BoardUc, CardUc } from '../uc';
import {
AnyContentElementResponse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import {
} from '@nestjs/common';
import { ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { ApiValidationError } from '@shared/common';
import { ICurrentUser } from '@src/modules/authentication';
import { Authenticate, CurrentUser } from '@src/modules/authentication/decorator/auth.decorator';
import { ICurrentUser, Authenticate, CurrentUser } from '@src/modules/authentication';
import { BoardUc } from '../uc';
import { CardResponse, ColumnUrlParams, MoveColumnBodyParams, RenameBodyParams } from './dto';
import { CardResponseMapper } from './mapper';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import {
} from '@nestjs/common';
import { ApiBody, ApiExtraModels, ApiOperation, ApiResponse, ApiTags, getSchemaPath } from '@nestjs/swagger';
import { ApiValidationError } from '@shared/common';
import { ICurrentUser } from '@src/modules/authentication';
import { Authenticate, CurrentUser } from '@src/modules/authentication/decorator/auth.decorator';
import { ICurrentUser, Authenticate, CurrentUser } from '@src/modules/authentication';
import { CardUc } from '../uc';
import { ElementUc } from '../uc/element.uc';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ApiResponse, ApiTags } from '@nestjs/swagger';
import { Body, Controller, Param, Patch } from '@nestjs/common';
import { Authenticate, CurrentUser } from '@src/modules/authentication/decorator/auth.decorator';
import { Authenticate, CurrentUser, ICurrentUser } from '@src/modules/authentication';
import { LegacyLogger } from '@src/core/logger';
import { ICurrentUser } from '../../authentication/interface/user';
import { CollaborativeStorageUc } from '../uc/collaborative-storage.uc';
import { TeamPermissionsBody } from './dto/team-permissions.body.params';
import { TeamRoleDto } from './dto/team-role.params';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import {
import { ApiConsumes, ApiHeader, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { ApiValidationError, RequestLoggingInterceptor } from '@shared/common';
import { PaginationParams } from '@shared/controller';
import { ICurrentUser } from '@src/modules/authentication';
import { Authenticate, CurrentUser } from '@src/modules/authentication/decorator/auth.decorator';
import { ICurrentUser, Authenticate, CurrentUser } from '@src/modules/authentication';
import { Request, Response } from 'express';
import { GetFileResponse } from '../interface';
import { FilesStorageMapper } from '../mapper';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
StreamableFile,
} from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { Authenticate } from '@src/modules/authentication/decorator/auth.decorator';
import { Authenticate } from '@src/modules/authentication';
import { Request, Response } from 'express';
import { FwuLearningContentsUc } from '../uc/fwu-learning-contents.uc';
import { GetFwuLearningContentParams } from './dto/fwu-learning-contents.params';
Expand Down
3 changes: 1 addition & 2 deletions apps/server/src/modules/group/controller/group.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { PaginationParams } from '@shared/controller';
import { Page } from '@shared/domain';
import { ErrorResponse } from '@src/core/error/dto';
import { ICurrentUser } from '@src/modules/authentication';
import { Authenticate, CurrentUser } from '@src/modules/authentication/decorator/auth.decorator';
import { ICurrentUser, Authenticate, CurrentUser } from '@src/modules/authentication';
import { GroupUc } from '../uc';
import { ClassInfoDto, ResolvedGroupDto } from '../uc/dto';
import { ClassInfoSearchListResponse, ClassSortParams, GroupIdParams, GroupResponse } from './dto';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BadRequestException, Controller, ForbiddenException, Get, InternalServerErrorException } from '@nestjs/common';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { ApiValidationError } from '@shared/common';
import { Authenticate } from '@src/modules/authentication/decorator/auth.decorator';
import { Authenticate } from '@src/modules/authentication';

// Dummy html response so we can test i-frame integration
const dummyResponse = (title: string) => `
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Controller, Get, NotFoundException, Param, Query, Res, StreamableFile } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { Authenticate, CurrentUser } from '@src/modules/authentication/decorator/auth.decorator';
import { ICurrentUser, Authenticate, CurrentUser } from '@src/modules/authentication';
import { PaginationParams } from '@shared/controller/';
import { ICurrentUser } from '@src/modules/authentication';
import { Response } from 'express';
import { ConfigService } from '@nestjs/config';
import { CourseUc } from '../uc/course.uc';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Body, Controller, Get, Param, Patch, Query } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { ICurrentUser } from '@src/modules/authentication';
import { Authenticate, CurrentUser } from '@src/modules/authentication/decorator/auth.decorator';
import { ICurrentUser, Authenticate, CurrentUser } from '@src/modules/authentication';
import { DashboardMapper } from '../mapper/dashboard.mapper';
import { DashboardUc } from '../uc/dashboard.uc';
import { DashboardResponse, DashboardUrlParams, MoveElementParams, PatchGroupParams } from './dto';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { RequestTimeout } from '@shared/common';
import { ICurrentUser } from '@src/modules/authentication';
import { Authenticate, CurrentUser } from '@src/modules/authentication/decorator/auth.decorator';
import { ICurrentUser, Authenticate, CurrentUser } from '@src/modules/authentication';
import { CopyApiResponse, CopyMapper } from '@src/modules/copy-helper';
import { serverConfig } from '@src/modules/server/server.config';
import { RoomBoardResponseMapper } from '../mapper/room-board-response.mapper';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {
ApiTags,
ApiUnauthorizedResponse,
} from '@nestjs/swagger';
import { ICurrentUser } from '@src/modules/authentication';
import { Authenticate, CurrentUser } from '@src/modules/authentication/decorator/auth.decorator';
import { ICurrentUser, Authenticate, CurrentUser } from '@src/modules/authentication';
import { MigrationMapper } from '../mapper/migration.mapper';
import { OauthMigrationDto } from '../uc/dto/oauth-migration.dto';
import { LegacySchoolUc } from '../uc';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Controller, Delete, Param } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { ICurrentUser } from '@src/modules/authentication';
import { Authenticate, CurrentUser } from '@src/modules/authentication/decorator/auth.decorator';
import { ICurrentUser, Authenticate, CurrentUser } from '@src/modules/authentication';
import { LessonUC } from '../uc';
import { LessonUrlParams } from './dto';

Expand Down
49 changes: 49 additions & 0 deletions apps/server/src/modules/lesson/service/lesson-copy.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,55 @@ describe('lesson copy service', () => {
});
});

describe('when lesson contains LernStore content element without set resource', () => {
const setup = () => {
const lernStoreContent: IComponentProperties = {
title: 'text component 1',
hidden: false,
component: ComponentType.LERNSTORE,
};
const user = userFactory.build();
const originalCourse = courseFactory.build({ school: user.school });
const destinationCourse = courseFactory.build({ school: user.school, teachers: [user] });
const originalLesson = lessonFactory.build({
course: originalCourse,
contents: [lernStoreContent],
});
lessonRepo.findById.mockResolvedValueOnce(originalLesson);

return { user, originalCourse, destinationCourse, originalLesson, lernStoreContent };
};

it('the content should be fully copied', async () => {
const { user, destinationCourse, originalLesson, lernStoreContent } = setup();

const status = await copyService.copyLesson({
originalLessonId: originalLesson.id,
destinationCourse,
user,
});

const copiedLessonContents = (status.copyEntity as LessonEntity).contents as IComponentProperties[];
expect(copiedLessonContents[0]).toEqual(lernStoreContent);
});

it('should set content type to LESSON_CONTENT_LERNSTORE', async () => {
const { user, destinationCourse, originalLesson } = setup();

const status = await copyService.copyLesson({
originalLessonId: originalLesson.id,
destinationCourse,
user,
});
const contentsStatus = status.elements?.find((el) => el.type === CopyElementType.LESSON_CONTENT_GROUP);
expect(contentsStatus).toBeDefined();
if (contentsStatus?.elements) {
expect(contentsStatus.elements[0].type).toEqual(CopyElementType.LESSON_CONTENT_LERNSTORE);
expect(contentsStatus.elements[0].status).toEqual(CopyStatusEnum.SUCCESS);
}
});
});

describe('when lesson contains geoGebra content element', () => {
const setup = () => {
const geoGebraContent: IComponentProperties = {
Expand Down
39 changes: 21 additions & 18 deletions apps/server/src/modules/lesson/service/lesson-copy.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,29 +266,32 @@ export class LessonCopyService {
}

private copyLernStore(element: IComponentProperties): IComponentProperties {
const resources = ((element.content as IComponentLernstoreProperties).resources ?? []).map(
({ client, description, merlinReference, title, url }) => {
const result = {
client,
description,
merlinReference,
title,
url,
};
return result;
}
);

const lernstore = {
const lernstore: IComponentProperties = {
title: element.title,
hidden: element.hidden,
component: ComponentType.LERNSTORE,
user: element.user, // TODO should be params.user - but that made the server crash, but property is normally undefined
content: {
resources,
},
};
return lernstore as IComponentProperties;

if (element.content) {
const resources = ((element.content as IComponentLernstoreProperties).resources ?? []).map(
({ client, description, merlinReference, title, url }) => {
const result = {
client,
description,
merlinReference,
title,
url,
};
return result;
}
);

const lernstoreContent: IComponentLernstoreProperties = { resources };
lernstore.content = lernstoreContent;
}

return lernstore;
}

private static copyGeogebra(originalElement: IComponentProperties): IComponentProperties {
Expand Down
3 changes: 1 addition & 2 deletions apps/server/src/modules/news/controller/news.controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Body, Controller, Delete, Get, Param, Patch, Post, Query } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { PaginationParams } from '@shared/controller';
import { ICurrentUser } from '@src/modules/authentication';
import { Authenticate, CurrentUser } from '@src/modules/authentication/decorator/auth.decorator';
import { ICurrentUser, Authenticate, CurrentUser } from '@src/modules/authentication';
import { NewsMapper } from '../mapper/news.mapper';
import { NewsUc } from '../uc/news.uc';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { Controller, Get, Param, Query } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { ICurrentUser } from '@src/modules/authentication';

import { ICurrentUser, Authenticate, CurrentUser } from '@src/modules/authentication';
import { PaginationParams } from '@shared/controller';
import { Authenticate, CurrentUser } from '@src/modules/authentication/decorator/auth.decorator';

import { NewsMapper } from '../mapper/news.mapper';
import { NewsUc } from '../uc';
import { FilterNewsParams, NewsListResponse, TeamUrlParams } from './dto';
Expand Down
Loading

0 comments on commit 385ad0e

Please sign in to comment.