mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 07:04:45 -04:00
NoteEntity: Allow anonymous notes
Notes created by anonymous users don't have an owner. This commit updates the entity accordingly. Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
bd56d17663
commit
0a8dd454ab
2 changed files with 6 additions and 5 deletions
|
@ -56,8 +56,9 @@ export class Note {
|
||||||
viewCount: number;
|
viewCount: number;
|
||||||
@ManyToOne((_) => User, (user) => user.ownedNotes, {
|
@ManyToOne((_) => User, (user) => user.ownedNotes, {
|
||||||
onDelete: 'CASCADE', // This deletes the Note, when the associated User is deleted
|
onDelete: 'CASCADE', // This deletes the Note, when the associated User is deleted
|
||||||
|
nullable: true,
|
||||||
})
|
})
|
||||||
owner: User;
|
owner: User | null;
|
||||||
@OneToMany((_) => Revision, (revision) => revision.note, { cascade: true })
|
@OneToMany((_) => Revision, (revision) => revision.note, { cascade: true })
|
||||||
revisions: Promise<Revision[]>;
|
revisions: Promise<Revision[]>;
|
||||||
@OneToMany((_) => AuthorColor, (authorColor) => authorColor.note)
|
@OneToMany((_) => AuthorColor, (authorColor) => authorColor.note)
|
||||||
|
@ -89,9 +90,9 @@ export class Note {
|
||||||
}
|
}
|
||||||
const newNote = new Note();
|
const newNote = new Note();
|
||||||
newNote.shortid = shortid;
|
newNote.shortid = shortid;
|
||||||
newNote.alias = alias;
|
newNote.alias = alias ?? null;
|
||||||
newNote.viewCount = 0;
|
newNote.viewCount = 0;
|
||||||
newNote.owner = owner;
|
newNote.owner = owner ?? null;
|
||||||
newNote.authorColors = [];
|
newNote.authorColors = [];
|
||||||
newNote.userPermissions = [];
|
newNote.userPermissions = [];
|
||||||
newNote.groupPermissions = [];
|
newNote.groupPermissions = [];
|
||||||
|
|
|
@ -152,7 +152,7 @@ describe('NotesService', () => {
|
||||||
expect(newNote.userPermissions).toHaveLength(0);
|
expect(newNote.userPermissions).toHaveLength(0);
|
||||||
expect(newNote.groupPermissions).toHaveLength(0);
|
expect(newNote.groupPermissions).toHaveLength(0);
|
||||||
expect(newNote.tags).toHaveLength(0);
|
expect(newNote.tags).toHaveLength(0);
|
||||||
expect(newNote.owner).toBeUndefined();
|
expect(newNote.owner).toBeNull();
|
||||||
expect(newNote.alias).toBeNull();
|
expect(newNote.alias).toBeNull();
|
||||||
});
|
});
|
||||||
it('without alias, with owner', async () => {
|
it('without alias, with owner', async () => {
|
||||||
|
@ -177,7 +177,7 @@ describe('NotesService', () => {
|
||||||
expect(newNote.userPermissions).toHaveLength(0);
|
expect(newNote.userPermissions).toHaveLength(0);
|
||||||
expect(newNote.groupPermissions).toHaveLength(0);
|
expect(newNote.groupPermissions).toHaveLength(0);
|
||||||
expect(newNote.tags).toHaveLength(0);
|
expect(newNote.tags).toHaveLength(0);
|
||||||
expect(newNote.owner).toBeUndefined();
|
expect(newNote.owner).toBeNull();
|
||||||
expect(newNote.alias).toEqual(alias);
|
expect(newNote.alias).toEqual(alias);
|
||||||
});
|
});
|
||||||
it('with alias, with owner', async () => {
|
it('with alias, with owner', async () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue