]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/user/user-interface.ts
Support roles with rights and add moderator role
[github/Chocobozzz/PeerTube.git] / server / models / user / user-interface.ts
index fd98a042e06e75c66fda005df6b700a0d6022a35..49c75aa3be84be1227aa1f4ab0cc0cf34216edad 100644 (file)
@@ -1,63 +1,69 @@
 import * as Sequelize from 'sequelize'
-import * as Bluebird from 'bluebird'
+import * as Promise from 'bluebird'
 
 // Don't use barrel, import just what we need
-import { UserRole, User as FormatedUser } from '../../../shared/models/user.model'
+import { User as FormattedUser } from '../../../shared/models/users/user.model'
+import { ResultList } from '../../../shared/models/result-list.model'
+import { AuthorInstance } from '../video/author-interface'
+import { UserRight } from '../../../shared/models/users/user-right.enum'
+import { UserRole } from '../../../shared/models/users/user-role'
 
 export namespace UserMethods {
-  export type IsPasswordMatchCallback = (err: Error, same: boolean) => void
-  export type IsPasswordMatch = (this: UserInstance, password: string, callback: IsPasswordMatchCallback) => void
+  export type HasRight = (this: UserInstance, right: UserRight) => boolean
+  export type IsPasswordMatch = (this: UserInstance, password: string) => Promise<boolean>
 
-  export type ToFormatedJSON = (this: UserInstance) => FormatedUser
-  export type IsAdmin = (this: UserInstance) => boolean
+  export type ToFormattedJSON = (this: UserInstance) => FormattedUser
+  export type IsAbleToUploadVideo = (this: UserInstance, videoFile: Express.Multer.File) => Promise<boolean>
 
-  export type CountTotalCallback = (err: Error, total: number) => void
-  export type CountTotal = (callback: CountTotalCallback) => void
+  export type CountTotal = () => Promise<number>
 
-  export type GetByUsername = (username: string) => Bluebird<UserInstance>
+  export type GetByUsername = (username: string) => Promise<UserInstance>
 
-  export type ListCallback = (err: Error, userInstances: UserInstance[]) => void
-  export type List = (callback: ListCallback) => void
+  export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<UserInstance> >
 
-  export type ListForApiCallback = (err: Error, userInstances?: UserInstance[], total?: number) => void
-  export type ListForApi = (start: number, count: number, sort: string, callback: ListForApiCallback) => void
+  export type LoadById = (id: number) => Promise<UserInstance>
 
-  export type LoadByIdCallback = (err: Error, userInstance: UserInstance) => void
-  export type LoadById = (id: number, callback: LoadByIdCallback) => void
+  export type LoadByUsername = (username: string) => Promise<UserInstance>
+  export type LoadByUsernameAndPopulateChannels = (username: string) => Promise<UserInstance>
 
-  export type LoadByUsernameCallback = (err: Error, userInstance: UserInstance) => void
-  export type LoadByUsername = (username: string, callback: LoadByUsernameCallback) => void
-
-  export type LoadByUsernameOrEmailCallback = (err: Error, userInstance: UserInstance) => void
-  export type LoadByUsernameOrEmail = (username: string, email: string, callback: LoadByUsernameOrEmailCallback) => void
+  export type LoadByUsernameOrEmail = (username: string, email: string) => Promise<UserInstance>
 }
 
 export interface UserClass {
   isPasswordMatch: UserMethods.IsPasswordMatch,
-  toFormatedJSON: UserMethods.ToFormatedJSON,
-  isAdmin: UserMethods.IsAdmin,
+  toFormattedJSON: UserMethods.ToFormattedJSON,
+  hasRight: UserMethods.HasRight,
+  isAbleToUploadVideo: UserMethods.IsAbleToUploadVideo,
 
   countTotal: UserMethods.CountTotal,
   getByUsername: UserMethods.GetByUsername,
-  list: UserMethods.List,
   listForApi: UserMethods.ListForApi,
   loadById: UserMethods.LoadById,
   loadByUsername: UserMethods.LoadByUsername,
+  loadByUsernameAndPopulateChannels: UserMethods.LoadByUsernameAndPopulateChannels,
   loadByUsernameOrEmail: UserMethods.LoadByUsernameOrEmail
 }
 
 export interface UserAttributes {
+  id?: number
   password: string
   username: string
   email: string
   displayNSFW?: boolean
   role: UserRole
+  videoQuota: number
+
+  Author?: AuthorInstance
 }
 
 export interface UserInstance extends UserClass, UserAttributes, Sequelize.Instance<UserAttributes> {
   id: number
   createdAt: Date
   updatedAt: Date
+
+  isPasswordMatch: UserMethods.IsPasswordMatch
+  toFormattedJSON: UserMethods.ToFormattedJSON
+  hasRight: UserMethods.HasRight
 }
 
 export interface UserModel extends UserClass, Sequelize.Model<UserInstance, UserAttributes> {}