mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-29 19:14:25 -05:00
Update Note entity
We now use the new permissions split in users and groups. Also the note now knows the colors of its authors. Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
1121ed9507
commit
67e60a3c37
4 changed files with 47 additions and 71 deletions
|
@ -6,19 +6,11 @@ import {
|
||||||
OneToMany,
|
OneToMany,
|
||||||
PrimaryGeneratedColumn,
|
PrimaryGeneratedColumn,
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
import { Author } from '../authors/author.entity';
|
import { NoteGroupPermission } from '../permissions/note-group-permission.entity';
|
||||||
|
import { NoteUserPermission } from '../permissions/note-user-permission.entity';
|
||||||
import { Revision } from '../revisions/revision.entity';
|
import { Revision } from '../revisions/revision.entity';
|
||||||
import { User } from '../users/user.entity';
|
import { User } from '../users/user.entity';
|
||||||
|
import { AuthorColor } from './author-color.entity';
|
||||||
// permission types
|
|
||||||
enum PermissionEnum {
|
|
||||||
freely = 'freely',
|
|
||||||
editable = 'editable',
|
|
||||||
limited = 'limited',
|
|
||||||
locked = 'locked',
|
|
||||||
protected = 'protected',
|
|
||||||
private = 'private',
|
|
||||||
}
|
|
||||||
|
|
||||||
@Entity('Notes')
|
@Entity('Notes')
|
||||||
export class Note {
|
export class Note {
|
||||||
|
@ -37,10 +29,17 @@ export class Note {
|
||||||
})
|
})
|
||||||
alias: string;
|
alias: string;
|
||||||
|
|
||||||
@Column({
|
@OneToMany(
|
||||||
type: 'text',
|
_ => NoteGroupPermission,
|
||||||
})
|
groupPermission => groupPermission.note,
|
||||||
permission: PermissionEnum;
|
)
|
||||||
|
groupPermissions: NoteGroupPermission[];
|
||||||
|
|
||||||
|
@OneToMany(
|
||||||
|
_ => NoteUserPermission,
|
||||||
|
userPermission => userPermission.note,
|
||||||
|
)
|
||||||
|
userPermissions: NoteUserPermission[];
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: false,
|
nullable: false,
|
||||||
|
@ -48,20 +47,13 @@ export class Note {
|
||||||
})
|
})
|
||||||
viewcount: number;
|
viewcount: number;
|
||||||
|
|
||||||
@Column({
|
@ManyToOne(
|
||||||
nullable: true,
|
_ => User,
|
||||||
})
|
user => user.ownedNotes,
|
||||||
lastchangeAt: Date;
|
{ onDelete: 'CASCADE' },
|
||||||
|
)
|
||||||
@Column()
|
|
||||||
savedAt: Date;
|
|
||||||
|
|
||||||
@ManyToOne(_ => User, { onDelete: 'CASCADE' })
|
|
||||||
owner: User;
|
owner: User;
|
||||||
|
|
||||||
@ManyToOne(_ => User)
|
|
||||||
lastchangeuser: User;
|
|
||||||
|
|
||||||
@OneToMany(
|
@OneToMany(
|
||||||
_ => Revision,
|
_ => Revision,
|
||||||
revision => revision.note,
|
revision => revision.note,
|
||||||
|
@ -69,39 +61,12 @@ export class Note {
|
||||||
revisions: Revision[];
|
revisions: Revision[];
|
||||||
|
|
||||||
@OneToMany(
|
@OneToMany(
|
||||||
_ => Author,
|
_ => AuthorColor,
|
||||||
author => author.note,
|
authorColor => authorColor.note,
|
||||||
)
|
)
|
||||||
authors: Author[];
|
authorColors: AuthorColor[];
|
||||||
|
|
||||||
@Column({
|
constructor(shortid: string, alias: string, owner: User) {
|
||||||
type: 'text',
|
|
||||||
nullable: true,
|
|
||||||
})
|
|
||||||
title: string;
|
|
||||||
|
|
||||||
@Column({
|
|
||||||
type: 'text',
|
|
||||||
})
|
|
||||||
content: string;
|
|
||||||
|
|
||||||
@Column({
|
|
||||||
type: 'text',
|
|
||||||
nullable: true,
|
|
||||||
})
|
|
||||||
authorship: string;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
shortid: string,
|
|
||||||
alias: string,
|
|
||||||
permission: PermissionEnum,
|
|
||||||
lastchangeAt: Date,
|
|
||||||
savedAt: Date,
|
|
||||||
owner: User,
|
|
||||||
title: string,
|
|
||||||
content: string,
|
|
||||||
authorship: string,
|
|
||||||
) {
|
|
||||||
if (shortid) {
|
if (shortid) {
|
||||||
this.shortid = shortid;
|
this.shortid = shortid;
|
||||||
} else {
|
} else {
|
||||||
|
@ -109,12 +74,6 @@ export class Note {
|
||||||
this.shortid = shortIdGenerate() as string;
|
this.shortid = shortIdGenerate() as string;
|
||||||
}
|
}
|
||||||
this.alias = alias;
|
this.alias = alias;
|
||||||
this.permission = permission;
|
|
||||||
this.lastchangeAt = lastchangeAt;
|
|
||||||
this.savedAt = savedAt;
|
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.title = title;
|
|
||||||
this.content = content;
|
|
||||||
this.authorship = authorship;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
import { Column, ManyToOne } from 'typeorm/index';
|
import { Column, Entity, ManyToOne } from 'typeorm/index';
|
||||||
import { Group } from '../groups/group.entity';
|
import { Group } from '../groups/group.entity';
|
||||||
import { Note } from '../notes/note.entity';
|
import { Note } from '../notes/note.entity';
|
||||||
|
|
||||||
|
@Entity()
|
||||||
export class NoteGroupPermission {
|
export class NoteGroupPermission {
|
||||||
@ManyToOne(_ => Group)
|
@ManyToOne(_ => Group, { primary: true })
|
||||||
group: Group;
|
group: Group;
|
||||||
|
|
||||||
@ManyToOne(_ => Note)
|
@ManyToOne(
|
||||||
|
_ => Note,
|
||||||
|
note => note.groupPermissions,
|
||||||
|
{ primary: true },
|
||||||
|
)
|
||||||
note: Note;
|
note: Note;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
import { Column, ManyToOne } from 'typeorm/index';
|
import { Column, Entity, ManyToOne } from 'typeorm/index';
|
||||||
import { Note } from '../notes/note.entity';
|
import { Note } from '../notes/note.entity';
|
||||||
import { User } from '../users/user.entity';
|
import { User } from '../users/user.entity';
|
||||||
|
|
||||||
|
@Entity()
|
||||||
export class NoteUserPermission {
|
export class NoteUserPermission {
|
||||||
@ManyToOne(_ => User)
|
@ManyToOne(_ => User, { primary: true })
|
||||||
user: User;
|
user: User;
|
||||||
|
|
||||||
@ManyToOne(_ => Note)
|
@ManyToOne(
|
||||||
|
_ => Note,
|
||||||
|
note => note.userPermissions,
|
||||||
|
{ primary: true },
|
||||||
|
)
|
||||||
note: Note;
|
note: Note;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
|
|
|
@ -1,4 +1,11 @@
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { NoteGroupPermission } from './note-group-permission.entity';
|
||||||
|
import { NoteUserPermission } from './note-user-permission.entity';
|
||||||
|
|
||||||
@Module({})
|
@Module({
|
||||||
|
imports: [
|
||||||
|
TypeOrmModule.forFeature([NoteUserPermission, NoteGroupPermission]),
|
||||||
|
],
|
||||||
|
})
|
||||||
export class PermissionsModule {}
|
export class PermissionsModule {}
|
||||||
|
|
Loading…
Reference in a new issue