aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/video/sql/videos-id-list-query-builder.ts18
-rw-r--r--server/models/video/video.ts15
2 files changed, 26 insertions, 7 deletions
diff --git a/server/models/video/sql/videos-id-list-query-builder.ts b/server/models/video/sql/videos-id-list-query-builder.ts
index 4a882e790..d825225ab 100644
--- a/server/models/video/sql/videos-id-list-query-builder.ts
+++ b/server/models/video/sql/videos-id-list-query-builder.ts
@@ -40,6 +40,7 @@ export type BuildVideosListQueryOptions = {
40 languageOneOf?: string[] 40 languageOneOf?: string[]
41 tagsOneOf?: string[] 41 tagsOneOf?: string[]
42 tagsAllOf?: string[] 42 tagsAllOf?: string[]
43 privacyOneOf?: VideoPrivacy[]
43 44
44 uuids?: string[] 45 uuids?: string[]
45 46
@@ -138,11 +139,6 @@ export class VideosIdListQueryBuilder extends AbstractRunQuery {
138 this.whereStateAvailable() 139 this.whereStateAvailable()
139 } 140 }
140 141
141 // Only list videos with the appropriate priavcy
142 if (!(options.include & VideoInclude.HIDDEN_PRIVACY)) {
143 this.wherePrivacyAvailable(options.user)
144 }
145
146 if (options.videoPlaylistId) { 142 if (options.videoPlaylistId) {
147 this.joinPlaylist(options.videoPlaylistId) 143 this.joinPlaylist(options.videoPlaylistId)
148 } 144 }
@@ -187,6 +183,13 @@ export class VideosIdListQueryBuilder extends AbstractRunQuery {
187 this.whereTagsAllOf(options.tagsAllOf) 183 this.whereTagsAllOf(options.tagsAllOf)
188 } 184 }
189 185
186 if (options.privacyOneOf) {
187 this.wherePrivacyOneOf(options.privacyOneOf)
188 } else {
189 // Only list videos with the appropriate priavcy
190 this.wherePrivacyAvailable(options.user)
191 }
192
190 if (options.uuids) { 193 if (options.uuids) {
191 this.whereUUIDs(options.uuids) 194 this.whereUUIDs(options.uuids)
192 } 195 }
@@ -435,6 +438,11 @@ export class VideosIdListQueryBuilder extends AbstractRunQuery {
435 ) 438 )
436 } 439 }
437 440
441 private wherePrivacyOneOf (privacyOneOf: VideoPrivacy[]) {
442 this.and.push('"video"."privacy" IN (:privacyOneOf)')
443 this.replacements.privacyOneOf = privacyOneOf
444 }
445
438 private whereUUIDs (uuids: string[]) { 446 private whereUUIDs (uuids: string[]) {
439 this.and.push('"video"."uuid" IN (' + createSafeIn(this.sequelize, uuids) + ')') 447 this.and.push('"video"."uuid" IN (' + createSafeIn(this.sequelize, uuids) + ')')
440 } 448 }
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