aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
Diffstat (limited to 'shared')
-rw-r--r--shared/models/users/user-notification-setting.model.ts3
-rw-r--r--shared/models/users/user-notification.model.ts24
-rw-r--r--shared/models/users/user-right.enum.ts5
-rw-r--r--shared/models/users/user-role.ts3
-rw-r--r--shared/utils/users/user-notifications.ts113
5 files changed, 140 insertions, 8 deletions
diff --git a/shared/models/users/user-notification-setting.model.ts b/shared/models/users/user-notification-setting.model.ts
index 55d351abf..f580e827e 100644
--- a/shared/models/users/user-notification-setting.model.ts
+++ b/shared/models/users/user-notification-setting.model.ts
@@ -12,4 +12,7 @@ export interface UserNotificationSetting {
12 blacklistOnMyVideo: UserNotificationSettingValue 12 blacklistOnMyVideo: UserNotificationSettingValue
13 myVideoPublished: UserNotificationSettingValue 13 myVideoPublished: UserNotificationSettingValue
14 myVideoImportFinished: UserNotificationSettingValue 14 myVideoImportFinished: UserNotificationSettingValue
15 newUserRegistration: UserNotificationSettingValue
16 newFollow: UserNotificationSettingValue
17 commentMention: UserNotificationSettingValue
15} 18}
diff --git a/shared/models/users/user-notification.model.ts b/shared/models/users/user-notification.model.ts
index ee9ac275a..9dd4f099f 100644
--- a/shared/models/users/user-notification.model.ts
+++ b/shared/models/users/user-notification.model.ts
@@ -6,7 +6,10 @@ export enum UserNotificationType {
6 UNBLACKLIST_ON_MY_VIDEO = 5, 6 UNBLACKLIST_ON_MY_VIDEO = 5,
7 MY_VIDEO_PUBLISHED = 6, 7 MY_VIDEO_PUBLISHED = 6,
8 MY_VIDEO_IMPORT_SUCCESS = 7, 8 MY_VIDEO_IMPORT_SUCCESS = 7,
9 MY_VIDEO_IMPORT_ERROR = 8 9 MY_VIDEO_IMPORT_ERROR = 8,
10 NEW_USER_REGISTRATION = 9,
11 NEW_FOLLOW = 10,
12 COMMENT_MENTION = 11
10} 13}
11 14
12export interface VideoInfo { 15export interface VideoInfo {
@@ -55,6 +58,25 @@ export interface UserNotification {
55 video: VideoInfo 58 video: VideoInfo
56 } 59 }
57 60
61 account?: {
62 id: number
63 displayName: string
64 name: string
65 }
66
67 actorFollow?: {
68 id: number
69 follower: {
70 name: string
71 displayName: string
72 }
73 following: {
74 type: 'account' | 'channel'
75 name: string
76 displayName: string
77 }
78 }
79
58 createdAt: string 80 createdAt: string
59 updatedAt: string 81 updatedAt: string
60} 82}
diff --git a/shared/models/users/user-right.enum.ts b/shared/models/users/user-right.enum.ts
index 51c59d20a..090256bca 100644
--- a/shared/models/users/user-right.enum.ts
+++ b/shared/models/users/user-right.enum.ts
@@ -2,10 +2,15 @@ export enum UserRight {
2 ALL, 2 ALL,
3 3
4 MANAGE_USERS, 4 MANAGE_USERS,
5
5 MANAGE_SERVER_FOLLOW, 6 MANAGE_SERVER_FOLLOW,
7
6 MANAGE_SERVER_REDUNDANCY, 8 MANAGE_SERVER_REDUNDANCY,
9
7 MANAGE_VIDEO_ABUSES, 10 MANAGE_VIDEO_ABUSES,
11
8 MANAGE_JOBS, 12 MANAGE_JOBS,
13
9 MANAGE_CONFIGURATION, 14 MANAGE_CONFIGURATION,
10 15
11 MANAGE_ACCOUNTS_BLOCKLIST, 16 MANAGE_ACCOUNTS_BLOCKLIST,
diff --git a/shared/models/users/user-role.ts b/shared/models/users/user-role.ts
index adef8fd95..59c2ba106 100644
--- a/shared/models/users/user-role.ts
+++ b/shared/models/users/user-role.ts
@@ -29,7 +29,8 @@ const userRoleRights: { [ id: number ]: UserRight[] } = {
29 UserRight.UPDATE_ANY_VIDEO, 29 UserRight.UPDATE_ANY_VIDEO,
30 UserRight.SEE_ALL_VIDEOS, 30 UserRight.SEE_ALL_VIDEOS,
31 UserRight.MANAGE_ACCOUNTS_BLOCKLIST, 31 UserRight.MANAGE_ACCOUNTS_BLOCKLIST,
32 UserRight.MANAGE_SERVERS_BLOCKLIST 32 UserRight.MANAGE_SERVERS_BLOCKLIST,
33 UserRight.MANAGE_USERS
33 ], 34 ],
34 35
35 [UserRole.USER]: [] 36 [UserRole.USER]: []
diff --git a/shared/utils/users/user-notifications.ts b/shared/utils/users/user-notifications.ts
index 75d52023a..1222899e7 100644
--- a/shared/utils/users/user-notifications.ts
+++ b/shared/utils/users/user-notifications.ts
@@ -98,9 +98,11 @@ async function checkNotification (
98 }) 98 })
99 99
100 if (checkType === 'presence') { 100 if (checkType === 'presence') {
101 expect(socketNotification, 'The socket notification is absent. ' + inspect(base.socketNotifications)).to.not.be.undefined 101 const obj = inspect(base.socketNotifications, { depth: 5 })
102 expect(socketNotification, 'The socket notification is absent. ' + obj).to.not.be.undefined
102 } else { 103 } else {
103 expect(socketNotification, 'The socket notification is present. ' + inspect(socketNotification)).to.be.undefined 104 const obj = inspect(socketNotification, { depth: 5 })
105 expect(socketNotification, 'The socket notification is present. ' + obj).to.be.undefined
104 } 106 }
105 } 107 }
106 108
@@ -131,10 +133,9 @@ function checkVideo (video: any, videoName?: string, videoUUID?: string) {
131 expect(video.id).to.be.a('number') 133 expect(video.id).to.be.a('number')
132} 134}
133 135
134function checkActor (channel: any) { 136function checkActor (actor: any) {
135 expect(channel.id).to.be.a('number') 137 expect(actor.displayName).to.be.a('string')
136 expect(channel.displayName).to.be.a('string') 138 expect(actor.displayName).to.not.be.empty
137 expect(channel.displayName).to.not.be.empty
138} 139}
139 140
140function checkComment (comment: any, commentId: number, threadId: number) { 141function checkComment (comment: any, commentId: number, threadId: number) {
@@ -220,6 +221,103 @@ async function checkMyVideoImportIsFinished (
220 await checkNotification(base, notificationChecker, emailFinder, type) 221 await checkNotification(base, notificationChecker, emailFinder, type)
221} 222}
222 223
224async function checkUserRegistered (base: CheckerBaseParams, username: string, type: CheckerType) {
225 const notificationType = UserNotificationType.NEW_USER_REGISTRATION
226
227 function notificationChecker (notification: UserNotification, type: CheckerType) {
228 if (type === 'presence') {
229 expect(notification).to.not.be.undefined
230 expect(notification.type).to.equal(notificationType)
231
232 checkActor(notification.account)
233 expect(notification.account.name).to.equal(username)
234 } else {
235 expect(notification).to.satisfy(n => n.type !== notificationType || n.account.name !== username)
236 }
237 }
238
239 function emailFinder (email: object) {
240 const text: string = email[ 'text' ]
241
242 return text.includes(' registered ') && text.includes(username)
243 }
244
245 await checkNotification(base, notificationChecker, emailFinder, type)
246}
247
248async function checkNewActorFollow (
249 base: CheckerBaseParams,
250 followType: 'channel' | 'account',
251 followerName: string,
252 followerDisplayName: string,
253 followingDisplayName: string,
254 type: CheckerType
255) {
256 const notificationType = UserNotificationType.NEW_FOLLOW
257
258 function notificationChecker (notification: UserNotification, type: CheckerType) {
259 if (type === 'presence') {
260 expect(notification).to.not.be.undefined
261 expect(notification.type).to.equal(notificationType)
262
263 checkActor(notification.actorFollow.follower)
264 expect(notification.actorFollow.follower.displayName).to.equal(followerDisplayName)
265 expect(notification.actorFollow.follower.name).to.equal(followerName)
266
267 checkActor(notification.actorFollow.following)
268 expect(notification.actorFollow.following.displayName).to.equal(followingDisplayName)
269 expect(notification.actorFollow.following.type).to.equal(followType)
270 } else {
271 expect(notification).to.satisfy(n => {
272 return n.type !== notificationType ||
273 (n.actorFollow.follower.name !== followerName && n.actorFollow.following !== followingDisplayName)
274 })
275 }
276 }
277
278 function emailFinder (email: object) {
279 const text: string = email[ 'text' ]
280
281 return text.includes('Your ' + followType) && text.includes(followingDisplayName) && text.includes(followerDisplayName)
282 }
283
284 await checkNotification(base, notificationChecker, emailFinder, type)
285}
286
287async function checkCommentMention (
288 base: CheckerBaseParams,
289 uuid: string,
290 commentId: number,
291 threadId: number,
292 byAccountDisplayName: string,
293 type: CheckerType
294) {
295 const notificationType = UserNotificationType.COMMENT_MENTION
296
297 function notificationChecker (notification: UserNotification, type: CheckerType) {
298 if (type === 'presence') {
299 expect(notification).to.not.be.undefined
300 expect(notification.type).to.equal(notificationType)
301
302 checkComment(notification.comment, commentId, threadId)
303 checkActor(notification.comment.account)
304 expect(notification.comment.account.displayName).to.equal(byAccountDisplayName)
305
306 checkVideo(notification.comment.video, undefined, uuid)
307 } else {
308 expect(notification).to.satisfy(n => n.type !== notificationType || n.comment.id !== commentId)
309 }
310 }
311
312 function emailFinder (email: object) {
313 const text: string = email[ 'text' ]
314
315 return text.includes(' mentioned ') && text.includes(uuid) && text.includes(byAccountDisplayName)
316 }
317
318 await checkNotification(base, notificationChecker, emailFinder, type)
319}
320
223let lastEmailCount = 0 321let lastEmailCount = 0
224async function checkNewCommentOnMyVideo (base: CheckerBaseParams, uuid: string, commentId: number, threadId: number, type: CheckerType) { 322async function checkNewCommentOnMyVideo (base: CheckerBaseParams, uuid: string, commentId: number, threadId: number, type: CheckerType) {
225 const notificationType = UserNotificationType.NEW_COMMENT_ON_MY_VIDEO 323 const notificationType = UserNotificationType.NEW_COMMENT_ON_MY_VIDEO
@@ -312,10 +410,13 @@ export {
312 CheckerType, 410 CheckerType,
313 checkNotification, 411 checkNotification,
314 checkMyVideoImportIsFinished, 412 checkMyVideoImportIsFinished,
413 checkUserRegistered,
315 checkVideoIsPublished, 414 checkVideoIsPublished,
316 checkNewVideoFromSubscription, 415 checkNewVideoFromSubscription,
416 checkNewActorFollow,
317 checkNewCommentOnMyVideo, 417 checkNewCommentOnMyVideo,
318 checkNewBlacklistOnMyVideo, 418 checkNewBlacklistOnMyVideo,
419 checkCommentMention,
319 updateMyNotificationSettings, 420 updateMyNotificationSettings,
320 checkNewVideoAbuseForModerators, 421 checkNewVideoAbuseForModerators,
321 getUserNotifications, 422 getUserNotifications,