]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/models/user/user-interface.ts
Support roles with rights and add moderator role
[github/Chocobozzz/PeerTube.git] / server / models / user / user-interface.ts
CommitLineData
e02643f3 1import * as Sequelize from 'sequelize'
6fcd19ba 2import * as Promise from 'bluebird'
69818c93
C
3
4// Don't use barrel, import just what we need
0aef76c4 5import { User as FormattedUser } from '../../../shared/models/users/user.model'
6fcd19ba 6import { ResultList } from '../../../shared/models/result-list.model'
72c7248b 7import { AuthorInstance } from '../video/author-interface'
954605a8
C
8import { UserRight } from '../../../shared/models/users/user-right.enum'
9import { UserRole } from '../../../shared/models/users/user-role'
e02643f3
C
10
11export namespace UserMethods {
954605a8 12 export type HasRight = (this: UserInstance, right: UserRight) => boolean
6fcd19ba 13 export type IsPasswordMatch = (this: UserInstance, password: string) => Promise<boolean>
69818c93 14
0aef76c4 15 export type ToFormattedJSON = (this: UserInstance) => FormattedUser
b0f9f39e 16 export type IsAbleToUploadVideo = (this: UserInstance, videoFile: Express.Multer.File) => Promise<boolean>
e02643f3 17
6fcd19ba 18 export type CountTotal = () => Promise<number>
69818c93 19
6fcd19ba 20 export type GetByUsername = (username: string) => Promise<UserInstance>
69818c93 21
6fcd19ba 22 export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<UserInstance> >
69818c93 23
6fcd19ba 24 export type LoadById = (id: number) => Promise<UserInstance>
69818c93 25
6fcd19ba 26 export type LoadByUsername = (username: string) => Promise<UserInstance>
72c7248b 27 export type LoadByUsernameAndPopulateChannels = (username: string) => Promise<UserInstance>
69818c93 28
6fcd19ba 29 export type LoadByUsernameOrEmail = (username: string, email: string) => Promise<UserInstance>
e02643f3
C
30}
31
32export interface UserClass {
33 isPasswordMatch: UserMethods.IsPasswordMatch,
0aef76c4 34 toFormattedJSON: UserMethods.ToFormattedJSON,
954605a8 35 hasRight: UserMethods.HasRight,
b0f9f39e 36 isAbleToUploadVideo: UserMethods.IsAbleToUploadVideo,
e02643f3
C
37
38 countTotal: UserMethods.CountTotal,
39 getByUsername: UserMethods.GetByUsername,
e02643f3
C
40 listForApi: UserMethods.ListForApi,
41 loadById: UserMethods.LoadById,
42 loadByUsername: UserMethods.LoadByUsername,
72c7248b 43 loadByUsernameAndPopulateChannels: UserMethods.LoadByUsernameAndPopulateChannels,
e02643f3
C
44 loadByUsernameOrEmail: UserMethods.LoadByUsernameOrEmail
45}
46
47export interface UserAttributes {
b0f9f39e 48 id?: number
e02643f3
C
49 password: string
50 username: string
51 email: string
52 displayNSFW?: boolean
ee9e7b61 53 role: UserRole
b0f9f39e 54 videoQuota: number
72c7248b
C
55
56 Author?: AuthorInstance
e02643f3
C
57}
58
59export interface UserInstance extends UserClass, UserAttributes, Sequelize.Instance<UserAttributes> {
60 id: number
61 createdAt: Date
62 updatedAt: Date
154898b0
C
63
64 isPasswordMatch: UserMethods.IsPasswordMatch
0aef76c4 65 toFormattedJSON: UserMethods.ToFormattedJSON
954605a8 66 hasRight: UserMethods.HasRight
e02643f3
C
67}
68
69export interface UserModel extends UserClass, Sequelize.Model<UserInstance, UserAttributes> {}