Commit graph

742 commits

Author SHA1 Message Date
David Mehren
3b0bbe8b00
MediaService: Handle unexpected backend type
Signed-off-by: David Mehren <git@herrmehren.de>
2021-04-29 16:59:18 +02:00
David Mehren
22702b3390
Correctly type nullable columns
TypeORM columns with `nullable: true` can be `null` at runtime.
This commit ensures that the types of the corresponding properties reflect that.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-04-29 16:54:57 +02:00
David Mehren
d63f581a42
MediaController: Double-check that req.user is defined
TokenAuthGuard ensures that req.user is always
defined, but thanks to strict mode we have to check again.

In the future, we may add a custom Request type and
a custom param decorator to centralize the check.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-04-29 16:44:27 +02:00
David Mehren
90038cf116
MeController: Double-check that req.user is defined
TokenAuthGuard ensures that req.user is always
defined, but thanks to strict mode we have to check again.

In the future, we may add a custom Request type and
a custom param decorator to centralize the check.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-04-29 16:43:16 +02:00
David Mehren
87eb099d34
UsersService: Remove null from toUserDto return type
toUserDto won't return null, as TS's strict mode
prevents user from being nullish

Signed-off-by: David Mehren <git@herrmehren.de>
2021-04-29 16:40:13 +02:00
David Mehren
a453344205
MarkdownBody: Handle error in getOwnPropertyDescriptor
Signed-off-by: David Mehren <git@herrmehren.de>
2021-04-29 16:27:15 +02:00
David Mehren
4959be739a
Handle config initialisation error on app bootstrap
Signed-off-by: David Mehren <git@herrmehren.de>
2021-04-29 16:22:01 +02:00
David Mehren
8357f3072c
HistoryService: Throw NotInDBError on empty DB result
This adds error handling to getEntryByNote, so it throws a
NotInDBError instead of (illegally, according to the type) returning
null.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-04-29 16:16:30 +02:00
David Mehren
1a72e3c727
FrontendConfig DTOs: Make properties consistently optional
Some properties already have a IsOptional decorator,
this makes the properties themselves also optional

Signed-off-by: David Mehren <git@herrmehren.de>
2021-04-29 16:13:54 +02:00
David Mehren
56ce66bc8b
ConsoleLoggerService: Fix type of context properties
Nullish values of functionContext and classContext are handled correctly,
so the type can be adjusted

Signed-off-by: David Mehren <git@herrmehren.de>
2021-04-29 16:10:46 +02:00
David Mehren
52bb44a561
AuthService: Fix type of toAuthTokenWithSecretDto
toAuthTokenDto does not return nor accept a nullish value anymore,
so the types can be adjusted.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-04-29 16:07:58 +02:00
David Mehren
327f36af94
AuthService.randomString: Throw Error instead of returning null
A string with a negative length is invalid, so we should throw here
instead of complicating the type with a possible null return value.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-04-29 16:06:59 +02:00
David Mehren
5ee9b2a7e8
AuthTokenDto: Make properties consistently optional
validUntil and lastUsed already have a IsOptional decorator,
this makes the properties themselves also optional

Signed-off-by: David Mehren <git@herrmehren.de>
2021-04-29 15:55:11 +02:00
David Mehren
ef8b8d985e
AuthService: Throw NotInDBError on empty DB result
This adds error handling to various functions, so they throw a
NotInDBError instead of a TypeError

Signed-off-by: David Mehren <git@herrmehren.de>
2021-05-09 18:27:03 +02:00
David Mehren
52f6310e91
Safely parse numbers from environment vars
This adds the function parseOptionalInt to help parse numbers
from environment variables

Signed-off-by: David Mehren <git@herrmehren.de>
2021-04-29 15:34:59 +02:00
David Mehren
36e721d4a9
Config Utils: Fix type of toArrayConfig
configValue is checked for a nullish value,
the type should reflect that.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-04-29 15:26:15 +02:00
David Mehren
dcc09747d2
AuthService: Remove null from toAuthTokenDto return type
toAuthTokenDto won't return null, as TS's strict mode
prevents authToken from being nullish

Signed-off-by: David Mehren <git@herrmehren.de>
2021-04-29 15:07:50 +02:00
David Mehren
d87980ae6d
RevisionsService: Throw NotInDBError on empty DB result
This adds error handling to various getters, so they throw a
NotInDBError instead of (illegally, according to the type) returning
null.

Signed-off-by: David Mehren <git@herrmehren.de>
2021-04-29 15:03:44 +02:00
David Mehren
6604a6e499
Enable TypeScript strict mode
This enables strict mode, but sets strictPropertyInitialization to false,
as "the class-validator DTO pattern described in the documentation is
not compatible with strict property initialization" according to
https://github.com/nestjs/typescript-starter/pull/192

Signed-off-by: David Mehren <git@herrmehren.de>
2021-04-29 15:01:00 +02:00
Renovate Bot
b2f0bfa0bf
Update dependency eslint to v7.26.0
Signed-off-by: Renovate Bot <bot@renovateapp.com>
2021-05-09 12:41:30 +00:00
Renovate Bot
618ab0dc9b
Update dependency ts-loader to v9.1.2
Signed-off-by: Renovate Bot <bot@renovateapp.com>
2021-05-09 12:41:15 +00:00
Renovate Bot
0e698f6aad
Update dependency pymdown-extensions to v8.2
Signed-off-by: Renovate Bot <bot@renovateapp.com>
2021-05-08 19:43:43 +00:00
Renovate Bot
ad8a6d0ebc
Update dependency mkdocs-material to v7.1.4
Signed-off-by: Renovate Bot <bot@renovateapp.com>
2021-05-07 09:51:32 +00:00
Renovate Bot
8c0554d40e
Update linters to v4.22.1
Signed-off-by: Renovate Bot <bot@renovateapp.com>
2021-05-05 20:27:14 +00:00
Renovate Bot
a6d7fc2c30
Update dependency file-type to v16.4.0
Signed-off-by: Renovate Bot <bot@renovateapp.com>
2021-05-05 20:26:59 +00:00
Renovate Bot
d0f787e3c2
Update dependency ts-jest to v26.5.6
Signed-off-by: Renovate Bot <bot@renovateapp.com>
2021-05-05 16:10:56 +00:00
Renovate Bot
c2645472f0
Lock file maintenance
Signed-off-by: Renovate Bot <bot@renovateapp.com>
2021-05-03 01:12:21 +00:00
Philip Molares
8186c96806
PrivateHistoryE2E: Extend POST /me/history
Test the correct behaviour in error cases

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-04-12 10:55:16 +02:00
Philip Molares
258a38f8c0
ControllerTests: Add connection to controller tests
Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-04-11 22:06:41 +02:00
Philip Molares
0933b88ff5
ESLint: Add extra rules for tests
Add afterEach and beforeAll as additional additionalTestBlockFunctions for jest/no-standalone-expect. This is necessary, because we use expects in those functions for the history service unit tests.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-04-18 14:02:55 +02:00
Philip Molares
ea7b0cb9c4
HistoryService: Add test for setHistory
Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-04-11 22:06:36 +02:00
Philip Molares
524ad658d8
HistoryService: Add setHistory method
This is the transactional reimplementation of the business logic of the history controllers setHistory method (of the private api). This should prevent the problem that the history gets deleted, but a later error in the handling of the list of HistoryEntryImportDto let's the call fail.

See also: https://docs.nestjs.com/techniques/database#transactions

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-04-11 21:54:50 +02:00
Philip Molares
7c648e7056
HistoryService: Remove extra parameters from createOrUpdateHistoryEntry
As the function is now only called with a user and a note and the previous extra parameters are now added into the transactional setHistory method, this is no longer necessary.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-04-11 21:28:53 +02:00
Philip Molares
6b6aef284c
NotesService: Extract checkNoteIdOrAlias into own method
To reuse this functionality in the history services setHistory method, it was extracted into its own exported function.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-04-11 21:25:41 +02:00
Philip Molares
7e20bb0fef
[Project] Add seed script
This script invokes src/seed.ts to create a sqlite DB. The DB already contains some objects to manual test with. This ensures that devs easily can spin up a test instance of HedgeDoc and don't need to fumble around with the DB file.

See https://github.com/typeorm/typeorm#creating-a-connection-to-the-database

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-04-29 11:53:59 +02:00
Philip Molares
162f736647
PrivateApi: Add CORS-Header for rendererOrigin
Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-04-02 17:36:51 +02:00
Philip Molares
bf13668548
PrivateApi: Serve under /api/private
Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-04-02 17:33:42 +02:00
Philip Molares
1edc0d87c5
FrontendConfig: Fix unit test
Emulate the behaviour of the new app config: If renderOrigin is undefined instead use domain.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-04-27 23:33:13 +02:00
Philip Molares
662d428e3c
AppConfig: Move default for rendererOrigin to config file
As we only use rendererOrigin in the frontend config service, where domain will be used if it is not defined, it makes more sense to move this default behavior to the app config directly. That makes it easier to understand what this variable contains and that it defaults to domain.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-04-25 15:20:51 +02:00
Renovate Bot
116aa5e022
Pin dependency @tsconfig/node12 to 1.0.7
Signed-off-by: Renovate Bot <bot@renovateapp.com>
2021-04-30 18:53:44 +00:00
Renovate Bot
34ae957dee
Update dependency rxjs to v7
Signed-off-by: Renovate Bot <bot@renovateapp.com>
2021-04-30 18:53:59 +00:00
David Mehren
6ee2ddead5
Use node12 TypeScript base config
TypeScript recommends using a base config from https://github.com/tsconfig/bases.

Using this config reduces compile times by ~30%
and the size of the dist folder by ~45%.
It also enables the recommended `esModuleInterop` option,
which necessitated some changes to imports.
See also https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html#support-for-import-d-from-cjs-from-commonjs-modules-with---esmoduleinterop

Signed-off-by: David Mehren <git@herrmehren.de>
2021-04-29 22:47:18 +02:00
Renovate Bot
c32c601d36
Lock file maintenance
Signed-off-by: Renovate Bot <bot@renovateapp.com>
2021-04-29 14:49:27 +00:00
Renovate Bot
448225e124
Update dependency eslint-plugin-jest to v24.3.6
Signed-off-by: Renovate Bot <bot@renovateapp.com>
2021-04-27 20:32:19 +00:00
Renovate Bot
77d03dd4aa
Update definitelyTyped
Signed-off-by: Renovate Bot <bot@renovateapp.com>
2021-04-27 14:46:56 +00:00
Philip Molares
33dce8f607
README: Replace HedgeDoc header with logo
We have such a lovely logo we should use it on our user-facing README.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-04-25 23:03:33 +02:00
Tilman Vatteroth
58075f787e
Remove banner from frontend config
NestJS adds the headers "Last Modified" and "ETag" to asset serving responses.
Therefore all the information we need for the banner are already given by the
file content or the file meta data.

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
2021-04-25 14:45:04 +02:00
Tilman Vatteroth
ff06f368de
Add serving of static assets under the relative URL '/public'
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
2021-04-25 14:41:38 +02:00
Renovate Bot
fc3d98d23a
Update dependency mkdocs-material to v7.1.3
Signed-off-by: Renovate Bot <bot@renovateapp.com>
2021-04-25 19:19:36 +00:00
Philip Molares
1f56ba95f4
Gitignore: Add .env
Because the new config is done via the file `.env`, it should not be possible to include it in the git repository.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
2021-04-25 12:00:13 +02:00