aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/account/user-notification-setting.ts10
-rw-r--r--server/models/video/schedule-video-update.ts3
-rw-r--r--server/models/video/video-blacklist.ts56
3 files changed, 49 insertions, 20 deletions
diff --git a/server/models/account/user-notification-setting.ts b/server/models/account/user-notification-setting.ts
index f1c3ac223..ba7f739b9 100644
--- a/server/models/account/user-notification-setting.ts
+++ b/server/models/account/user-notification-setting.ts
@@ -59,6 +59,15 @@ export class UserNotificationSettingModel extends Model<UserNotificationSettingM
59 @AllowNull(false) 59 @AllowNull(false)
60 @Default(null) 60 @Default(null)
61 @Is( 61 @Is(
62 'UserNotificationSettingVideoAutoBlacklistAsModerator',
63 value => throwIfNotValid(value, isUserNotificationSettingValid, 'videoAutoBlacklistAsModerator')
64 )
65 @Column
66 videoAutoBlacklistAsModerator: UserNotificationSettingValue
67
68 @AllowNull(false)
69 @Default(null)
70 @Is(
62 'UserNotificationSettingBlacklistOnMyVideo', 71 'UserNotificationSettingBlacklistOnMyVideo',
63 value => throwIfNotValid(value, isUserNotificationSettingValid, 'blacklistOnMyVideo') 72 value => throwIfNotValid(value, isUserNotificationSettingValid, 'blacklistOnMyVideo')
64 ) 73 )
@@ -139,6 +148,7 @@ export class UserNotificationSettingModel extends Model<UserNotificationSettingM
139 newCommentOnMyVideo: this.newCommentOnMyVideo, 148 newCommentOnMyVideo: this.newCommentOnMyVideo,
140 newVideoFromSubscription: this.newVideoFromSubscription, 149 newVideoFromSubscription: this.newVideoFromSubscription,
141 videoAbuseAsModerator: this.videoAbuseAsModerator, 150 videoAbuseAsModerator: this.videoAbuseAsModerator,
151 videoAutoBlacklistAsModerator: this.videoAutoBlacklistAsModerator,
142 blacklistOnMyVideo: this.blacklistOnMyVideo, 152 blacklistOnMyVideo: this.blacklistOnMyVideo,
143 myVideoPublished: this.myVideoPublished, 153 myVideoPublished: this.myVideoPublished,
144 myVideoImportFinished: this.myVideoImportFinished, 154 myVideoImportFinished: this.myVideoImportFinished,
diff --git a/server/models/video/schedule-video-update.ts b/server/models/video/schedule-video-update.ts
index 1e56562e1..abddc1111 100644
--- a/server/models/video/schedule-video-update.ts
+++ b/server/models/video/schedule-video-update.ts
@@ -72,7 +72,8 @@ export class ScheduleVideoUpdateModel extends Model<ScheduleVideoUpdateModel> {
72 model: VideoModel.scope( 72 model: VideoModel.scope(
73 [ 73 [
74 VideoScopeNames.WITH_FILES, 74 VideoScopeNames.WITH_FILES,
75 VideoScopeNames.WITH_ACCOUNT_DETAILS 75 VideoScopeNames.WITH_ACCOUNT_DETAILS,
76 VideoScopeNames.WITH_BLACKLISTED
76 ] 77 ]
77 ) 78 )
78 } 79 }
diff --git a/server/models/video/video-blacklist.ts b/server/models/video/video-blacklist.ts
index 3b567e488..86b1f6acb 100644
--- a/server/models/video/video-blacklist.ts
+++ b/server/models/video/video-blacklist.ts
@@ -1,8 +1,21 @@
1import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' 1import {
2 AllowNull,
3 BelongsTo,
4 Column,
5 CreatedAt,
6 DataType,
7 Default,
8 ForeignKey,
9 Is, Model,
10 Table,
11 UpdatedAt,
12 IFindOptions
13} from 'sequelize-typescript'
2import { getSortOnModel, SortType, throwIfNotValid } from '../utils' 14import { getSortOnModel, SortType, throwIfNotValid } from '../utils'
3import { VideoModel } from './video' 15import { VideoModel } from './video'
4import { isVideoBlacklistReasonValid } from '../../helpers/custom-validators/video-blacklist' 16import { VideoChannelModel, ScopeNames as VideoChannelScopeNames } from './video-channel'
5import { VideoBlacklist } from '../../../shared/models/videos' 17import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../helpers/custom-validators/video-blacklist'
18import { VideoBlacklist, VideoBlacklistType } from '../../../shared/models/videos'
6import { CONSTRAINTS_FIELDS } from '../../initializers' 19import { CONSTRAINTS_FIELDS } from '../../initializers'
7 20
8@Table({ 21@Table({
@@ -25,6 +38,12 @@ export class VideoBlacklistModel extends Model<VideoBlacklistModel> {
25 @Column 38 @Column
26 unfederated: boolean 39 unfederated: boolean
27 40
41 @AllowNull(false)
42 @Default(null)
43 @Is('VideoBlacklistType', value => throwIfNotValid(value, isVideoBlacklistTypeValid, 'type'))
44 @Column
45 type: VideoBlacklistType
46
28 @CreatedAt 47 @CreatedAt
29 createdAt: Date 48 createdAt: Date
30 49
@@ -43,19 +62,29 @@ export class VideoBlacklistModel extends Model<VideoBlacklistModel> {
43 }) 62 })
44 Video: VideoModel 63 Video: VideoModel
45 64
46 static listForApi (start: number, count: number, sort: SortType) { 65 static listForApi (start: number, count: number, sort: SortType, type?: VideoBlacklistType) {
47 const query = { 66 const query: IFindOptions<VideoBlacklistModel> = {
48 offset: start, 67 offset: start,
49 limit: count, 68 limit: count,
50 order: getSortOnModel(sort.sortModel, sort.sortValue), 69 order: getSortOnModel(sort.sortModel, sort.sortValue),
51 include: [ 70 include: [
52 { 71 {
53 model: VideoModel, 72 model: VideoModel,
54 required: true 73 required: true,
74 include: [
75 {
76 model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, true ] }),
77 required: true
78 }
79 ]
55 } 80 }
56 ] 81 ]
57 } 82 }
58 83
84 if (type) {
85 query.where = { type }
86 }
87
59 return VideoBlacklistModel.findAndCountAll(query) 88 return VideoBlacklistModel.findAndCountAll(query)
60 .then(({ rows, count }) => { 89 .then(({ rows, count }) => {
61 return { 90 return {
@@ -76,26 +105,15 @@ export class VideoBlacklistModel extends Model<VideoBlacklistModel> {
76 } 105 }
77 106
78 toFormattedJSON (): VideoBlacklist { 107 toFormattedJSON (): VideoBlacklist {
79 const video = this.Video
80
81 return { 108 return {
82 id: this.id, 109 id: this.id,
83 createdAt: this.createdAt, 110 createdAt: this.createdAt,
84 updatedAt: this.updatedAt, 111 updatedAt: this.updatedAt,
85 reason: this.reason, 112 reason: this.reason,
86 unfederated: this.unfederated, 113 unfederated: this.unfederated,
114 type: this.type,
87 115
88 video: { 116 video: this.Video.toFormattedJSON()
89 id: video.id,
90 name: video.name,
91 uuid: video.uuid,
92 description: video.description,
93 duration: video.duration,
94 views: video.views,
95 likes: video.likes,
96 dislikes: video.dislikes,
97 nsfw: video.nsfw
98 }
99 } 117 }
100 } 118 }
101} 119}