mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-23 10:16:32 -05:00
Permissions: Add cascade
This makes it possible to create permissions by setting them in the note entity and delete them when either the user or note is deleted. Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
f3d53a687b
commit
029dc0d7d6
3 changed files with 22 additions and 5 deletions
|
@ -39,9 +39,14 @@ export class Note {
|
||||||
@OneToMany(
|
@OneToMany(
|
||||||
(_) => NoteGroupPermission,
|
(_) => NoteGroupPermission,
|
||||||
(groupPermission) => groupPermission.note,
|
(groupPermission) => groupPermission.note,
|
||||||
|
{ cascade: true }, // This ensures that embedded NoteGroupPermissions are automatically saved to the database
|
||||||
)
|
)
|
||||||
groupPermissions: NoteGroupPermission[];
|
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[];
|
userPermissions: NoteUserPermission[];
|
||||||
@Column({
|
@Column({
|
||||||
nullable: false,
|
nullable: false,
|
||||||
|
|
|
@ -10,10 +10,16 @@ import { Note } from '../notes/note.entity';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class NoteGroupPermission {
|
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;
|
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;
|
note: Note;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
|
|
|
@ -10,10 +10,16 @@ import { User } from '../users/user.entity';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class NoteUserPermission {
|
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;
|
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;
|
note: Note;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
|
|
Loading…
Reference in a new issue