History: Add HistoryEntry

With this the backend now can hold a history entry.
Also included in this commit are some minor changes to tests and services so they can still work.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2021-02-03 21:15:39 +01:00
parent 6bce4c241b
commit b76fa91a3c
7 changed files with 72 additions and 2 deletions

View file

@ -134,11 +134,20 @@ entity "media_upload" {
*createdAt : date *createdAt : date
} }
entity "history_entry" {
*noteId : uuid <<FK note>>
*userId : uuid <<FK user>>
--
*pinStatus: boolean
*updatedAt: date
}
user "1" -- "0..*" note: owner user "1" -- "0..*" note: owner
user "1" -u- "1..*" identity user "1" -u- "1..*" identity
user "1" - "1..*" auth_token: authTokens user "1" - "1..*" auth_token: authTokens
user "1" -l- "1..*" session user "1" -l- "1..*" session
user "1" - "0..*" media_upload user "1" - "0..*" media_upload
user "1" - "0..*" history_entry
user "0..*" -- "0..*" note user "0..*" -- "0..*" note
user "1" - "0..*" authorship user "1" - "0..*" authorship
@ -149,6 +158,7 @@ revision "0..*" - "0..*" authorship
media_upload "0..*" -- "1" note media_upload "0..*" -- "1" note
note "1" - "1..*" revision note "1" - "1..*" revision
note "1" - "0..*" history_entry
note "0..*" -l- "0..*" tag note "0..*" -l- "0..*" tag
note "0..*" -- "0..*" group note "0..*" -- "0..*" group

View file

@ -19,6 +19,7 @@ import { Identity } from '../../../users/identity.entity';
import { User } from '../../../users/user.entity'; import { User } from '../../../users/user.entity';
import { UsersModule } from '../../../users/users.module'; import { UsersModule } from '../../../users/users.module';
import { MeController } from './me.controller'; import { MeController } from './me.controller';
import { HistoryEntry } from '../../../history/history-entry.entity';
describe('Me Controller', () => { describe('Me Controller', () => {
let controller: MeController; let controller: MeController;
@ -44,6 +45,8 @@ describe('Me Controller', () => {
.useValue({}) .useValue({})
.overrideProvider(getRepositoryToken(Tag)) .overrideProvider(getRepositoryToken(Tag))
.useValue({}) .useValue({})
.overrideProvider(getRepositoryToken(HistoryEntry))
.useValue({})
.compile(); .compile();
controller = module.get<MeController>(MeController); controller = module.get<MeController>(MeController);

View file

@ -28,6 +28,7 @@ describe('AuthService', () => {
id: '1', id: '1',
identities: [], identities: [],
ownedNotes: [], ownedNotes: [],
historyEntries: [],
updatedAt: new Date(), updatedAt: new Date(),
userName: 'Testy', userName: 'Testy',
}; };

View file

@ -0,0 +1,47 @@
/*
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import {
Column,
Entity,
ManyToOne,
UpdateDateColumn,
} from 'typeorm';
import { User } from '../users/user.entity';
import { Note } from '../notes/note.entity';
@Entity()
export class HistoryEntry {
@ManyToOne((_) => User, (user) => user.historyEntries, {
onDelete: 'CASCADE',
primary: true,
})
user: User;
@ManyToOne((_) => Note, (note) => note.historyEntries, {
onDelete: 'CASCADE',
primary: true,
})
note: Note;
@Column()
pinStatus: boolean;
@UpdateDateColumn()
updatedAt: Date;
// The optional note parameter is necessary for the createNote method in the NotesService,
// as we create the note then and don't need to add it to the HistoryEntry.
public static create(user: User, note?: Note): HistoryEntry {
const newHistoryEntry = new HistoryEntry();
newHistoryEntry.user = user;
if (note) {
newHistoryEntry.note = note;
}
newHistoryEntry.pinStatus = false;
return newHistoryEntry;
}
}

View file

@ -20,6 +20,7 @@ import { Revision } from '../revisions/revision.entity';
import { User } from '../users/user.entity'; import { User } from '../users/user.entity';
import { AuthorColor } from './author-color.entity'; import { AuthorColor } from './author-color.entity';
import { Tag } from './tag.entity'; import { Tag } from './tag.entity';
import { HistoryEntry } from '../history/history-entry.entity';
@Entity() @Entity()
export class Note { export class Note {
@ -53,6 +54,8 @@ export class Note {
revisions: Promise<Revision[]>; revisions: Promise<Revision[]>;
@OneToMany((_) => AuthorColor, (authorColor) => authorColor.note) @OneToMany((_) => AuthorColor, (authorColor) => authorColor.note)
authorColors: AuthorColor[]; authorColors: AuthorColor[];
@OneToMany((_) => HistoryEntry, (historyEntry) => historyEntry.user)
historyEntries: HistoryEntry[];
@Column({ @Column({
nullable: true, nullable: true,

View file

@ -21,6 +21,7 @@ import {
import { NoteDto } from './note.dto'; import { NoteDto } from './note.dto';
import { Note } from './note.entity'; import { Note } from './note.entity';
import { Tag } from './tag.entity'; import { Tag } from './tag.entity';
import { HistoryEntry } from '../history/history-entry.entity';
@Injectable() @Injectable()
export class NotesService { export class NotesService {
@ -46,6 +47,7 @@ export class NotesService {
description: 'Very descriptive text.', description: 'Very descriptive text.',
userPermissions: [], userPermissions: [],
groupPermissions: [], groupPermissions: [],
historyEntries: [],
tags: [], tags: [],
revisions: Promise.resolve([]), revisions: Promise.resolve([]),
authorColors: [], authorColors: [],
@ -69,6 +71,7 @@ export class NotesService {
newNote.alias = alias; newNote.alias = alias;
} }
if (owner) { if (owner) {
newNote.historyEntries = [HistoryEntry.create(owner)];
newNote.owner = owner; newNote.owner = owner;
} }
return this.noteRepository.save(newNote); return this.noteRepository.save(newNote);
@ -153,12 +156,14 @@ export class NotesService {
id: '1', id: '1',
identities: [], identities: [],
ownedNotes: [], ownedNotes: [],
historyEntries: [],
updatedAt: new Date(), updatedAt: new Date(),
userName: 'Testy', userName: 'Testy',
}, },
description: 'Very descriptive text.', description: 'Very descriptive text.',
userPermissions: [], userPermissions: [],
groupPermissions: [], groupPermissions: [],
historyEntries: [],
tags: [], tags: [],
revisions: Promise.resolve([]), revisions: Promise.resolve([]),
authorColors: [], authorColors: [],

View file

@ -14,6 +14,7 @@ import { Column, OneToMany } from 'typeorm';
import { Note } from '../notes/note.entity'; import { Note } from '../notes/note.entity';
import { AuthToken } from '../auth/auth-token.entity'; import { AuthToken } from '../auth/auth-token.entity';
import { Identity } from './identity.entity'; import { Identity } from './identity.entity';
import { HistoryEntry } from '../history/history-entry.entity';
@Entity() @Entity()
export class User { export class User {
@ -51,8 +52,8 @@ export class User {
@OneToMany((_) => Identity, (identity) => identity.user) @OneToMany((_) => Identity, (identity) => identity.user)
identities: Identity[]; identities: Identity[];
// eslint-disable-next-line @typescript-eslint/no-empty-function @OneToMany((_) => HistoryEntry, (historyEntry) => historyEntry.user)
private constructor() {} historyEntries: HistoryEntry[];
public static create( public static create(
userName: string, userName: string,