mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-21 17:26:29 -05:00
chore: move identity entity in its own folder
Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
547f2239cc
commit
23e26fb830
19 changed files with 129 additions and 73 deletions
|
@ -40,8 +40,9 @@ entity "identity" {
|
|||
*id : number
|
||||
--
|
||||
*userId : uuid <<FK user>>
|
||||
*providerType: text
|
||||
' Identifies the external login provider and is set in the config
|
||||
*providerName : text
|
||||
providerName : text
|
||||
*syncSource : boolean
|
||||
*createdAt : date
|
||||
*updatedAt : date
|
||||
|
|
|
@ -17,6 +17,7 @@ import appConfigMock from '../../../../config/mock/app.config.mock';
|
|||
import { Group } from '../../../../groups/group.entity';
|
||||
import { HistoryEntry } from '../../../../history/history-entry.entity';
|
||||
import { HistoryModule } from '../../../../history/history.module';
|
||||
import { Identity } from '../../../../identity/identity.entity';
|
||||
import { LoggerModule } from '../../../../logger/logger.module';
|
||||
import { Note } from '../../../../notes/note.entity';
|
||||
import { NotesModule } from '../../../../notes/notes.module';
|
||||
|
@ -25,7 +26,6 @@ import { NoteGroupPermission } from '../../../../permissions/note-group-permissi
|
|||
import { NoteUserPermission } from '../../../../permissions/note-user-permission.entity';
|
||||
import { Edit } from '../../../../revisions/edit.entity';
|
||||
import { Revision } from '../../../../revisions/revision.entity';
|
||||
import { Identity } from '../../../../users/identity.entity';
|
||||
import { Session } from '../../../../users/session.entity';
|
||||
import { User } from '../../../../users/user.entity';
|
||||
import { UsersModule } from '../../../../users/users.module';
|
||||
|
|
|
@ -14,6 +14,7 @@ import customizationConfigMock from '../../../config/mock/customization.config.m
|
|||
import externalServicesConfigMock from '../../../config/mock/external-services.config.mock';
|
||||
import mediaConfigMock from '../../../config/mock/media.config.mock';
|
||||
import { Group } from '../../../groups/group.entity';
|
||||
import { Identity } from '../../../identity/identity.entity';
|
||||
import { LoggerModule } from '../../../logger/logger.module';
|
||||
import { MediaUpload } from '../../../media/media-upload.entity';
|
||||
import { MediaModule } from '../../../media/media.module';
|
||||
|
@ -23,7 +24,6 @@ import { NoteGroupPermission } from '../../../permissions/note-group-permission.
|
|||
import { NoteUserPermission } from '../../../permissions/note-user-permission.entity';
|
||||
import { Edit } from '../../../revisions/edit.entity';
|
||||
import { Revision } from '../../../revisions/revision.entity';
|
||||
import { Identity } from '../../../users/identity.entity';
|
||||
import { Session } from '../../../users/session.entity';
|
||||
import { User } from '../../../users/user.entity';
|
||||
import { UsersModule } from '../../../users/users.module';
|
||||
|
|
|
@ -15,6 +15,7 @@ import customizationConfigMock from '../../../config/mock/customization.config.m
|
|||
import externalConfigMock from '../../../config/mock/external-services.config.mock';
|
||||
import mediaConfigMock from '../../../config/mock/media.config.mock';
|
||||
import { Group } from '../../../groups/group.entity';
|
||||
import { Identity } from '../../../identity/identity.entity';
|
||||
import { LoggerModule } from '../../../logger/logger.module';
|
||||
import { MediaUpload } from '../../../media/media-upload.entity';
|
||||
import { MediaModule } from '../../../media/media.module';
|
||||
|
@ -25,7 +26,6 @@ import { NoteGroupPermission } from '../../../permissions/note-group-permission.
|
|||
import { NoteUserPermission } from '../../../permissions/note-user-permission.entity';
|
||||
import { Edit } from '../../../revisions/edit.entity';
|
||||
import { Revision } from '../../../revisions/revision.entity';
|
||||
import { Identity } from '../../../users/identity.entity';
|
||||
import { Session } from '../../../users/session.entity';
|
||||
import { User } from '../../../users/user.entity';
|
||||
import { UsersModule } from '../../../users/users.module';
|
||||
|
|
|
@ -19,6 +19,7 @@ import { Group } from '../../../groups/group.entity';
|
|||
import { GroupsModule } from '../../../groups/groups.module';
|
||||
import { HistoryEntry } from '../../../history/history-entry.entity';
|
||||
import { HistoryModule } from '../../../history/history.module';
|
||||
import { Identity } from '../../../identity/identity.entity';
|
||||
import { LoggerModule } from '../../../logger/logger.module';
|
||||
import { MediaUpload } from '../../../media/media-upload.entity';
|
||||
import { MediaModule } from '../../../media/media.module';
|
||||
|
@ -31,7 +32,6 @@ import { PermissionsModule } from '../../../permissions/permissions.module';
|
|||
import { Edit } from '../../../revisions/edit.entity';
|
||||
import { Revision } from '../../../revisions/revision.entity';
|
||||
import { RevisionsModule } from '../../../revisions/revisions.module';
|
||||
import { Identity } from '../../../users/identity.entity';
|
||||
import { Session } from '../../../users/session.entity';
|
||||
import { User } from '../../../users/user.entity';
|
||||
import { UsersModule } from '../../../users/users.module';
|
||||
|
|
|
@ -10,8 +10,8 @@ import { getRepositoryToken } from '@nestjs/typeorm';
|
|||
import { AuthToken } from '../../../auth/auth-token.entity';
|
||||
import { AuthModule } from '../../../auth/auth.module';
|
||||
import appConfigMock from '../../../config/mock/app.config.mock';
|
||||
import { Identity } from '../../../identity/identity.entity';
|
||||
import { LoggerModule } from '../../../logger/logger.module';
|
||||
import { Identity } from '../../../users/identity.entity';
|
||||
import { Session } from '../../../users/session.entity';
|
||||
import { User } from '../../../users/user.entity';
|
||||
import { TokensController } from './tokens.controller';
|
||||
|
|
|
@ -18,6 +18,7 @@ import mediaConfigMock from '../../../config/mock/media.config.mock';
|
|||
import { Group } from '../../../groups/group.entity';
|
||||
import { HistoryEntry } from '../../../history/history-entry.entity';
|
||||
import { HistoryModule } from '../../../history/history.module';
|
||||
import { Identity } from '../../../identity/identity.entity';
|
||||
import { LoggerModule } from '../../../logger/logger.module';
|
||||
import { MediaUpload } from '../../../media/media-upload.entity';
|
||||
import { MediaModule } from '../../../media/media.module';
|
||||
|
@ -28,7 +29,6 @@ import { NoteGroupPermission } from '../../../permissions/note-group-permission.
|
|||
import { NoteUserPermission } from '../../../permissions/note-user-permission.entity';
|
||||
import { Edit } from '../../../revisions/edit.entity';
|
||||
import { Revision } from '../../../revisions/revision.entity';
|
||||
import { Identity } from '../../../users/identity.entity';
|
||||
import { Session } from '../../../users/session.entity';
|
||||
import { User } from '../../../users/user.entity';
|
||||
import { UsersModule } from '../../../users/users.module';
|
||||
|
|
|
@ -12,6 +12,7 @@ import { Author } from '../../../authors/author.entity';
|
|||
import appConfigMock from '../../../config/mock/app.config.mock';
|
||||
import mediaConfigMock from '../../../config/mock/media.config.mock';
|
||||
import { Group } from '../../../groups/group.entity';
|
||||
import { Identity } from '../../../identity/identity.entity';
|
||||
import { LoggerModule } from '../../../logger/logger.module';
|
||||
import { MediaUpload } from '../../../media/media-upload.entity';
|
||||
import { MediaModule } from '../../../media/media.module';
|
||||
|
@ -22,7 +23,6 @@ import { NoteGroupPermission } from '../../../permissions/note-group-permission.
|
|||
import { NoteUserPermission } from '../../../permissions/note-user-permission.entity';
|
||||
import { Edit } from '../../../revisions/edit.entity';
|
||||
import { Revision } from '../../../revisions/revision.entity';
|
||||
import { Identity } from '../../../users/identity.entity';
|
||||
import { Session } from '../../../users/session.entity';
|
||||
import { User } from '../../../users/user.entity';
|
||||
import { MediaController } from './media.controller';
|
||||
|
|
|
@ -19,6 +19,7 @@ import { Group } from '../../../groups/group.entity';
|
|||
import { GroupsModule } from '../../../groups/groups.module';
|
||||
import { HistoryEntry } from '../../../history/history-entry.entity';
|
||||
import { HistoryModule } from '../../../history/history.module';
|
||||
import { Identity } from '../../../identity/identity.entity';
|
||||
import { LoggerModule } from '../../../logger/logger.module';
|
||||
import { MediaUpload } from '../../../media/media-upload.entity';
|
||||
import { MediaModule } from '../../../media/media.module';
|
||||
|
@ -31,7 +32,6 @@ import { PermissionsModule } from '../../../permissions/permissions.module';
|
|||
import { Edit } from '../../../revisions/edit.entity';
|
||||
import { Revision } from '../../../revisions/revision.entity';
|
||||
import { RevisionsModule } from '../../../revisions/revisions.module';
|
||||
import { Identity } from '../../../users/identity.entity';
|
||||
import { Session } from '../../../users/session.entity';
|
||||
import { User } from '../../../users/user.entity';
|
||||
import { UsersModule } from '../../../users/users.module';
|
||||
|
|
|
@ -13,6 +13,7 @@ import { Author } from '../authors/author.entity';
|
|||
import appConfigMock from '../config/mock/app.config.mock';
|
||||
import { NotInDBError } from '../errors/errors';
|
||||
import { Group } from '../groups/group.entity';
|
||||
import { Identity } from '../identity/identity.entity';
|
||||
import { LoggerModule } from '../logger/logger.module';
|
||||
import { Note } from '../notes/note.entity';
|
||||
import { NotesModule } from '../notes/notes.module';
|
||||
|
@ -21,7 +22,6 @@ import { NoteGroupPermission } from '../permissions/note-group-permission.entity
|
|||
import { NoteUserPermission } from '../permissions/note-user-permission.entity';
|
||||
import { Edit } from '../revisions/edit.entity';
|
||||
import { Revision } from '../revisions/revision.entity';
|
||||
import { Identity } from '../users/identity.entity';
|
||||
import { Session } from '../users/session.entity';
|
||||
import { User } from '../users/user.entity';
|
||||
import { UsersModule } from '../users/users.module';
|
||||
|
|
111
src/identity/identity.entity.ts
Normal file
111
src/identity/identity.entity.ts
Normal file
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
import { User } from '../users/user.entity';
|
||||
import { ProviderType } from './provider-type.enum';
|
||||
|
||||
/**
|
||||
* The identity represents a single way for a user to login.
|
||||
* A 'user' can have any number of these.
|
||||
* Each one holds a type (local, github, twitter, etc.), if this type can have multiple instances (e.g. gitlab),
|
||||
* it also saves the name of the instance. Also if this identity shall be the syncSource is saved.
|
||||
*/
|
||||
@Entity()
|
||||
export class Identity {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
/**
|
||||
* User that this identity corresponds to
|
||||
*/
|
||||
@ManyToOne((_) => User, (user) => user.identities, {
|
||||
onDelete: 'CASCADE', // This deletes the Identity, when the associated User is deleted
|
||||
})
|
||||
user: User;
|
||||
|
||||
/**
|
||||
* The ProviderType of the identity
|
||||
*/
|
||||
@Column()
|
||||
providerType: string;
|
||||
|
||||
/**
|
||||
* The name of the provider.
|
||||
* Only set if there are multiple provider of that type (e.g. gitlab)
|
||||
*/
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: 'text',
|
||||
})
|
||||
providerName: string | null;
|
||||
|
||||
/**
|
||||
* If the identity should be used as the sync source.
|
||||
* See [authentication doc](../../docs/content/dev/authentication.md) for clarification
|
||||
*/
|
||||
@Column()
|
||||
syncSource: boolean;
|
||||
|
||||
/**
|
||||
* When the identity was created.
|
||||
*/
|
||||
@CreateDateColumn()
|
||||
createdAt: Date;
|
||||
|
||||
/**
|
||||
* When the identity was last updated.
|
||||
*/
|
||||
@UpdateDateColumn()
|
||||
updatedAt: Date;
|
||||
|
||||
/**
|
||||
* The unique identifier of a user from the login provider
|
||||
*/
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: 'text',
|
||||
})
|
||||
providerUserId: string | null;
|
||||
|
||||
/**
|
||||
* Token used to access the OAuth provider in the users name.
|
||||
*/
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: 'text',
|
||||
})
|
||||
oAuthAccessToken: string | null;
|
||||
|
||||
/**
|
||||
* The hash of the password
|
||||
* Only set when the type of the identity is local
|
||||
*/
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: 'text',
|
||||
})
|
||||
passwordHash: string | null;
|
||||
|
||||
public static create(
|
||||
user: User,
|
||||
providerType: ProviderType,
|
||||
syncSource = false,
|
||||
): Identity {
|
||||
const newIdentity = new Identity();
|
||||
newIdentity.user = user;
|
||||
newIdentity.providerType = providerType;
|
||||
newIdentity.syncSource = syncSource;
|
||||
return newIdentity;
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ import { Author } from '../authors/author.entity';
|
|||
import mediaConfigMock from '../config/mock/media.config.mock';
|
||||
import { ClientError, NotInDBError } from '../errors/errors';
|
||||
import { Group } from '../groups/group.entity';
|
||||
import { Identity } from '../identity/identity.entity';
|
||||
import { LoggerModule } from '../logger/logger.module';
|
||||
import { Note } from '../notes/note.entity';
|
||||
import { NotesModule } from '../notes/notes.module';
|
||||
|
@ -23,7 +24,6 @@ import { NoteGroupPermission } from '../permissions/note-group-permission.entity
|
|||
import { NoteUserPermission } from '../permissions/note-user-permission.entity';
|
||||
import { Edit } from '../revisions/edit.entity';
|
||||
import { Revision } from '../revisions/revision.entity';
|
||||
import { Identity } from '../users/identity.entity';
|
||||
import { Session } from '../users/session.entity';
|
||||
import { User } from '../users/user.entity';
|
||||
import { UsersModule } from '../users/users.module';
|
||||
|
|
|
@ -19,13 +19,13 @@ import {
|
|||
} from '../errors/errors';
|
||||
import { Group } from '../groups/group.entity';
|
||||
import { GroupsModule } from '../groups/groups.module';
|
||||
import { Identity } from '../identity/identity.entity';
|
||||
import { LoggerModule } from '../logger/logger.module';
|
||||
import { NoteGroupPermission } from '../permissions/note-group-permission.entity';
|
||||
import { NoteUserPermission } from '../permissions/note-user-permission.entity';
|
||||
import { Edit } from '../revisions/edit.entity';
|
||||
import { Revision } from '../revisions/revision.entity';
|
||||
import { RevisionsModule } from '../revisions/revisions.module';
|
||||
import { Identity } from '../users/identity.entity';
|
||||
import { Session } from '../users/session.entity';
|
||||
import { User } from '../users/user.entity';
|
||||
import { UsersModule } from '../users/users.module';
|
||||
|
|
|
@ -11,13 +11,13 @@ import { AuthToken } from '../auth/auth-token.entity';
|
|||
import { Author } from '../authors/author.entity';
|
||||
import appConfigMock from '../config/mock/app.config.mock';
|
||||
import { Group } from '../groups/group.entity';
|
||||
import { Identity } from '../identity/identity.entity';
|
||||
import { LoggerModule } from '../logger/logger.module';
|
||||
import { Note } from '../notes/note.entity';
|
||||
import { NotesModule } from '../notes/notes.module';
|
||||
import { Tag } from '../notes/tag.entity';
|
||||
import { Edit } from '../revisions/edit.entity';
|
||||
import { Revision } from '../revisions/revision.entity';
|
||||
import { Identity } from '../users/identity.entity';
|
||||
import { Session } from '../users/session.entity';
|
||||
import { User } from '../users/user.entity';
|
||||
import { UsersModule } from '../users/users.module';
|
||||
|
|
|
@ -13,13 +13,13 @@ import { Author } from '../authors/author.entity';
|
|||
import appConfigMock from '../config/mock/app.config.mock';
|
||||
import { NotInDBError } from '../errors/errors';
|
||||
import { Group } from '../groups/group.entity';
|
||||
import { Identity } from '../identity/identity.entity';
|
||||
import { LoggerModule } from '../logger/logger.module';
|
||||
import { Note } from '../notes/note.entity';
|
||||
import { NotesModule } from '../notes/notes.module';
|
||||
import { Tag } from '../notes/tag.entity';
|
||||
import { NoteGroupPermission } from '../permissions/note-group-permission.entity';
|
||||
import { NoteUserPermission } from '../permissions/note-user-permission.entity';
|
||||
import { Identity } from '../users/identity.entity';
|
||||
import { Session } from '../users/session.entity';
|
||||
import { User } from '../users/user.entity';
|
||||
import { Edit } from './edit.entity';
|
||||
|
|
|
@ -9,6 +9,7 @@ import { AuthToken } from './auth/auth-token.entity';
|
|||
import { Author } from './authors/author.entity';
|
||||
import { Group } from './groups/group.entity';
|
||||
import { HistoryEntry } from './history/history-entry.entity';
|
||||
import { Identity } from './identity/identity.entity';
|
||||
import { MediaUpload } from './media/media-upload.entity';
|
||||
import { Note } from './notes/note.entity';
|
||||
import { Tag } from './notes/tag.entity';
|
||||
|
@ -16,7 +17,6 @@ import { NoteGroupPermission } from './permissions/note-group-permission.entity'
|
|||
import { NoteUserPermission } from './permissions/note-user-permission.entity';
|
||||
import { Edit } from './revisions/edit.entity';
|
||||
import { Revision } from './revisions/revision.entity';
|
||||
import { Identity } from './users/identity.entity';
|
||||
import { Session } from './users/session.entity';
|
||||
import { User } from './users/user.entity';
|
||||
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
import { User } from './user.entity';
|
||||
|
||||
@Entity()
|
||||
export class Identity {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@ManyToOne((_) => User, (user) => user.identities, {
|
||||
onDelete: 'CASCADE', // This deletes the Identity, when the associated User is deleted
|
||||
})
|
||||
user: User;
|
||||
|
||||
@Column()
|
||||
providerName: string;
|
||||
|
||||
@Column()
|
||||
syncSource: boolean;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt: Date;
|
||||
|
||||
@UpdateDateColumn()
|
||||
updatedAt: Date;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: 'text',
|
||||
})
|
||||
providerUserId: string | null;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: 'text',
|
||||
})
|
||||
oAuthAccessToken: string | null;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: 'text',
|
||||
})
|
||||
passwordHash: string | null;
|
||||
}
|
|
@ -17,9 +17,9 @@ import { AuthToken } from '../auth/auth-token.entity';
|
|||
import { Author } from '../authors/author.entity';
|
||||
import { Group } from '../groups/group.entity';
|
||||
import { HistoryEntry } from '../history/history-entry.entity';
|
||||
import { Identity } from '../identity/identity.entity';
|
||||
import { MediaUpload } from '../media/media-upload.entity';
|
||||
import { Note } from '../notes/note.entity';
|
||||
import { Identity } from './identity.entity';
|
||||
|
||||
@Entity()
|
||||
export class User {
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
import { Identity } from '../identity/identity.entity';
|
||||
import { LoggerModule } from '../logger/logger.module';
|
||||
import { Identity } from './identity.entity';
|
||||
import { Session } from './session.entity';
|
||||
import { User } from './user.entity';
|
||||
import { UsersService } from './users.service';
|
||||
|
|
Loading…
Reference in a new issue