Merge pull request #1039 from hedgedoc/fix/permissionsCreationAndFinding

This commit is contained in:
Yannick Bungers 2021-04-18 22:45:24 +02:00 committed by GitHub
commit eaa5254418
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 5 deletions

View file

@ -39,9 +39,14 @@ export class Note {
@OneToMany(
(_) => NoteGroupPermission,
(groupPermission) => groupPermission.note,
{ cascade: true }, // This ensures that embedded NoteGroupPermissions are automatically saved to the database
)
groupPermissions: NoteGroupPermission[];
@OneToMany((_) => NoteUserPermission, (userPermission) => userPermission.note)
@OneToMany(
(_) => NoteUserPermission,
(userPermission) => userPermission.note,
{ cascade: true }, // This ensures that embedded NoteUserPermission are automatically saved to the database
)
userPermissions: NoteUserPermission[];
@Column({
nullable: false,

View file

@ -183,7 +183,9 @@ export class NotesService {
'authorColors',
'owner',
'groupPermissions',
'groupPermissions.group',
'userPermissions',
'userPermissions.user',
'tags',
],
});
@ -224,6 +226,8 @@ export class NotesService {
//TODO: Calculate patch
revisions.push(Revision.create(noteContent, noteContent));
note.revisions = Promise.resolve(revisions);
note.userPermissions = [];
note.groupPermissions = [];
return await this.noteRepository.save(note);
}
@ -270,6 +274,7 @@ export class NotesService {
user,
newUserPermission.canEdit,
);
createdPermission.note = note;
note.userPermissions.push(createdPermission);
}
@ -282,6 +287,7 @@ export class NotesService {
group,
newGroupPermission.canEdit,
);
createdPermission.note = note;
note.groupPermissions.push(createdPermission);
}