Commit graph

489 commits

Author SHA1 Message Date
Philip Molares
a2e89c7c97 feat: add local auth dtos
Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-09-16 23:59:59 +02:00
Philip Molares
5985c4e67d chore: add user relation enum
this enum is used to specify which relation of the user object should be populated.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-09-16 23:59:59 +02:00
Philip Molares
e37caf1e6a feat: lazy load identities of user object
This makes it possible that we can get identities from any user object even if we didn't specify that while getting them from the orm

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-09-16 23:59:59 +02:00
Philip Molares
b2da8a2b95 chore: move identity entity in its own folder
Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-09-16 23:59:59 +02:00
Philip Molares
87a5f77abe chore: move password related functions from AuthService to utils file
As these methods will be used in both the AuthService and the IdentityService, it makes sense to extract them and use them in this manner. Especially if one considers that they are quite standalone functions.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-09-16 23:59:59 +02:00
Philip Molares
4938d308b0 feat: add ProviderType enum
This is used to give identities a type and to easily get the identity any auth method would need.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-09-16 23:59:59 +02:00
Abhilasha Sinha
9d6aa10923 Add new API to purge note history #1064
Signed-off-by: Abhilasha Sinha <abhisinha662000@gmail.com>

Combine the describe block

Signed-off-by: Abhilasha Sinha <abhisinha662000@gmail.com>

Fix naming

Signed-off-by: Abhilasha Sinha <abhisinha662000@gmail.com>

Rename purgeRevision to purgeRevisions

Signed-off-by: Abhilasha Sinha <abhisinha662000@gmail.com>

Fix notes e2e test description

Signed-off-by: Abhilasha Sinha <abhisinha662000@gmail.com>

Add yarn.lock

Fix lint and format

Signed-off-by: Abhilasha Sinha <abhisinha662000@gmail.com>
2021-09-07 21:23:26 +05:30
David Mehren
7c618e7f9f
Merge pull request #1613 from hedgedoc/merge/tokenGuardAndStrategy 2021-09-06 12:12:44 +02:00
David Mehren
0dc472bba8
RevisionsService: Refactor getFirst/LastRevision
The functions now expect a `Note` object instead of a noteId to
make it more consistent with other functions.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-09-04 22:40:15 +02:00
David Mehren
5c7a787d7e
MediaService: Refactor saveFile
The function now expects a `Note` object instead of a noteId
and a `User` instead of a username to
make it more consistent with other functions.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-09-04 22:40:15 +02:00
David Mehren
279d90dad1
HistoryService: Remove getEntryByNoteIdOrAlias
As we now have a GetNotePipe, we can easily get rid of this function.
All clients can directly provide a `Note` instance
and use `getEntryByNote`.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-09-04 22:40:15 +02:00
David Mehren
b552fc10b6
HistoryService: Refactor deleteHistoryEntry
The function now expects a `Note` object instead of a noteId to
make it more consistent with other functions.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-09-04 22:40:15 +02:00
David Mehren
c515569299
HistoryService: Refactor updateHistoryEntry
The function now expects a `Note` object instead of a noteId to
make it more consistent with `updateHistoryEntryTimestamp`.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-09-04 22:40:15 +02:00
David Mehren
99db4bc336
UserService: Improve method naming
This renames `createOrUpdateHistoryEntry` to `updateHistoryEntryTimestamp`,
which reduces confusion with the similarly named
`updateHistoryEntry` function.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-09-04 22:40:15 +02:00
David Mehren
ea2dfafbd0
Private API: Use GetNotePipe
This replaces repeated calls to `noteService.getNoteByIdOrAlias`
and associated error handling with the `GetNotePipe`
in the `Param` decorator.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-09-04 21:42:54 +02:00
David Mehren
adc9ca6939
Public API: Remove superfluous try/catch
`getNoteMetadata` does not use a method that
can throw a `PermissionsUpdateInconsistentError`.
The try/catch-block seems to be a copy-paste error.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-09-04 21:42:54 +02:00
David Mehren
9da8d0efb0
Public API: Use GetNotePipe
This replaces repeated calls to `noteService.getNoteByIdOrAlias`
and associated error handling with the `GetNotePipe`
in the `Param` decorator.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-09-04 21:42:54 +02:00
David Mehren
1e3c08b3df
Implement GetNotePipe
This pipe transforms a note ID or alias to a Note object
by loading it from the database.
It also performs error handling

Signed-off-by: David Mehren <git@herrmehren.de>
2021-09-04 21:42:54 +02:00
David Mehren
83c36ee3f9
Merge pull request #1588 from hedgedoc/enhancement/requestuser_decorator
Introduce RequestUser decorator
2021-09-04 18:40:03 +02:00
Philip Molares
c22727dad7 refactor: move TokenAuthGuard in the same file as TokenStrategy
This should help to make clear why code is executed when the TokenAuthGuard is encountered by a request. Currently, one has to connect both files via the string 'token', which is a bit cryptic

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-09-04 18:09:17 +02:00
David Mehren
ba2e4b0e3a
Public API: Introduce RequestUser decorator
This introduces the `RequestUser` decorator
to extract the `User` from a request.

It reduces code duplication across the public API
and allows us to drop the override of the `Request` type from express.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-09-04 17:05:38 +02:00
Yannick Bungers
9c7ab01016 Fix copy paste error in auth toAuthTokenDto test
Add an hour difference between createdAt and validUntil to better detect
these errors.

Signed-off-by: Yannick Bungers <git@innay.de>
2021-09-03 19:19:55 +02:00
David Mehren
3658204acb
Cleanup some imports
Signed-off-by: David Mehren <git@herrmehren.de>
2021-08-29 18:57:00 +02:00
David Mehren
bcc9ec9c75
Enforce import order with prettier
Signed-off-by: David Mehren <git@herrmehren.de>
2021-08-29 18:45:46 +02:00
David Mehren
2dc8fc2b66
Merge pull request #1389 from hedgedoc/fix/publicId 2021-07-15 20:37:01 +02:00
David Mehren
ab231e0f6e
Switch to new buffered logger
NestJS 8 allows the logs to buffer on startup, so that all logs run
through our custom logger.

See also https://docs.nestjs.com/techniques/logger#dependency-injection

Signed-off-by: David Mehren <git@herrmehren.de>
2021-07-15 20:21:42 +02:00
Philip Molares
eea0e410d3 test(generatePublicId): test if with a given random buffer a correct encoding is generated
Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-06-17 21:45:28 +02:00
Philip Molares
b636afc4bd fix(publicId): generate 128-bit instead of 128-byte value
Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-06-17 21:45:28 +02:00
David Mehren
57d1fc12bf
EditDto: Clarify that the username can be null
If the edit was made by a anonymous user, we don't have a username.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-05-31 22:16:06 +02:00
David Mehren
09329ae360
Rename NoteAuthorshipDto to EditDto
After Authorship was renamed to Edit, the DTO should follow.
The file is also moved to the revisions folder, where the entity
already is.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-05-31 22:02:32 +02:00
David Mehren
62e0530d2b
Rename Authorship entity to Edit
As we now have a separate Author entity, which holds information
about an author (the color), the Authorship name became confusing.
Edit seems to be a better name, as the entity saves information
about a change in a note.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-05-31 21:46:41 +02:00
David Mehren
4d0205a61f
NotesService: Implement getAuthorUsers
This reimplements logic to get all Users that ever edited a note
and fixes the empty `editedBy` property of `toNoteMetadataDto`
introduced in 81cc092e.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-05-31 21:14:06 +02:00
David Mehren
5f9f134eb0
Seed: Generate multiple notes and authorships
Signed-off-by: David Mehren <git@herrmehren.de>
2021-05-31 18:44:00 +02:00
David Mehren
b2b3849300
Adjust tests to new Session and Author entities
Signed-off-by: David Mehren <git@herrmehren.de>
2021-05-31 18:44:00 +02:00
David Mehren
20006df82f
AuthorshipEntity: Adjust to DB schema
This commit replaces the user property with a author property,
in accordance with the DB schema updated in 0d6c3002.

It also adjusts the NoteService accordingly.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-05-31 18:42:57 +02:00
David Mehren
27c2bfb36f
Add Author property to Session & User
The DB schema was updated in 0d6c3002,
this adds the new author property to
the Session and User entities.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-05-31 18:39:33 +02:00
David Mehren
62e442343a
AuthorEntity: Add create method
Signed-off-by: David Mehren <git@herrmehren.de>
2021-05-31 18:19:31 +02:00
David Mehren
228c2941e5
AuthorEntity: Add missing properties
This adds the missing properties according to the DB PlantUML schema

Signed-off-by: David Mehren <git@herrmehren.de>
2021-05-31 18:19:31 +02:00
David Mehren
b850d03b5f
UsersModule: Add Session to TypeORM module
This seems to have been missed in
db026d6a57, where the Session entity
was added.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-05-31 18:19:31 +02:00
David Mehren
81cc092e51
Remove AuthorColor entity
It will be replaced with the Author entity,
that will save the color

Signed-off-by: David Mehren <git@herrmehren.de>
2021-05-31 17:38:58 +02:00
David Mehren
a2e8c3d031
Move publicID creation to Note.create
Before this commit, `Note.create()` did not return a complete object,
as the `publicId` property was missing.
This adds the generation of the property to the `create` method and
moves the actual generation code from the `NotesService`
to a utility method.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-05-19 22:19:04 +02:00
Philip Molares
fb79f44b1f chore(test): Change test to work with publicId
Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-05-17 20:27:44 +02:00
Philip Molares
430e75ef44 feat(notes): Use publicId in notes service
Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-05-17 20:27:43 +02:00
Philip Molares
072c2b6a59 feat(note): Add publicId field
This field is a randomly generated 128-bit value encoded with base32-encode using the crockford variant and converted to lowercase.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-05-17 20:27:43 +02:00
Philip Molares
840ca2fa6c refactor: Remove randomString function
This was done because it was only a wrapper for a nodejs function to check if the given parameter is a positive number.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-05-17 20:27:40 +02:00
Thomas Snowden
95df1525a9
Add API decorator to reduce clutter
Signed-off-by: Thomas Snowden <zapperchamp1@gmail.com>
2021-05-16 22:09:28 +02:00
David Mehren
e4317725cd
Format with Prettier 2.3
Signed-off-by: David Mehren <git@herrmehren.de>
2021-05-15 21:13:44 +02:00
Philip Molares
8c562016ab Refactor(note): Remove shortid from note
This is a 1.x relict and isn't used anymore in 2.x. All 1.x shortids will be converted to aliases on migration of 1.x to 2.x.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-05-11 22:49:44 +02:00
David Mehren
ac01521d82
Merge pull request #1212 from hedgedoc/eslint/customLoggerRule 2021-05-09 22:22:05 +02:00
Philip Molares
b07c3be398 Linting: Fixed wrong logger contexts
Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-05-09 22:18:41 +02:00