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

Dev/sharing -> codecov #489

Merged
merged 31 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
23531b6
Created share request dto
JanSpies82 Sep 24, 2023
e37f77c
Share dto
JulianPienaar Sep 24, 2023
a0a3529
Created share backend infrastructure
JanSpies82 Sep 24, 2023
df536d5
Basic UI for sharing
JulianPienaar Sep 24, 2023
8c3690e
Integration of sharing
JulianPienaar Sep 24, 2023
1c196ed
Added clone function
JanSpies82 Sep 24, 2023
79d8d6c
Added functionality for sharing an empty doc
JanSpies82 Sep 24, 2023
2f03001
Added clone function in usages
JanSpies82 Sep 24, 2023
ea48202
Fixed exists
JanSpies82 Sep 24, 2023
0c1caeb
Update DTO + debugging output
JulianPienaar Sep 24, 2023
3cc805b
Changed backend MarkdownFIleID to markdownID
JanSpies82 Sep 24, 2023
0634f04
Removed outdated field
JanSpies82 Sep 24, 2023
f987b6a
Made spelling consistent
JanSpies82 Sep 24, 2023
1151237
Better toasts and error handling
JulianPienaar Sep 24, 2023
9785576
Refactored UI of sharing
JulianPienaar Sep 24, 2023
e0be778
Added enter button
JulianPienaar Sep 24, 2023
79770a5
Can now press enter on rename dialog
JulianPienaar Sep 24, 2023
ddcd0a5
Added document content copying
JanSpies82 Sep 24, 2023
de508c0
button colour tweaks
JulianPienaar Sep 24, 2023
c35522e
Fix when sharing with non existent user
JulianPienaar Sep 24, 2023
c582910
Fixed size of copied doc
JanSpies82 Sep 24, 2023
02a4c49
Allowing delete of locked doc
JulianPienaar Sep 24, 2023
af65dcc
Merge branch 'dev/sharing' of https://github.com/COS301-SE-2023/Write…
JulianPienaar Sep 24, 2023
f3b74a0
Implemented refresh button
JulianPienaar Sep 24, 2023
b6e87af
Added sharing to home page
JulianPienaar Sep 24, 2023
c246fe0
Implemented Cropping!
JulianPienaar Sep 24, 2023
6e2d6f9
Name length limit of tree
JulianPienaar Sep 24, 2023
12b588d
White text of adjust contrast
JulianPienaar Sep 24, 2023
55553d8
Throw exception upon deprecated endpoint use
JulianPienaar Sep 24, 2023
2a89694
Removed code duplication for sonar cloud+export removal
JulianPienaar Sep 24, 2023
a020c67
Fixed tests
JulianPienaar Sep 24, 2023
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
48 changes: 30 additions & 18 deletions backend/src/file_manager/__mocks__/file_manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,33 @@ export class FileManagerServiceMock {
const markdownFilesDTOArr: MarkdownFileDTO[] =
[];
files.forEach((file) => {
const markdownFileDTO: MarkdownFileDTO = {
MarkdownID: file.MarkdownID,
UserID: file.UserID,
DateCreated: file.DateCreated,
LastModified: file.LastModified,
Name: file.Name,
Path: file.Path,
Size: file.Size,
ParentFolderID: file.ParentFolderID,
Content: '',
SafeLock: false,
NewDiff: '',
NextDiffIndex: file.NextDiffIndex,
PreviousDiffs: [],
NextSnapshotIndex: file.NextSnapshotIndex,
TotalNumDiffs: file.TotalNumDiffs,
TotalNumSnapshots: file.TotalNumSnapshots,
};
const markdownFileDTO =
new MarkdownFileDTO();
markdownFileDTO.MarkdownID =
file.MarkdownID;
markdownFileDTO.UserID = file.UserID;
markdownFileDTO.DateCreated =
file.DateCreated;
markdownFileDTO.LastModified =
file.LastModified;
markdownFileDTO.Name = file.Name;
markdownFileDTO.Path = file.Path;
markdownFileDTO.Size = file.Size;
markdownFileDTO.ParentFolderID =
file.ParentFolderID;
markdownFileDTO.Content = '';
markdownFileDTO.SafeLock = false;
markdownFileDTO.NewDiff = '';
markdownFileDTO.NextDiffIndex =
file.NextDiffIndex;
markdownFileDTO.PreviousDiffs = [];
markdownFileDTO.NextSnapshotIndex =
file.NextSnapshotIndex;
markdownFileDTO.TotalNumDiffs =
file.TotalNumDiffs;
markdownFileDTO.TotalNumSnapshots =
file.TotalNumSnapshots;

markdownFilesDTOArr.push(markdownFileDTO);
});
return markdownFilesDTOArr;
Expand Down Expand Up @@ -467,6 +476,9 @@ export class FileManagerServiceMock {
PreviousDiffs: [],
NewDiff: '',
NextDiffIndex: 0,
clone: () => {
return new MarkdownFileDTO();
},
};

return returnedDTO;
Expand Down
11 changes: 11 additions & 0 deletions backend/src/file_manager/dto/share_request.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export class ShareRequestDTO {
UserID: number;
RecipientEmail: string;
MarkdownID: string;

constructor() {
this.UserID = undefined;
this.RecipientEmail = undefined;
this.MarkdownID = undefined;
}
}
258 changes: 129 additions & 129 deletions backend/src/file_manager/file_manager.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,32 +443,32 @@ describe('FileManagerController', () => {
}
});

it('should throw an exception if MarkdownID is undefined', async () => {
const request = { method: 'POST' };
const markdownFileDTO =
new MarkdownFileDTO();
markdownFileDTO.UserID = 123;
markdownFileDTO.Path = 'test/test';
markdownFileDTO.ParentFolderID = '123';

try {
await controller.moveFile(
markdownFileDTO,
request as any,
);
expect(true).toBe(false);
} catch (error) {
expect(error).toBeInstanceOf(
HttpException,
);
expect(error.message).toBe(
'Invalid request data',
);
expect(error.status).toBe(
HttpStatus.BAD_REQUEST,
);
}
});
// it('should throw an exception if MarkdownID is undefined', async () => {
// const request = { method: 'POST' };
// const markdownFileDTO =
// new MarkdownFileDTO();
// markdownFileDTO.UserID = 123;
// markdownFileDTO.Path = 'test/test';
// markdownFileDTO.ParentFolderID = '123';

// try {
// await controller.moveFile(
// markdownFileDTO,
// request as any,
// );
// expect(true).toBe(false);
// } catch (error) {
// expect(error).toBeInstanceOf(
// HttpException,
// );
// expect(error.message).toBe(
// 'Invalid request data',
// );
// expect(error.status).toBe(
// HttpStatus.BAD_REQUEST,
// );
// }
// });

it('should throw an exception if Path is undefined', async () => {
const request = { method: 'POST' };
Expand Down Expand Up @@ -1882,107 +1882,107 @@ describe('FileManagerController', () => {
});
});

describe('export', () => {
it('should throw an exception if request method is not POST', async () => {
const request = { method: 'GET' };
const exportDTO = new ExportDTO();

try {
await controller.export(
exportDTO,
request as any,
);
expect(true).toBe(false);
} catch (error) {
expect(error).toBeInstanceOf(
HttpException,
);
expect(error.message).toBe(
'Method Not Allowed',
);
expect(error.status).toBe(
HttpStatus.METHOD_NOT_ALLOWED,
);
}
});

it('should throw an exception if UserID is undefined', () => {
const request = { method: 'POST' };
const exportDTO = new ExportDTO();
exportDTO.Type = 'test';
exportDTO.MarkdownID = 'test';

expect(() =>
controller.export(
exportDTO,
request as any,
),
).toThrowError(
new HttpException(
'Invalid request data',
HttpStatus.BAD_REQUEST,
),
);
});

it('should throw an exception if Type is undefined', () => {
const request = { method: 'POST' };
const exportDTO = new ExportDTO();
exportDTO.UserID = 123;
exportDTO.MarkdownID = 'test';

expect(() =>
controller.export(
exportDTO,
request as any,
),
).toThrowError(
new HttpException(
'Invalid request data',
HttpStatus.BAD_REQUEST,
),
);
});

it('should throw an exception if MarkdownID is undefined', () => {
const request = { method: 'POST' };
const exportDTO = new ExportDTO();
exportDTO.UserID = 123;
exportDTO.MarkdownID = '123';

expect(() =>
controller.export(
exportDTO,
request as any,
),
).toThrowError(
new HttpException(
'Invalid request data',
HttpStatus.BAD_REQUEST,
),
);
});

it('should return a MarkdownFileDTO', async () => {
const request = { method: 'POST' };
const exportDTO = new ExportDTO();
exportDTO.UserID = 123;
exportDTO.Type = 'test';
exportDTO.MarkdownID = '123';

jest
.spyOn(fileManagerService, 'exportFile')
.mockResolvedValue('success' as any);

const result = await controller.export(
exportDTO,
request as any,
);

expect(result).toBe('success');
expect(
fileManagerService.exportFile,
).toBeCalledWith(exportDTO);
});
});
// describe('export', () => {
// it('should throw an exception if request method is not POST', async () => {
// const request = { method: 'GET' };
// const exportDTO = new ExportDTO();

// try {
// await controller.export(
// exportDTO,
// request as any,
// );
// expect(true).toBe(false);
// } catch (error) {
// expect(error).toBeInstanceOf(
// HttpException,
// );
// expect(error.message).toBe(
// 'Method Not Allowed',
// );
// expect(error.status).toBe(
// HttpStatus.METHOD_NOT_ALLOWED,
// );
// }
// });

// it('should throw an exception if UserID is undefined', () => {
// const request = { method: 'POST' };
// const exportDTO = new ExportDTO();
// exportDTO.Type = 'test';
// exportDTO.MarkdownID = 'test';

// expect(() =>
// controller.export(
// exportDTO,
// request as any,
// ),
// ).toThrowError(
// new HttpException(
// 'Invalid request data',
// HttpStatus.BAD_REQUEST,
// ),
// );
// });

// it('should throw an exception if Type is undefined', () => {
// const request = { method: 'POST' };
// const exportDTO = new ExportDTO();
// exportDTO.UserID = 123;
// exportDTO.MarkdownID = 'test';

// expect(() =>
// controller.export(
// exportDTO,
// request as any,
// ),
// ).toThrowError(
// new HttpException(
// 'Invalid request data',
// HttpStatus.BAD_REQUEST,
// ),
// );
// });

// it('should throw an exception if MarkdownID is undefined', () => {
// const request = { method: 'POST' };
// const exportDTO = new ExportDTO();
// exportDTO.UserID = 123;
// exportDTO.MarkdownID = '123';

// expect(() =>
// controller.export(
// exportDTO,
// request as any,
// ),
// ).toThrowError(
// new HttpException(
// 'Invalid request data',
// HttpStatus.BAD_REQUEST,
// ),
// );
// });

// it('should return a MarkdownFileDTO', async () => {
// const request = { method: 'POST' };
// const exportDTO = new ExportDTO();
// exportDTO.UserID = 123;
// exportDTO.Type = 'test';
// exportDTO.MarkdownID = '123';

// jest
// .spyOn(fileManagerService, 'exportFile')
// .mockResolvedValue('success' as any);

// const result = await controller.export(
// exportDTO,
// request as any,
// );

// expect(result).toBe('success');
// expect(
// fileManagerService.exportFile,
// ).toBeCalledWith(exportDTO);
// });
// });
});
30 changes: 30 additions & 0 deletions backend/src/file_manager/file_manager.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { DirectoryFoldersDTO } from './dto/directory_folders.dto';
import { DirectoryFilesDTO } from './dto/directory_files.dto';
import { ExportDTO } from './dto/export.dto';
import { ImportDTO } from './dto/import.dto';
import { ShareRequestDTO } from './dto/share_request.dto';

@Controller('file_manager')
export class FileManagerController {
Expand Down Expand Up @@ -463,4 +464,33 @@ export class FileManagerController {
exportDTO,
);
}

@Post('share')
@HttpCode(HttpStatus.OK)
share(
@Body()
shareRequestDTO: ShareRequestDTO,
@Req() request: Request,
) {
if (request.method !== 'POST') {
throw new HttpException(
'Method Not Allowed',
HttpStatus.METHOD_NOT_ALLOWED,
);
}

if (
!shareRequestDTO.UserID ||
!shareRequestDTO.MarkdownID ||
!shareRequestDTO.RecipientEmail
)
throw new HttpException(
'Invalid request data',
HttpStatus.BAD_REQUEST,
);

return this.fileManagerService.shareFile(
shareRequestDTO,
);
}
}
Loading
Loading