diff --git a/backend/src/permissions/permissions.service.spec.ts b/backend/src/permissions/permissions.service.spec.ts index e83c8ba30..9b1a4b133 100644 --- a/backend/src/permissions/permissions.service.spec.ts +++ b/backend/src/permissions/permissions.service.spec.ts @@ -1015,6 +1015,13 @@ describe('PermissionsService', () => { expect(eventEmitterEmitSpy).toHaveBeenCalled(); }); describe('works', () => { + it('with user not added if owner', async () => { + const user = User.create('test', 'Testy') as User; + const note = Note.create(user) as Note; + const resultNote = await service.setUserPermission(note, user, true); + expect(await resultNote.userPermissions).toHaveLength(0); + }); + it('with user not added before and editable', async () => { const note = Note.create(null) as Note; const user = User.create('test', 'Testy') as User; diff --git a/backend/src/permissions/permissions.service.ts b/backend/src/permissions/permissions.service.ts index 9292dcc7d..9e99358ea 100644 --- a/backend/src/permissions/permissions.service.ts +++ b/backend/src/permissions/permissions.service.ts @@ -235,6 +235,9 @@ export class PermissionsService { permissionUser: User, canEdit: boolean, ): Promise { + if (await this.isOwner(permissionUser, note)) { + return note; + } const permissions = await note.userPermissions; const permission = await this.findPermissionForUser( permissions,