aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account/account.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-14 17:38:41 +0100
committerChocobozzz <me@florianbigard.com>2017-12-19 10:53:16 +0100
commit50d6de9c286abcb34ff4234d56d9cbb803db7665 (patch)
treef1732b27edcd05c7877a8358b8312f1e38c287ed /server/models/account/account.ts
parentfadf619ad61a016c1c7fc53de5a8f398a4f77519 (diff)
downloadPeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.tar.gz
PeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.tar.zst
PeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.zip
Begin moving video channel to actor
Diffstat (limited to 'server/models/account/account.ts')
-rw-r--r--server/models/account/account.ts111
1 files changed, 33 insertions, 78 deletions
diff --git a/server/models/account/account.ts b/server/models/account/account.ts
index b26395fd4..1ee232537 100644
--- a/server/models/account/account.ts
+++ b/server/models/account/account.ts
@@ -5,18 +5,16 @@ import {
5 BelongsTo, 5 BelongsTo,
6 Column, 6 Column,
7 CreatedAt, 7 CreatedAt,
8 DataType, 8 DefaultScope,
9 Default,
10 ForeignKey, 9 ForeignKey,
11 HasMany, 10 HasMany,
12 Is, 11 Is,
13 IsUUID,
14 Model, 12 Model,
15 Table, 13 Table,
16 UpdatedAt 14 UpdatedAt
17} from 'sequelize-typescript' 15} from 'sequelize-typescript'
18import { isUserUsernameValid } from '../../helpers/custom-validators/users' 16import { isUserUsernameValid } from '../../helpers/custom-validators/users'
19import { sendDeleteAccount } from '../../lib/activitypub/send' 17import { sendDeleteActor } from '../../lib/activitypub/send'
20import { ActorModel } from '../activitypub/actor' 18import { ActorModel } from '../activitypub/actor'
21import { ApplicationModel } from '../application/application' 19import { ApplicationModel } from '../application/application'
22import { ServerModel } from '../server/server' 20import { ServerModel } from '../server/server'
@@ -24,31 +22,30 @@ import { throwIfNotValid } from '../utils'
24import { VideoChannelModel } from '../video/video-channel' 22import { VideoChannelModel } from '../video/video-channel'
25import { UserModel } from './user' 23import { UserModel } from './user'
26 24
27@Table({ 25@DefaultScope({
28 tableName: 'account', 26 include: [
29 indexes: [
30 {
31 fields: [ 'name' ]
32 },
33 {
34 fields: [ 'serverId' ]
35 },
36 {
37 fields: [ 'userId' ],
38 unique: true
39 },
40 {
41 fields: [ 'applicationId' ],
42 unique: true
43 },
44 { 27 {
45 fields: [ 'name', 'serverId', 'applicationId' ], 28 model: () => ActorModel,
46 unique: true 29 required: true,
30 include: [
31 {
32 model: () => ServerModel,
33 required: false
34 }
35 ]
47 } 36 }
48 ] 37 ]
49}) 38})
39@Table({
40 tableName: 'account'
41})
50export class AccountModel extends Model<AccountModel> { 42export class AccountModel extends Model<AccountModel> {
51 43
44 @AllowNull(false)
45 @Is('AccountName', value => throwIfNotValid(value, isUserUsernameValid, 'account name'))
46 @Column
47 name: string
48
52 @CreatedAt 49 @CreatedAt
53 createdAt: Date 50 createdAt: Date
54 51
@@ -89,7 +86,7 @@ export class AccountModel extends Model<AccountModel> {
89 }, 86 },
90 onDelete: 'cascade' 87 onDelete: 'cascade'
91 }) 88 })
92 Application: ApplicationModel 89 Account: ApplicationModel
93 90
94 @HasMany(() => VideoChannelModel, { 91 @HasMany(() => VideoChannelModel, {
95 foreignKey: { 92 foreignKey: {
@@ -103,32 +100,27 @@ export class AccountModel extends Model<AccountModel> {
103 @AfterDestroy 100 @AfterDestroy
104 static sendDeleteIfOwned (instance: AccountModel) { 101 static sendDeleteIfOwned (instance: AccountModel) {
105 if (instance.isOwned()) { 102 if (instance.isOwned()) {
106 return sendDeleteAccount(instance, undefined) 103 return sendDeleteActor(instance.Actor, undefined)
107 } 104 }
108 105
109 return undefined 106 return undefined
110 } 107 }
111 108
112 static loadApplication () {
113 return AccountModel.findOne({
114 include: [
115 {
116 model: ApplicationModel,
117 required: true
118 }
119 ]
120 })
121 }
122
123 static load (id: number) { 109 static load (id: number) {
124 return AccountModel.findById(id) 110 return AccountModel.findById(id)
125 } 111 }
126 112
127 static loadByUUID (uuid: string) { 113 static loadByUUID (uuid: string) {
128 const query = { 114 const query = {
129 where: { 115 include: [
130 uuid 116 {
131 } 117 model: ActorModel,
118 required: true,
119 where: {
120 uuid
121 }
122 }
123 ]
132 } 124 }
133 125
134 return AccountModel.findOne(query) 126 return AccountModel.findOne(query)
@@ -156,25 +148,6 @@ export class AccountModel extends Model<AccountModel> {
156 return AccountModel.findOne(query) 148 return AccountModel.findOne(query)
157 } 149 }
158 150
159 static loadByNameAndHost (name: string, host: string) {
160 const query = {
161 where: {
162 name
163 },
164 include: [
165 {
166 model: ServerModel,
167 required: true,
168 where: {
169 host
170 }
171 }
172 ]
173 }
174
175 return AccountModel.findOne(query)
176 }
177
178 static loadByUrl (url: string, transaction?: Sequelize.Transaction) { 151 static loadByUrl (url: string, transaction?: Sequelize.Transaction) {
179 const query = { 152 const query = {
180 include: [ 153 include: [
@@ -192,29 +165,11 @@ export class AccountModel extends Model<AccountModel> {
192 return AccountModel.findOne(query) 165 return AccountModel.findOne(query)
193 } 166 }
194 167
195 static listByFollowersUrls (followersUrls: string[], transaction?: Sequelize.Transaction) {
196 const query = {
197 include: [
198 {
199 model: ActorModel,
200 required: true,
201 where: {
202 followersUrl: {
203 [ Sequelize.Op.in ]: followersUrls
204 }
205 }
206 }
207 ],
208 transaction
209 }
210
211 return AccountModel.findAll(query)
212 }
213
214 toFormattedJSON () { 168 toFormattedJSON () {
215 const actor = this.Actor.toFormattedJSON() 169 const actor = this.Actor.toFormattedJSON()
216 const account = { 170 const account = {
217 id: this.id, 171 id: this.id,
172 name: this.name,
218 createdAt: this.createdAt, 173 createdAt: this.createdAt,
219 updatedAt: this.updatedAt 174 updatedAt: this.updatedAt
220 } 175 }
@@ -223,7 +178,7 @@ export class AccountModel extends Model<AccountModel> {
223 } 178 }
224 179
225 toActivityPubObject () { 180 toActivityPubObject () {
226 return this.Actor.toActivityPubObject(this.name, this.uuid, 'Account') 181 return this.Actor.toActivityPubObject(this.name, 'Account')
227 } 182 }
228 183
229 isOwned () { 184 isOwned () {