diff options
author | Chocobozzz <me@florianbigard.com> | 2021-11-12 14:19:56 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-11-12 14:23:22 +0100 |
commit | 527a52ac4295a072927ff46761766a8b181a7603 (patch) | |
tree | 632f66b1691d8d72f04630671af8bdf1655d6b00 /server/models/video/video.ts | |
parent | 8f2608e9a9d54c87ace636f99cdb9d2a7730990f (diff) | |
download | PeerTube-527a52ac4295a072927ff46761766a8b181a7603.tar.gz PeerTube-527a52ac4295a072927ff46761766a8b181a7603.tar.zst PeerTube-527a52ac4295a072927ff46761766a8b181a7603.zip |
Add ability to filter out public videos from admin
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r-- | server/models/video/video.ts | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 003741da0..69d009e04 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -1041,6 +1041,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1041 | languageOneOf?: string[] | 1041 | languageOneOf?: string[] |
1042 | tagsOneOf?: string[] | 1042 | tagsOneOf?: string[] |
1043 | tagsAllOf?: string[] | 1043 | tagsAllOf?: string[] |
1044 | privacyOneOf?: VideoPrivacy[] | ||
1044 | 1045 | ||
1045 | accountId?: number | 1046 | accountId?: number |
1046 | videoChannelId?: number | 1047 | videoChannelId?: number |
@@ -1059,6 +1060,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1059 | search?: string | 1060 | search?: string |
1060 | }) { | 1061 | }) { |
1061 | VideoModel.throwIfPrivateIncludeWithoutUser(options.include, options.user) | 1062 | VideoModel.throwIfPrivateIncludeWithoutUser(options.include, options.user) |
1063 | VideoModel.throwIfPrivacyOneOfWithoutUser(options.privacyOneOf, options.user) | ||
1062 | 1064 | ||
1063 | const trendingDays = options.sort.endsWith('trending') | 1065 | const trendingDays = options.sort.endsWith('trending') |
1064 | ? CONFIG.TRENDING.VIDEOS.INTERVAL_DAYS | 1066 | ? CONFIG.TRENDING.VIDEOS.INTERVAL_DAYS |
@@ -1082,6 +1084,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1082 | 'languageOneOf', | 1084 | 'languageOneOf', |
1083 | 'tagsOneOf', | 1085 | 'tagsOneOf', |
1084 | 'tagsAllOf', | 1086 | 'tagsAllOf', |
1087 | 'privacyOneOf', | ||
1085 | 'isLocal', | 1088 | 'isLocal', |
1086 | 'include', | 1089 | 'include', |
1087 | 'displayOnlyForFollower', | 1090 | 'displayOnlyForFollower', |
@@ -1119,6 +1122,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1119 | languageOneOf?: string[] | 1122 | languageOneOf?: string[] |
1120 | tagsOneOf?: string[] | 1123 | tagsOneOf?: string[] |
1121 | tagsAllOf?: string[] | 1124 | tagsAllOf?: string[] |
1125 | privacyOneOf?: VideoPrivacy[] | ||
1122 | 1126 | ||
1123 | displayOnlyForFollower: DisplayOnlyForFollowerOptions | null | 1127 | displayOnlyForFollower: DisplayOnlyForFollowerOptions | null |
1124 | 1128 | ||
@@ -1140,6 +1144,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1140 | uuids?: string[] | 1144 | uuids?: string[] |
1141 | }) { | 1145 | }) { |
1142 | VideoModel.throwIfPrivateIncludeWithoutUser(options.include, options.user) | 1146 | VideoModel.throwIfPrivateIncludeWithoutUser(options.include, options.user) |
1147 | VideoModel.throwIfPrivacyOneOfWithoutUser(options.privacyOneOf, options.user) | ||
1143 | 1148 | ||
1144 | const serverActor = await getServerActor() | 1149 | const serverActor = await getServerActor() |
1145 | 1150 | ||
@@ -1153,6 +1158,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1153 | 'languageOneOf', | 1158 | 'languageOneOf', |
1154 | 'tagsOneOf', | 1159 | 'tagsOneOf', |
1155 | 'tagsAllOf', | 1160 | 'tagsAllOf', |
1161 | 'privacyOneOf', | ||
1156 | 'user', | 1162 | 'user', |
1157 | 'isLocal', | 1163 | 'isLocal', |
1158 | 'host', | 1164 | 'host', |
@@ -1510,14 +1516,19 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1510 | 1516 | ||
1511 | private static throwIfPrivateIncludeWithoutUser (include: VideoInclude, user: MUserAccountId) { | 1517 | private static throwIfPrivateIncludeWithoutUser (include: VideoInclude, user: MUserAccountId) { |
1512 | if (VideoModel.isPrivateInclude(include) && !user?.hasRight(UserRight.SEE_ALL_VIDEOS)) { | 1518 | if (VideoModel.isPrivateInclude(include) && !user?.hasRight(UserRight.SEE_ALL_VIDEOS)) { |
1513 | throw new Error('Try to filter all-local but no user has not the see all videos right') | 1519 | throw new Error('Try to filter all-local but user cannot see all videos') |
1520 | } | ||
1521 | } | ||
1522 | |||
1523 | private static throwIfPrivacyOneOfWithoutUser (privacyOneOf: VideoPrivacy[], user: MUserAccountId) { | ||
1524 | if (privacyOneOf && !user?.hasRight(UserRight.SEE_ALL_VIDEOS)) { | ||
1525 | throw new Error('Try to choose video privacies but user cannot see all videos') | ||
1514 | } | 1526 | } |
1515 | } | 1527 | } |
1516 | 1528 | ||
1517 | private static isPrivateInclude (include: VideoInclude) { | 1529 | private static isPrivateInclude (include: VideoInclude) { |
1518 | return include & VideoInclude.BLACKLISTED || | 1530 | return include & VideoInclude.BLACKLISTED || |
1519 | include & VideoInclude.BLOCKED_OWNER || | 1531 | include & VideoInclude.BLOCKED_OWNER || |
1520 | include & VideoInclude.HIDDEN_PRIVACY || | ||
1521 | include & VideoInclude.NOT_PUBLISHED_STATE | 1532 | include & VideoInclude.NOT_PUBLISHED_STATE |
1522 | } | 1533 | } |
1523 | 1534 | ||