Commit graph

194 commits

Author SHA1 Message Date
David Mehren
80e4d029f7
DB Schema: Make layout pretty
Signed-off-by: David Mehren <git@herrmehren.de>
Co-authored-by: Yannick Bungers <git@innay.de>
2020-10-24 20:55:31 +02:00
David Mehren
520046f8d4
Remove NoteUtils class, as the planned parsing logic is not needed anymore
Signed-off-by: David Mehren <git@herrmehren.de>
Co-authored-by: Yannick Bungers <git@innay.de>
2020-10-03 17:36:01 +02:00
David Mehren
a04d5b29f9
Add missing TagRepository provider in unit tests
Signed-off-by: David Mehren <git@herrmehren.de>
Co-authored-by: Yannick Bungers <git@innay.de>
2020-10-03 17:24:42 +02:00
David Mehren
9152f05c61
Add E2E tests for note metadata routes
Signed-off-by: David Mehren <git@herrmehren.de>
Co-authored-by: Yannick Bungers <git@innay.de>
2020-10-03 16:45:04 +02:00
David Mehren
67cd8cb0f6
NotesController: Add PUT :noteIdOrAlias/metadata route
Signed-off-by: David Mehren <git@herrmehren.de>
Co-authored-by: Yannick Bungers <git@innay.de>
2020-10-03 15:53:30 +02:00
David Mehren
08fd070bcb
NotesService: Implement updateNoteMetadata
Signed-off-by: David Mehren <git@herrmehren.de>
Co-authored-by: Yannick Bungers <git@innay.de>
2020-10-03 15:52:49 +02:00
David Mehren
6541cfda4e
NoteEntity: Enable eager loading and cascades for tags
Signed-off-by: David Mehren <git@herrmehren.de>
Co-authored-by: Yannick Bungers <git@innay.de>
2020-10-03 15:37:57 +02:00
David Mehren
99ab9f04c2
NotesService: Get metadata from database
Signed-off-by: David Mehren <git@herrmehren.de>
Co-authored-by: Yannick Bungers <git@innay.de>
2020-10-03 11:27:15 +02:00
David Mehren
7d5dddaaaf
Add note metadata properties and Tag entity.
These were planned to be parsed at runtime from the note-content in the database, but having to run a markdown parser in the backend was found to be a bad idea. Now the frontend (that already implements the parsing logic) has to set title, description and tags.

Signed-off-by: David Mehren <git@herrmehren.de>
Co-authored-by: Yannick Bungers <git@innay.de>
2020-10-03 11:17:07 +02:00
David Mehren
990742e569
Note.alias should be optional in db schema
Signed-off-by: David Mehren <git@herrmehren.de>
Co-authored-by: Yannick Bungers <git@innay.de>
2020-10-03 11:14:41 +02:00
David Mehren
566e95f95d
Add note metadata to db schema
Signed-off-by: David Mehren <git@herrmehren.de>
Co-authored-by: Yannick Bungers <git@innay.de>
2020-10-03 11:02:03 +02:00
David Mehren
e30b16d91d
Public API: Cleanup history schemas
Signed-off-by: David Mehren <git@herrmehren.de>
Co-authored-by: Yannick Bungers <git@innay.de>
2020-10-24 19:39:34 +02:00
David Mehren
d43bca69b8
Public API: NoteRevisionsMetadata is not an array
Signed-off-by: David Mehren <git@herrmehren.de>
Co-authored-by: Yannick Bungers <git@innay.de>
2020-10-24 19:39:05 +02:00
David Mehren
2302667787
Public API: Remove PUT /notes/{note}/metadata
The note metadata will be automatically extracted from the note content and cannot be updated separately.

Signed-off-by: David Mehren <git@herrmehren.de>
Co-authored-by: Yannick Bungers <git@innay.de>
2020-10-24 19:25:15 +02:00
David Mehren
c685bd8e50
Public API: Fix PUT /notes/{note}/permissions response
This route should return a full `NotePermissions` object instead of only `NotePermissionsUpdate`

Signed-off-by: David Mehren <git@herrmehren.de>
Co-authored-by: Yannick Bungers <git@innay.de>
2020-10-03 18:08:31 +02:00
David Mehren
cae430f25f
Public API: Update description of /notes/{note} POST and PUT routes.
Signed-off-by: David Mehren <git@herrmehren.de>
Co-authored-by: Yannick Bungers <git@innay.de>
2020-10-03 14:51:22 +02:00
David Mehren
ad676ce6ff
NoteMetadataDto: Rename permission to permissions
Signed-off-by: David Mehren <git@herrmehren.de>
Co-authored-by: Yannick Bungers <git@innay.de>
2020-10-03 14:45:04 +02:00
David Mehren
fe5f9bc9c3
Public API: Successful POST requests should result in a 201.
Signed-off-by: David Mehren <git@herrmehren.de>
Co-authored-by: Yannick Bungers <git@innay.de>
2020-10-03 14:40:51 +02:00
David Mehren
ee0d85bc85
Public API: Simplify PUT /me/history/{note}
Previously, one had to send a complete `NoteMetadata` object when updating the pinned status of a note. A new `HistoryUpdateObject` type was introduced, that only contains the pinned status boolean.

Signed-off-by: David Mehren <git@herrmehren.de>
Co-authored-by: Yannick Bungers <git@innay.de>
2020-10-03 12:49:50 +02:00
David Mehren
2c9ccad8e5
Public API: Split-out a /notes/{note}/permissions route to set only permissions
Previously, the metadata route was used to both update note metadata (like title, description and tags) and the permissions. Additionally, one had to send many unchangeable properties. In this commit, a /notes/{note}/permissions route is introduced, that only changes permissions. Additionally, PUT /notes/{note}/metadata now needs only the properties that are actually changeable.

Signed-off-by: David Mehren <git@herrmehren.de>
Co-authored-by: Yannick Bungers <git@innay.de>
2020-10-03 12:46:28 +02:00
David Mehren
713e2ada31
Update NotePermissionsUpdate DTOs to be aware of groups
The NotePermissionsUpdateDto was not updated when group permissions were introduced.

Signed-off-by: David Mehren <git@herrmehren.de>
Co-authored-by: Yannick Bungers <git@innay.de>
2020-10-03 12:42:14 +02:00
David Mehren
2980f3a244
Update dependencies
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-24 23:02:05 +02:00
David Mehren
7563eb703d
Public API: Add routes to get uploads by user or note
Co-authored-by: Yannick Bungers <git@innay.de>
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-24 21:48:29 +02:00
David Mehren
4f60a79e4b
Use unique sqlite file for every E2E test
Previously, this lead to locking errors, when multiple test runners accessed the same database and tried to clear it or tried to insert new test data.

Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-24 12:30:23 +02:00
David Mehren
ff0651e659
FilesystemBackend: Ensure uploads directory exists
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-24 12:28:52 +02:00
David Mehren
fff46f0255
Add E2E tests for the /media route
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-24 11:50:45 +02:00
David Mehren
ac2646a74a
AppModule: Remove unused imports
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-24 11:49:19 +02:00
David Mehren
2b23dcc5a9
MediaService: Simplify saveFile signature
As the `saveFile` method only really uses the files `Buffer`, this commit changes the signature so it directly gets a `Buffer` instead of a complicated `MulterFile` object. This also simplifies testing.

Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-24 11:49:01 +02:00
David Mehren
53fbe82b6a
UserEntity: Fix column types for create/update dates
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-24 11:34:49 +02:00
David Mehren
558addf83e
UsersService: Improve logging in getNoteByIdOrAlias
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-24 11:34:16 +02:00
David Mehren
15db6a9b2a
Use useStaticAssets instead of @nestjs/serve-static
`serve-static` does not work with `createTestingModule` and is not recommended when "just" serving a few images.

See https://github.com/nestjs/serve-static/issues/240

Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-24 11:32:23 +02:00
David Mehren
bd1a6e528e
Public API: Add media deletion
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 21:55:05 +02:00
David Mehren
490e4cac69
MediaController: Add DELETE /{filename} route
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 21:54:44 +02:00
David Mehren
eeb3f6f5a7
MediaService: Implement delete feature
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 21:54:08 +02:00
David Mehren
5262a58639
FilesystemBackend: ESLint fixes
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 21:53:34 +02:00
David Mehren
16dfbdd42d
UsersService: Wait for the DB to find a user
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 21:52:59 +02:00
David Mehren
f4c73a8f96
Use POST /media for file upload
The old `/media/upload` subpath does not follow the convention of REST APIs.

Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 20:58:10 +02:00
David Mehren
eb77642604
Public API: Update /media/upload route with supported content-types
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 20:55:40 +02:00
David Mehren
c2c51f1eef
MediaService: Only allow upload of common image formats and PDFs
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 20:50:20 +02:00
David Mehren
d41b68b41a
Add various missing imports and provider ovverides in unit tests
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 20:21:22 +02:00
David Mehren
5a07abfd43
MediaController: Handle errors when trying to save file
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 18:51:29 +02:00
David Mehren
0cc9c6b347
MediaService: Improve error handling and logging
Add debug logging to `saveFile` method and throw the proper errors when problems with the mime type are encountered

Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 18:50:53 +02:00
David Mehren
219a3bcb5f
UsersService: Add methods to find, create and delete users
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-12 21:46:53 +02:00
David Mehren
1f22f47327
NotesService: Throw NotInDBError when the note wasn't found
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 18:47:10 +02:00
David Mehren
273d9b2d19
MediaController: Get parent note from HedgeDoc-Note header
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 16:44:00 +02:00
David Mehren
a877f57875
FilesystemBackend: Implement deleteFile and getFileURL.
We use `fs.unlink` instead of `fs.rm`, as the latter is only available in the fsPromises API since Node 14.14

Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-17 16:24:30 +02:00
David Mehren
9b3345fa13
Use serve-static to serve uploaded files.
Add `@nestjs/serve-static` to serve uploaded media from the upload directory on the local filesystem.

Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-16 22:38:31 +02:00
David Mehren
e2b5acaf84
MediaController: Use MediaService to store media
Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-16 22:37:20 +02:00
David Mehren
c0cbcc863a
Add MediaService
This service is responsible for operations regarding uploaded media. It should perform save, get and delete operations with the configured backend.
The service also checks, if the mime type of the uploaded media is allowed.

Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-16 22:35:53 +02:00
David Mehren
23ba2026cc
Do not save file extension as a separate field.
It turned out that saving the file extension in a separate field is not necessary. Instead, the extension is saved in the complete filename in the `id` field.

Signed-off-by: David Mehren <git@herrmehren.de>
2020-10-16 22:32:58 +02:00