fix: don't create user permissions for owner

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2023-05-04 17:50:21 +02:00
parent 825b3b72ff
commit e02221acd2
2 changed files with 10 additions and 0 deletions

View file

@ -1015,6 +1015,13 @@ describe('PermissionsService', () => {
expect(eventEmitterEmitSpy).toHaveBeenCalled(); expect(eventEmitterEmitSpy).toHaveBeenCalled();
}); });
describe('works', () => { 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 () => { it('with user not added before and editable', async () => {
const note = Note.create(null) as Note; const note = Note.create(null) as Note;
const user = User.create('test', 'Testy') as User; const user = User.create('test', 'Testy') as User;

View file

@ -235,6 +235,9 @@ export class PermissionsService {
permissionUser: User, permissionUser: User,
canEdit: boolean, canEdit: boolean,
): Promise<Note> { ): Promise<Note> {
if (await this.isOwner(permissionUser, note)) {
return note;
}
const permissions = await note.userPermissions; const permissions = await note.userPermissions;
const permission = await this.findPermissionForUser( const permission = await this.findPermissionForUser(
permissions, permissions,