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);
}

View file

@ -10,10 +10,16 @@ import { Note } from '../notes/note.entity';
@Entity()
export class NoteGroupPermission {
@ManyToOne((_) => Group, { primary: true })
@ManyToOne((_) => Group, {
primary: true,
onDelete: 'CASCADE', // This deletes the NoteGroupPermission, when the associated Group is deleted
})
group: Group;
@ManyToOne((_) => Note, (note) => note.groupPermissions, { primary: true })
@ManyToOne((_) => Note, (note) => note.groupPermissions, {
primary: true,
onDelete: 'CASCADE', // This deletes the NoteGroupPermission, when the associated Note is deleted
})
note: Note;
@Column()

View file

@ -10,10 +10,16 @@ import { User } from '../users/user.entity';
@Entity()
export class NoteUserPermission {
@ManyToOne((_) => User, { primary: true })
@ManyToOne((_) => User, {
primary: true,
onDelete: 'CASCADE', // This deletes the NoteUserPermission, when the associated Note is deleted
})
user: User;
@ManyToOne((_) => Note, (note) => note.userPermissions, { primary: true })
@ManyToOne((_) => Note, (note) => note.userPermissions, {
primary: true,
onDelete: 'CASCADE', // This deletes the NoteUserPermission, when the associated Note is deleted
})
note: Note;
@Column()