diff options
author | Chocobozzz <me@florianbigard.com> | 2022-06-22 09:44:08 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-06-22 10:25:31 +0200 |
commit | ff9d43f62a4f4737c5bfe955883b48c5440f323a (patch) | |
tree | 60593f4b57ec5cd712986a3db370f39b0b7a4cef /server/models/user | |
parent | 2e401e8575decb1d491d0db48ca1ab1eba5b2a66 (diff) | |
download | PeerTube-ff9d43f62a4f4737c5bfe955883b48c5440f323a.tar.gz PeerTube-ff9d43f62a4f4737c5bfe955883b48c5440f323a.tar.zst PeerTube-ff9d43f62a4f4737c5bfe955883b48c5440f323a.zip |
Refactor video rights checker
Diffstat (limited to 'server/models/user')
-rw-r--r-- | server/models/user/user.ts | 21 |
1 files changed, 2 insertions, 19 deletions
diff --git a/server/models/user/user.ts b/server/models/user/user.ts index a25551ecd..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' |
@@ -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 | } |