mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-03-29 22:35:00 +00:00
As discussed in #835 we don't want to have default constructors and prefer .create methods. Because the created NoteGroupPermission and NoteUserPermission are not saved to the DB by themselves, but are saved via a change to the Note using a Pick<Class, attributes>-style return type is not helpful here as every single time the .create functions are called a full object is required. The mock calls in the PermissionService test are not needed and break the .create calls so they got removed. Signed-off-by: Philip Molares <philip.molares@udo.edu>
31 lines
845 B
TypeScript
31 lines
845 B
TypeScript
/*
|
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { Column, Entity, ManyToOne } from 'typeorm';
|
|
import { Group } from '../groups/group.entity';
|
|
import { Note } from '../notes/note.entity';
|
|
|
|
@Entity()
|
|
export class NoteGroupPermission {
|
|
@ManyToOne((_) => Group, { primary: true })
|
|
group: Group;
|
|
|
|
@ManyToOne((_) => Note, (note) => note.groupPermissions, { primary: true })
|
|
note: Note;
|
|
|
|
@Column()
|
|
canEdit: boolean;
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
private constructor() {}
|
|
|
|
public static create(group: Group, canEdit: boolean): NoteGroupPermission {
|
|
const groupPermission = new NoteGroupPermission();
|
|
groupPermission.group = group;
|
|
groupPermission.canEdit = canEdit;
|
|
return groupPermission;
|
|
}
|
|
}
|