aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/account/user.ts32
-rw-r--r--server/models/video/video-change-ownership.ts12
-rw-r--r--server/models/video/video-channel.ts16
3 files changed, 36 insertions, 24 deletions
diff --git a/server/models/account/user.ts b/server/models/account/user.ts
index 4b13e47a0..680b1d52d 100644
--- a/server/models/account/user.ts
+++ b/server/models/account/user.ts
@@ -23,13 +23,13 @@ import {
23 isUserAutoPlayVideoValid, 23 isUserAutoPlayVideoValid,
24 isUserBlockedReasonValid, 24 isUserBlockedReasonValid,
25 isUserBlockedValid, 25 isUserBlockedValid,
26 isUserNSFWPolicyValid,
27 isUserEmailVerifiedValid, 26 isUserEmailVerifiedValid,
27 isUserNSFWPolicyValid,
28 isUserPasswordValid, 28 isUserPasswordValid,
29 isUserRoleValid, 29 isUserRoleValid,
30 isUserUsernameValid, 30 isUserUsernameValid,
31 isUserVideoQuotaValid, 31 isUserVideoQuotaDailyValid,
32 isUserVideoQuotaDailyValid 32 isUserVideoQuotaValid
33} from '../../helpers/custom-validators/users' 33} from '../../helpers/custom-validators/users'
34import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto' 34import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto'
35import { OAuthTokenModel } from '../oauth/oauth-token' 35import { OAuthTokenModel } from '../oauth/oauth-token'
@@ -39,7 +39,6 @@ import { AccountModel } from './account'
39import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type' 39import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type'
40import { values } from 'lodash' 40import { values } from 'lodash'
41import { NSFW_POLICY_TYPES } from '../../initializers' 41import { NSFW_POLICY_TYPES } from '../../initializers'
42import { VideoFileModel } from '../video/video-file'
43 42
44enum ScopeNames { 43enum ScopeNames {
45 WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL' 44 WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL'
@@ -296,6 +295,20 @@ export class UserModel extends Model<UserModel> {
296 } 295 }
297 } 296 }
298 297
298 static autoComplete (search: string) {
299 const query = {
300 where: {
301 username: {
302 [ Sequelize.Op.like ]: `%${search}%`
303 }
304 },
305 limit: 10
306 }
307
308 return UserModel.findAll(query)
309 .then(u => u.map(u => u.username))
310 }
311
299 hasRight (right: UserRight) { 312 hasRight (right: UserRight) {
300 return hasUserRight(this.role, right) 313 return hasUserRight(this.role, right)
301 } 314 }
@@ -394,15 +407,4 @@ export class UserModel extends Model<UserModel> {
394 return parseInt(total, 10) 407 return parseInt(total, 10)
395 }) 408 })
396 } 409 }
397
398 static autocomplete (search: string) {
399 return UserModel.findAll({
400 where: {
401 username: {
402 [Sequelize.Op.like]: `%${search}%`
403 }
404 }
405 })
406 .then(u => u.map(u => u.username))
407 }
408} 410}
diff --git a/server/models/video/video-change-ownership.ts b/server/models/video/video-change-ownership.ts
index c9cff5054..48c07728f 100644
--- a/server/models/video/video-change-ownership.ts
+++ b/server/models/video/video-change-ownership.ts
@@ -39,7 +39,9 @@ enum ScopeNames {
39 { 39 {
40 model: () => VideoModel, 40 model: () => VideoModel,
41 required: true, 41 required: true,
42 include: [{ model: () => VideoFileModel }] 42 include: [
43 { model: () => VideoFileModel }
44 ]
43 } 45 }
44 ] 46 ]
45 } 47 }
@@ -94,15 +96,17 @@ export class VideoChangeOwnershipModel extends Model<VideoChangeOwnershipModel>
94 Video: VideoModel 96 Video: VideoModel
95 97
96 static listForApi (nextOwnerId: number, start: number, count: number, sort: string) { 98 static listForApi (nextOwnerId: number, start: number, count: number, sort: string) {
97 return VideoChangeOwnershipModel.scope(ScopeNames.FULL).findAndCountAll({ 99 const query = {
98 offset: start, 100 offset: start,
99 limit: count, 101 limit: count,
100 order: getSort(sort), 102 order: getSort(sort),
101 where: { 103 where: {
102 nextOwnerAccountId: nextOwnerId 104 nextOwnerAccountId: nextOwnerId
103 } 105 }
104 }) 106 }
105 .then(({ rows, count }) => ({ total: count, data: rows })) 107
108 return VideoChangeOwnershipModel.scope(ScopeNames.FULL).findAndCountAll(query)
109 .then(({ rows, count }) => ({ total: count, data: rows }))
106 } 110 }
107 111
108 static load (id: number) { 112 static load (id: number) {
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts
index 475530daf..f4586917e 100644
--- a/server/models/video/video-channel.ts
+++ b/server/models/video/video-channel.ts
@@ -296,6 +296,12 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
296 }) 296 })
297 } 297 }
298 298
299 static loadByIdAndPopulateAccount (id: number) {
300 return VideoChannelModel.unscoped()
301 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ])
302 .findById(id)
303 }
304
299 static loadByIdAndAccount (id: number, accountId: number) { 305 static loadByIdAndAccount (id: number, accountId: number) {
300 const query = { 306 const query = {
301 where: { 307 where: {
@@ -304,13 +310,13 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
304 } 310 }
305 } 311 }
306 312
307 return VideoChannelModel 313 return VideoChannelModel.unscoped()
308 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) 314 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ])
309 .findOne(query) 315 .findOne(query)
310 } 316 }
311 317
312 static loadAndPopulateAccount (id: number) { 318 static loadAndPopulateAccount (id: number) {
313 return VideoChannelModel 319 return VideoChannelModel.unscoped()
314 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) 320 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ])
315 .findById(id) 321 .findById(id)
316 } 322 }
@@ -365,7 +371,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
365 ] 371 ]
366 } 372 }
367 373
368 return VideoChannelModel 374 return VideoChannelModel.unscoped()
369 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) 375 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ])
370 .findOne(query) 376 .findOne(query)
371 } 377 }
@@ -390,7 +396,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
390 ] 396 ]
391 } 397 }
392 398
393 return VideoChannelModel 399 return VideoChannelModel.unscoped()
394 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) 400 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ])
395 .findOne(query) 401 .findOne(query)
396 } 402 }
@@ -402,7 +408,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
402 ] 408 ]
403 } 409 }
404 410
405 return VideoChannelModel 411 return VideoChannelModel.unscoped()
406 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_VIDEOS ]) 412 .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_VIDEOS ])
407 .findById(id, options) 413 .findById(id, options)
408 } 414 }