mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-18 17:25:16 -04:00
NotePermissions: Remove default constructors
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>
This commit is contained in:
parent
353384435e
commit
577811be29
3 changed files with 21 additions and 9 deletions
|
@ -18,4 +18,14 @@ export class NoteGroupPermission {
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
canEdit: boolean;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,4 +18,14 @@ export class NoteUserPermission {
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
canEdit: boolean;
|
canEdit: boolean;
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||||
|
private constructor() {}
|
||||||
|
|
||||||
|
public static create(user: User, canEdit: boolean): NoteUserPermission {
|
||||||
|
const userPermission = new NoteUserPermission();
|
||||||
|
userPermission.user = user;
|
||||||
|
userPermission.canEdit = canEdit;
|
||||||
|
return userPermission;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,11 +23,6 @@ import { Revision } from '../revisions/revision.entity';
|
||||||
import { Tag } from '../notes/tag.entity';
|
import { Tag } from '../notes/tag.entity';
|
||||||
import { Group } from '../groups/group.entity';
|
import { Group } from '../groups/group.entity';
|
||||||
|
|
||||||
jest.mock('../permissions/note-group-permission.entity.ts');
|
|
||||||
jest.mock('../groups/group.entity.ts');
|
|
||||||
jest.mock('../notes/note.entity.ts');
|
|
||||||
jest.mock('../users/user.entity.ts');
|
|
||||||
|
|
||||||
describe('PermissionsService', () => {
|
describe('PermissionsService', () => {
|
||||||
let permissionsService: PermissionsService;
|
let permissionsService: PermissionsService;
|
||||||
|
|
||||||
|
@ -292,10 +287,7 @@ describe('PermissionsService', () => {
|
||||||
group: Group,
|
group: Group,
|
||||||
write: boolean,
|
write: boolean,
|
||||||
): NoteGroupPermission {
|
): NoteGroupPermission {
|
||||||
const noteGroupPermission = new NoteGroupPermission();
|
return NoteGroupPermission.create(group, write);
|
||||||
noteGroupPermission.canEdit = write;
|
|
||||||
noteGroupPermission.group = group;
|
|
||||||
return noteGroupPermission;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const everybodyRead = createNoteGroupPermission(groups['everybody'], false);
|
const everybodyRead = createNoteGroupPermission(groups['everybody'], false);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue