From 87be26c57eda752b462aa7938258992311c92fc1 Mon Sep 17 00:00:00 2001 From: Dexter Chua Date: Thu, 18 Jun 2020 08:48:55 +0800 Subject: [PATCH] Fix default permission The code intends to check if the note is anonymous by checking if it has an owner. If it is anonymous, the default permission must be `freely`. However, at this point in the code, `owner` is never populated; only `ownerId` is. The property `owner` is automatically filled in *after* the Note is created, but this call happens before that. Thus, the default note permission is always `freely`, regardless of the `defaultPermission` setting. By checking `ownerId` instead of `owner`, the anonymity and hence default permission is correctly determined, This is especially an issue when `allowAnonymous` is `false`, since this would allow the user to create a note with `freely` permission when it should not be allowed. Signed-off-by: Dexter Chua --- src/lib/models/note.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/models/note.ts b/src/lib/models/note.ts index c186ce108..80ee43fae 100644 --- a/src/lib/models/note.ts +++ b/src/lib/models/note.ts @@ -170,7 +170,7 @@ export class Note extends Model { } // if no permission specified and have owner then give default permission in config, else default permission is freely if (!note.permission) { - if (note.owner) { + if (note.ownerId) { // TODO: Might explode if the user-defined permission does not exist note.permission = PermissionEnum[config.defaultPermission] } else {