diff options
Diffstat (limited to 'server/models/user/user.ts')
-rw-r--r-- | server/models/user/user.ts | 27 |
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' |
35 | import { AttributesOnly } from '@shared/typescript-utils' | 34 | import { AttributesOnly } from '@shared/typescript-utils' |
36 | import { hasUserRight, USER_ROLE_LABELS } from '../../../shared/core-utils/users' | 35 | import { hasUserRight, USER_ROLE_LABELS } from '../../../shared/core-utils/users' |
37 | import { AbuseState, MyUser, UserRight, VideoPlaylistType, VideoPrivacy } from '../../../shared/models' | 36 | import { AbuseState, MyUser, UserRight, VideoPlaylistType } from '../../../shared/models' |
38 | import { User, UserRole } from '../../../shared/models/users' | 37 | import { User, UserRole } from '../../../shared/models/users' |
39 | import { UserAdminFlag } from '../../../shared/models/users/user-flag.model' | 38 | import { UserAdminFlag } from '../../../shared/models/users/user-flag.model' |
40 | import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type' | 39 | import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type' |
@@ -66,7 +65,7 @@ import { ActorModel } from '../actor/actor' | |||
66 | import { ActorFollowModel } from '../actor/actor-follow' | 65 | import { ActorFollowModel } from '../actor/actor-follow' |
67 | import { ActorImageModel } from '../actor/actor-image' | 66 | import { ActorImageModel } from '../actor/actor-image' |
68 | import { OAuthTokenModel } from '../oauth/oauth-token' | 67 | import { OAuthTokenModel } from '../oauth/oauth-token' |
69 | import { getSort, throwIfNotValid } from '../utils' | 68 | import { getAdminUsersSort, throwIfNotValid } from '../utils' |
70 | import { VideoModel } from '../video/video' | 69 | import { VideoModel } from '../video/video' |
71 | import { VideoChannelModel } from '../video/video-channel' | 70 | import { VideoChannelModel } from '../video/video-channel' |
72 | import { VideoImportModel } from '../video/video-import' | 71 | import { 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 | } |