aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/audit-logger.ts
diff options
context:
space:
mode:
authorAurélien Bertron <aurelienbertron@gmail.com>2018-07-31 14:04:26 +0200
committerChocobozzz <me@florianbigard.com>2018-07-31 15:40:29 +0200
commit80e36cd9facb56b330be3e4f1c5ba253cc78c308 (patch)
tree807d8a642ae99ec3f05597e19ebe1ca5dc849582 /server/helpers/audit-logger.ts
parent59390818384baa0ffc0cb71af2e67350c6b39172 (diff)
downloadPeerTube-80e36cd9facb56b330be3e4f1c5ba253cc78c308.tar.gz
PeerTube-80e36cd9facb56b330be3e4f1c5ba253cc78c308.tar.zst
PeerTube-80e36cd9facb56b330be3e4f1c5ba253cc78c308.zip
Add audit logs in various modules
- Videos - Videos comments - Users - Videos channels - Videos abuses - Custom config
Diffstat (limited to 'server/helpers/audit-logger.ts')
-rw-r--r--server/helpers/audit-logger.ts138
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'
5import * as winston from 'winston' 5import * as winston from 'winston'
6import { CONFIG } from '../initializers' 6import { CONFIG } from '../initializers'
7import { jsonLoggerFormat, labelFormatter } from './logger' 7import { jsonLoggerFormat, labelFormatter } from './logger'
8import { VideoDetails } from '../../shared' 8import { VideoDetails, User, VideoChannel, VideoAbuse } from '../../shared'
9import { VideoComment } from '../../shared/models/videos/video-comment.model'
10import { CustomConfig } from '../../shared/models/server/custom-config.model'
9 11
10enum AUDIT_TYPE { 12enum AUDIT_TYPE {
11 CREATE = 'create', 13 CREATE = 'create',
@@ -111,13 +113,143 @@ const videoKeysToKeep = [
111 'support', 113 'support',
112 'commentsEnabled' 114 'commentsEnabled'
113] 115]
114class VideoAuditView extends AuditEntity { 116class 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
122const 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]
135class CommentAuditView extends EntityAuditView {
136 constructor (private comment: VideoComment) {
137 super(commentKeysToKeep, 'comment', comment)
138 }
139}
140
141const 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]
164class UserAuditView extends EntityAuditView {
165 constructor (private user: User) {
166 super(userKeysToKeep, 'user', user)
167 }
168}
169
170const 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]
190class VideoChannelAuditView extends EntityAuditView {
191 constructor (private channel: VideoChannel) {
192 super(channelKeysToKeep, 'channel', channel)
193 }
194}
195
196const videoAbuseKeysToKeep = [
197 'id',
198 'reason',
199 'reporterAccount',
200 'video-id',
201 'video-name',
202 'video-uuid',
203 'createdAt'
204]
205class VideoAbuseAuditView extends EntityAuditView {
206 constructor (private videoAbuse: VideoAbuse) {
207 super(videoAbuseKeysToKeep, 'abuse', videoAbuse)
208 }
209}
210
211const 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]
232class 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
120export { 247export {
121 auditLoggerFactory, 248 auditLoggerFactory,
122 VideoAuditView 249 VideoChannelAuditView,
250 CommentAuditView,
251 UserAuditView,
252 VideoAuditView,
253 VideoAbuseAuditView,
254 CustomConfigAuditView
123} 255}