diff options
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/audit-logger.ts | 138 |
1 files changed, 135 insertions, 3 deletions
diff --git a/server/helpers/audit-logger.ts b/server/helpers/audit-logger.ts index 4b237316f..f6eea7d90 100644 --- a/server/helpers/audit-logger.ts +++ b/server/helpers/audit-logger.ts | |||
@@ -5,7 +5,9 @@ import * as flatten from 'flat' | |||
5 | import * as winston from 'winston' | 5 | import * as winston from 'winston' |
6 | import { CONFIG } from '../initializers' | 6 | import { CONFIG } from '../initializers' |
7 | import { jsonLoggerFormat, labelFormatter } from './logger' | 7 | import { jsonLoggerFormat, labelFormatter } from './logger' |
8 | import { VideoDetails } from '../../shared' | 8 | import { VideoDetails, User, VideoChannel, VideoAbuse } from '../../shared' |
9 | import { VideoComment } from '../../shared/models/videos/video-comment.model' | ||
10 | import { CustomConfig } from '../../shared/models/server/custom-config.model' | ||
9 | 11 | ||
10 | enum AUDIT_TYPE { | 12 | enum AUDIT_TYPE { |
11 | CREATE = 'create', | 13 | CREATE = 'create', |
@@ -111,13 +113,143 @@ const videoKeysToKeep = [ | |||
111 | 'support', | 113 | 'support', |
112 | 'commentsEnabled' | 114 | 'commentsEnabled' |
113 | ] | 115 | ] |
114 | class VideoAuditView extends AuditEntity { | 116 | class VideoAuditView extends EntityAuditView { |
115 | constructor (private video: VideoDetails) { | 117 | constructor (private video: VideoDetails) { |
116 | super(videoKeysToKeep, 'video', video) | 118 | super(videoKeysToKeep, 'video', video) |
117 | } | 119 | } |
118 | } | 120 | } |
119 | 121 | ||
122 | const commentKeysToKeep = [ | ||
123 | 'id', | ||
124 | 'text', | ||
125 | 'threadId', | ||
126 | 'inReplyToCommentId', | ||
127 | 'videoId', | ||
128 | 'createdAt', | ||
129 | 'updatedAt', | ||
130 | 'totalReplies', | ||
131 | 'account-id', | ||
132 | 'account-uuid', | ||
133 | 'account-name' | ||
134 | ] | ||
135 | class CommentAuditView extends EntityAuditView { | ||
136 | constructor (private comment: VideoComment) { | ||
137 | super(commentKeysToKeep, 'comment', comment) | ||
138 | } | ||
139 | } | ||
140 | |||
141 | const userKeysToKeep = [ | ||
142 | 'id', | ||
143 | 'username', | ||
144 | 'email', | ||
145 | 'nsfwPolicy', | ||
146 | 'autoPlayVideo', | ||
147 | 'role', | ||
148 | 'videoQuota', | ||
149 | 'createdAt', | ||
150 | 'account-id', | ||
151 | 'account-uuid', | ||
152 | 'account-name', | ||
153 | 'account-followingCount', | ||
154 | 'account-followersCount', | ||
155 | 'account-createdAt', | ||
156 | 'account-updatedAt', | ||
157 | 'account-avatar-path', | ||
158 | 'account-avatar-createdAt', | ||
159 | 'account-avatar-updatedAt', | ||
160 | 'account-displayName', | ||
161 | 'account-description', | ||
162 | 'videoChannels' | ||
163 | ] | ||
164 | class UserAuditView extends EntityAuditView { | ||
165 | constructor (private user: User) { | ||
166 | super(userKeysToKeep, 'user', user) | ||
167 | } | ||
168 | } | ||
169 | |||
170 | const channelKeysToKeep = [ | ||
171 | 'id', | ||
172 | 'uuid', | ||
173 | 'name', | ||
174 | 'followingCount', | ||
175 | 'followersCount', | ||
176 | 'createdAt', | ||
177 | 'updatedAt', | ||
178 | 'avatar-path', | ||
179 | 'avatar-createdAt', | ||
180 | 'avatar-updatedAt', | ||
181 | 'displayName', | ||
182 | 'description', | ||
183 | 'support', | ||
184 | 'isLocal', | ||
185 | 'ownerAccount-id', | ||
186 | 'ownerAccount-uuid', | ||
187 | 'ownerAccount-name', | ||
188 | 'ownerAccount-displayedName' | ||
189 | ] | ||
190 | class VideoChannelAuditView extends EntityAuditView { | ||
191 | constructor (private channel: VideoChannel) { | ||
192 | super(channelKeysToKeep, 'channel', channel) | ||
193 | } | ||
194 | } | ||
195 | |||
196 | const videoAbuseKeysToKeep = [ | ||
197 | 'id', | ||
198 | 'reason', | ||
199 | 'reporterAccount', | ||
200 | 'video-id', | ||
201 | 'video-name', | ||
202 | 'video-uuid', | ||
203 | 'createdAt' | ||
204 | ] | ||
205 | class VideoAbuseAuditView extends EntityAuditView { | ||
206 | constructor (private videoAbuse: VideoAbuse) { | ||
207 | super(videoAbuseKeysToKeep, 'abuse', videoAbuse) | ||
208 | } | ||
209 | } | ||
210 | |||
211 | const customConfigKeysToKeep = [ | ||
212 | 'instance-name', | ||
213 | 'instance-shortDescription', | ||
214 | 'instance-description', | ||
215 | 'instance-terms', | ||
216 | 'instance-defaultClientRoute', | ||
217 | 'instance-defaultNSFWPolicy', | ||
218 | 'instance-customizations-javascript', | ||
219 | 'instance-customizations-css', | ||
220 | 'services-twitter-username', | ||
221 | 'services-twitter-whitelisted', | ||
222 | 'cache-previews-size', | ||
223 | 'cache-captions-size', | ||
224 | 'signup-enabled', | ||
225 | 'signup-limit', | ||
226 | 'admin-email', | ||
227 | 'user-videoQuota', | ||
228 | 'transcoding-enabled', | ||
229 | 'transcoding-threads', | ||
230 | 'transcoding-resolutions' | ||
231 | ] | ||
232 | class CustomConfigAuditView extends EntityAuditView { | ||
233 | constructor (customConfig: CustomConfig) { | ||
234 | const infos: any = customConfig | ||
235 | const resolutionsDict = infos.transcoding.resolutions | ||
236 | const resolutionsArray = [] | ||
237 | Object.entries(resolutionsDict).forEach(([resolution, isEnabled]) => { | ||
238 | if (isEnabled) { | ||
239 | resolutionsArray.push(resolution) | ||
240 | } | ||
241 | }) | ||
242 | infos.transcoding.resolutions = resolutionsArray | ||
243 | super(customConfigKeysToKeep, 'config', infos) | ||
244 | } | ||
245 | } | ||
246 | |||
120 | export { | 247 | export { |
121 | auditLoggerFactory, | 248 | auditLoggerFactory, |
122 | VideoAuditView | 249 | VideoChannelAuditView, |
250 | CommentAuditView, | ||
251 | UserAuditView, | ||
252 | VideoAuditView, | ||
253 | VideoAbuseAuditView, | ||
254 | CustomConfigAuditView | ||
123 | } | 255 | } |