aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/user/user.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/user/user.ts')
-rw-r--r--server/models/user/user.ts27
1 files changed, 5 insertions, 22 deletions
diff --git a/server/models/user/user.ts b/server/models/user/user.ts
index 68b2bf523..dc260e512 100644
--- a/server/models/user/user.ts
+++ b/server/models/user/user.ts
@@ -29,12 +29,11 @@ import {
29 MUserDefault, 29 MUserDefault,
30 MUserFormattable, 30 MUserFormattable,
31 MUserNotifSettingChannelDefault, 31 MUserNotifSettingChannelDefault,
32 MUserWithNotificationSetting, 32 MUserWithNotificationSetting
33 MVideoWithRights
34} from '@server/types/models' 33} from '@server/types/models'
35import { AttributesOnly } from '@shared/typescript-utils' 34import { AttributesOnly } from '@shared/typescript-utils'
36import { hasUserRight, USER_ROLE_LABELS } from '../../../shared/core-utils/users' 35import { hasUserRight, USER_ROLE_LABELS } from '../../../shared/core-utils/users'
37import { AbuseState, MyUser, UserRight, VideoPlaylistType, VideoPrivacy } from '../../../shared/models' 36import { AbuseState, MyUser, UserRight, VideoPlaylistType } from '../../../shared/models'
38import { User, UserRole } from '../../../shared/models/users' 37import { User, UserRole } from '../../../shared/models/users'
39import { UserAdminFlag } from '../../../shared/models/users/user-flag.model' 38import { UserAdminFlag } from '../../../shared/models/users/user-flag.model'
40import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type' 39import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type'
@@ -66,7 +65,7 @@ import { ActorModel } from '../actor/actor'
66import { ActorFollowModel } from '../actor/actor-follow' 65import { ActorFollowModel } from '../actor/actor-follow'
67import { ActorImageModel } from '../actor/actor-image' 66import { ActorImageModel } from '../actor/actor-image'
68import { OAuthTokenModel } from '../oauth/oauth-token' 67import { OAuthTokenModel } from '../oauth/oauth-token'
69import { getSort, throwIfNotValid } from '../utils' 68import { getAdminUsersSort, throwIfNotValid } from '../utils'
70import { VideoModel } from '../video/video' 69import { VideoModel } from '../video/video'
71import { VideoChannelModel } from '../video/video-channel' 70import { VideoChannelModel } from '../video/video-channel'
72import { VideoImportModel } from '../video/video-import' 71import { VideoImportModel } from '../video/video-import'
@@ -461,7 +460,7 @@ export class UserModel extends Model<Partial<AttributesOnly<UserModel>>> {
461 return this.count() 460 return this.count()
462 } 461 }
463 462
464 static listForApi (parameters: { 463 static listForAdminApi (parameters: {
465 start: number 464 start: number
466 count: number 465 count: number
467 sort: string 466 sort: string
@@ -497,7 +496,7 @@ export class UserModel extends Model<Partial<AttributesOnly<UserModel>>> {
497 const query: FindOptions = { 496 const query: FindOptions = {
498 offset: start, 497 offset: start,
499 limit: count, 498 limit: count,
500 order: getSort(sort), 499 order: getAdminUsersSort(sort),
501 where 500 where
502 } 501 }
503 502
@@ -851,22 +850,6 @@ export class UserModel extends Model<Partial<AttributesOnly<UserModel>>> {
851 .then(u => u.map(u => u.username)) 850 .then(u => u.map(u => u.username))
852 } 851 }
853 852
854 canGetVideo (video: MVideoWithRights) {
855 const videoUserId = video.VideoChannel.Account.userId
856
857 if (video.isBlacklisted()) {
858 return videoUserId === this.id || this.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST)
859 }
860
861 if (video.privacy === VideoPrivacy.PRIVATE) {
862 return video.VideoChannel && videoUserId === this.id || this.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST)
863 }
864
865 if (video.privacy === VideoPrivacy.INTERNAL) return true
866
867 return false
868 }
869
870 hasRight (right: UserRight) { 853 hasRight (right: UserRight) {
871 return hasUserRight(this.role, right) 854 return hasUserRight(this.role, right)
872 } 855 }