diff options
author | Chocobozzz <me@florianbigard.com> | 2021-03-11 16:54:52 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-03-24 18:18:41 +0100 |
commit | 32a18cbf33a7cdbbe3d4885d32e4b67e19cdc1cf (patch) | |
tree | 1db53245688a6b7839cab00f9d65e6c1c1774b00 /shared | |
parent | 3fbc6974334ca58c068f0f9def0b0a40db2a6de1 (diff) | |
download | PeerTube-32a18cbf33a7cdbbe3d4885d32e4b67e19cdc1cf.tar.gz PeerTube-32a18cbf33a7cdbbe3d4885d32e4b67e19cdc1cf.tar.zst PeerTube-32a18cbf33a7cdbbe3d4885d32e4b67e19cdc1cf.zip |
Add new plugin/peertube version notifs
Diffstat (limited to 'shared')
-rw-r--r-- | shared/extra-utils/index.ts | 2 | ||||
-rw-r--r-- | shared/extra-utils/miscs/sql.ts | 13 | ||||
-rw-r--r-- | shared/extra-utils/mock-servers/joinpeertube-versions.ts | 31 | ||||
-rw-r--r-- | shared/extra-utils/mock-servers/mock-instances-index.ts (renamed from shared/extra-utils/instances-index/mock-instances-index.ts) | 0 | ||||
-rw-r--r-- | shared/extra-utils/users/user-notifications.ts | 72 | ||||
-rw-r--r-- | shared/models/index.ts | 1 | ||||
-rw-r--r-- | shared/models/joinpeertube/index.ts | 1 | ||||
-rw-r--r-- | shared/models/joinpeertube/versions.model.ts | 5 | ||||
-rw-r--r-- | shared/models/users/user-notification-setting.model.ts | 3 | ||||
-rw-r--r-- | shared/models/users/user-notification.model.ts | 16 |
10 files changed, 132 insertions, 12 deletions
diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts index 5c95a1b3e..898a92d43 100644 --- a/shared/extra-utils/index.ts +++ b/shared/extra-utils/index.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | export * from './bulk/bulk' | 1 | export * from './bulk/bulk' |
2 | export * from './cli/cli' | 2 | export * from './cli/cli' |
3 | export * from './feeds/feeds' | 3 | export * from './feeds/feeds' |
4 | export * from './instances-index/mock-instances-index' | 4 | export * from './mock-servers/mock-instances-index' |
5 | export * from './miscs/miscs' | 5 | export * from './miscs/miscs' |
6 | export * from './miscs/sql' | 6 | export * from './miscs/sql' |
7 | export * from './miscs/stubs' | 7 | export * from './miscs/stubs' |
diff --git a/shared/extra-utils/miscs/sql.ts b/shared/extra-utils/miscs/sql.ts index 740f0c2d6..345e5bc16 100644 --- a/shared/extra-utils/miscs/sql.ts +++ b/shared/extra-utils/miscs/sql.ts | |||
@@ -106,12 +106,20 @@ async function closeAllSequelize (servers: ServerInfo[]) { | |||
106 | } | 106 | } |
107 | } | 107 | } |
108 | 108 | ||
109 | function setPluginVersion (internalServerNumber: number, pluginName: string, newVersion: string) { | 109 | function setPluginField (internalServerNumber: number, pluginName: string, field: string, value: string) { |
110 | const seq = getSequelize(internalServerNumber) | 110 | const seq = getSequelize(internalServerNumber) |
111 | 111 | ||
112 | const options = { type: QueryTypes.UPDATE } | 112 | const options = { type: QueryTypes.UPDATE } |
113 | 113 | ||
114 | return seq.query(`UPDATE "plugin" SET "version" = '${newVersion}' WHERE "name" = '${pluginName}'`, options) | 114 | return seq.query(`UPDATE "plugin" SET "${field}" = '${value}' WHERE "name" = '${pluginName}'`, options) |
115 | } | ||
116 | |||
117 | function setPluginVersion (internalServerNumber: number, pluginName: string, newVersion: string) { | ||
118 | return setPluginField(internalServerNumber, pluginName, 'version', newVersion) | ||
119 | } | ||
120 | |||
121 | function setPluginLatestVersion (internalServerNumber: number, pluginName: string, newVersion: string) { | ||
122 | return setPluginField(internalServerNumber, pluginName, 'latestVersion', newVersion) | ||
115 | } | 123 | } |
116 | 124 | ||
117 | function setActorFollowScores (internalServerNumber: number, newScore: number) { | 125 | function setActorFollowScores (internalServerNumber: number, newScore: number) { |
@@ -128,6 +136,7 @@ export { | |||
128 | setActorField, | 136 | setActorField, |
129 | countVideoViewsOf, | 137 | countVideoViewsOf, |
130 | setPluginVersion, | 138 | setPluginVersion, |
139 | setPluginLatestVersion, | ||
131 | selectQuery, | 140 | selectQuery, |
132 | deleteAll, | 141 | deleteAll, |
133 | updateQuery, | 142 | updateQuery, |
diff --git a/shared/extra-utils/mock-servers/joinpeertube-versions.ts b/shared/extra-utils/mock-servers/joinpeertube-versions.ts new file mode 100644 index 000000000..d7d5b2c49 --- /dev/null +++ b/shared/extra-utils/mock-servers/joinpeertube-versions.ts | |||
@@ -0,0 +1,31 @@ | |||
1 | import * as express from 'express' | ||
2 | |||
3 | export class MockJoinPeerTubeVersions { | ||
4 | private latestVersion: string | ||
5 | |||
6 | initialize () { | ||
7 | return new Promise<void>(res => { | ||
8 | const app = express() | ||
9 | |||
10 | app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
11 | if (process.env.DEBUG) console.log('Receiving request on mocked server %s.', req.url) | ||
12 | |||
13 | return next() | ||
14 | }) | ||
15 | |||
16 | app.get('/versions.json', (req: express.Request, res: express.Response) => { | ||
17 | return res.json({ | ||
18 | peertube: { | ||
19 | latestVersion: this.latestVersion | ||
20 | } | ||
21 | }) | ||
22 | }) | ||
23 | |||
24 | app.listen(42102, () => res()) | ||
25 | }) | ||
26 | } | ||
27 | |||
28 | setLatestVersion (latestVersion: string) { | ||
29 | this.latestVersion = latestVersion | ||
30 | } | ||
31 | } | ||
diff --git a/shared/extra-utils/instances-index/mock-instances-index.ts b/shared/extra-utils/mock-servers/mock-instances-index.ts index 2604eda03..2604eda03 100644 --- a/shared/extra-utils/instances-index/mock-instances-index.ts +++ b/shared/extra-utils/mock-servers/mock-instances-index.ts | |||
diff --git a/shared/extra-utils/users/user-notifications.ts b/shared/extra-utils/users/user-notifications.ts index 467a3d959..249e82925 100644 --- a/shared/extra-utils/users/user-notifications.ts +++ b/shared/extra-utils/users/user-notifications.ts | |||
@@ -2,7 +2,8 @@ | |||
2 | 2 | ||
3 | import { expect } from 'chai' | 3 | import { expect } from 'chai' |
4 | import { inspect } from 'util' | 4 | import { inspect } from 'util' |
5 | import { AbuseState } from '@shared/models' | 5 | import { AbuseState, PluginType } from '@shared/models' |
6 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
6 | import { UserNotification, UserNotificationSetting, UserNotificationSettingValue, UserNotificationType } from '../../models/users' | 7 | import { UserNotification, UserNotificationSetting, UserNotificationSettingValue, UserNotificationType } from '../../models/users' |
7 | import { MockSmtpServer } from '../miscs/email' | 8 | import { MockSmtpServer } from '../miscs/email' |
8 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' | 9 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' |
@@ -11,7 +12,6 @@ import { flushAndRunMultipleServers, ServerInfo } from '../server/servers' | |||
11 | import { getUserNotificationSocket } from '../socket/socket-io' | 12 | import { getUserNotificationSocket } from '../socket/socket-io' |
12 | import { setAccessTokensToServers, userLogin } from './login' | 13 | import { setAccessTokensToServers, userLogin } from './login' |
13 | import { createUser, getMyUserInformation } from './users' | 14 | import { createUser, getMyUserInformation } from './users' |
14 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
15 | 15 | ||
16 | function updateMyNotificationSettings ( | 16 | function updateMyNotificationSettings ( |
17 | url: string, | 17 | url: string, |
@@ -629,7 +629,59 @@ async function checkNewBlacklistOnMyVideo ( | |||
629 | await checkNotification(base, notificationChecker, emailNotificationFinder, 'presence') | 629 | await checkNotification(base, notificationChecker, emailNotificationFinder, 'presence') |
630 | } | 630 | } |
631 | 631 | ||
632 | function getAllNotificationsSettings () { | 632 | async function checkNewPeerTubeVersion (base: CheckerBaseParams, latestVersion: string, type: CheckerType) { |
633 | const notificationType = UserNotificationType.NEW_PEERTUBE_VERSION | ||
634 | |||
635 | function notificationChecker (notification: UserNotification, type: CheckerType) { | ||
636 | if (type === 'presence') { | ||
637 | expect(notification).to.not.be.undefined | ||
638 | expect(notification.type).to.equal(notificationType) | ||
639 | |||
640 | expect(notification.peertube).to.exist | ||
641 | expect(notification.peertube.latestVersion).to.equal(latestVersion) | ||
642 | } else { | ||
643 | expect(notification).to.satisfy((n: UserNotification) => { | ||
644 | return n === undefined || n.peertube === undefined || n.peertube.latestVersion !== latestVersion | ||
645 | }) | ||
646 | } | ||
647 | } | ||
648 | |||
649 | function emailNotificationFinder (email: object) { | ||
650 | const text = email['text'] | ||
651 | |||
652 | return text.includes(latestVersion) | ||
653 | } | ||
654 | |||
655 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | ||
656 | } | ||
657 | |||
658 | async function checkNewPluginVersion (base: CheckerBaseParams, pluginType: PluginType, pluginName: string, type: CheckerType) { | ||
659 | const notificationType = UserNotificationType.NEW_PLUGIN_VERSION | ||
660 | |||
661 | function notificationChecker (notification: UserNotification, type: CheckerType) { | ||
662 | if (type === 'presence') { | ||
663 | expect(notification).to.not.be.undefined | ||
664 | expect(notification.type).to.equal(notificationType) | ||
665 | |||
666 | expect(notification.plugin.name).to.equal(pluginName) | ||
667 | expect(notification.plugin.type).to.equal(pluginType) | ||
668 | } else { | ||
669 | expect(notification).to.satisfy((n: UserNotification) => { | ||
670 | return n === undefined || n.plugin === undefined || n.plugin.name !== pluginName | ||
671 | }) | ||
672 | } | ||
673 | } | ||
674 | |||
675 | function emailNotificationFinder (email: object) { | ||
676 | const text = email['text'] | ||
677 | |||
678 | return text.includes(pluginName) | ||
679 | } | ||
680 | |||
681 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | ||
682 | } | ||
683 | |||
684 | function getAllNotificationsSettings (): UserNotificationSetting { | ||
633 | return { | 685 | return { |
634 | newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 686 | newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
635 | newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 687 | newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
@@ -644,11 +696,13 @@ function getAllNotificationsSettings () { | |||
644 | newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 696 | newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
645 | abuseNewMessage: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 697 | abuseNewMessage: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
646 | abuseStateChange: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 698 | abuseStateChange: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
647 | autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL | 699 | autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
648 | } as UserNotificationSetting | 700 | newPeerTubeVersion: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
701 | newPluginVersion: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL | ||
702 | } | ||
649 | } | 703 | } |
650 | 704 | ||
651 | async function prepareNotificationsTest (serversCount = 3) { | 705 | async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: any = {}) { |
652 | const userNotifications: UserNotification[] = [] | 706 | const userNotifications: UserNotification[] = [] |
653 | const adminNotifications: UserNotification[] = [] | 707 | const adminNotifications: UserNotification[] = [] |
654 | const adminNotificationsServer2: UserNotification[] = [] | 708 | const adminNotificationsServer2: UserNotification[] = [] |
@@ -665,7 +719,7 @@ async function prepareNotificationsTest (serversCount = 3) { | |||
665 | limit: 20 | 719 | limit: 20 |
666 | } | 720 | } |
667 | } | 721 | } |
668 | const servers = await flushAndRunMultipleServers(serversCount, overrideConfig) | 722 | const servers = await flushAndRunMultipleServers(serversCount, Object.assign(overrideConfig, overrideConfigArg)) |
669 | 723 | ||
670 | await setAccessTokensToServers(servers) | 724 | await setAccessTokensToServers(servers) |
671 | 725 | ||
@@ -749,5 +803,7 @@ export { | |||
749 | checkNewInstanceFollower, | 803 | checkNewInstanceFollower, |
750 | prepareNotificationsTest, | 804 | prepareNotificationsTest, |
751 | checkNewCommentAbuseForModerators, | 805 | checkNewCommentAbuseForModerators, |
752 | checkNewAccountAbuseForModerators | 806 | checkNewAccountAbuseForModerators, |
807 | checkNewPeerTubeVersion, | ||
808 | checkNewPluginVersion | ||
753 | } | 809 | } |
diff --git a/shared/models/index.ts b/shared/models/index.ts index 2214f7ca3..f105303f4 100644 --- a/shared/models/index.ts +++ b/shared/models/index.ts | |||
@@ -7,6 +7,7 @@ export * from './redundancy' | |||
7 | export * from './users' | 7 | export * from './users' |
8 | export * from './videos' | 8 | export * from './videos' |
9 | export * from './feeds' | 9 | export * from './feeds' |
10 | export * from './joinpeertube' | ||
10 | export * from './overviews' | 11 | export * from './overviews' |
11 | export * from './plugins' | 12 | export * from './plugins' |
12 | export * from './search' | 13 | export * from './search' |
diff --git a/shared/models/joinpeertube/index.ts b/shared/models/joinpeertube/index.ts new file mode 100644 index 000000000..9681c35ad --- /dev/null +++ b/shared/models/joinpeertube/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './versions.model' | |||
diff --git a/shared/models/joinpeertube/versions.model.ts b/shared/models/joinpeertube/versions.model.ts new file mode 100644 index 000000000..60a769150 --- /dev/null +++ b/shared/models/joinpeertube/versions.model.ts | |||
@@ -0,0 +1,5 @@ | |||
1 | export interface JoinPeerTubeVersions { | ||
2 | peertube: { | ||
3 | latestVersion: string | ||
4 | } | ||
5 | } | ||
diff --git a/shared/models/users/user-notification-setting.model.ts b/shared/models/users/user-notification-setting.model.ts index 473148062..977e6b985 100644 --- a/shared/models/users/user-notification-setting.model.ts +++ b/shared/models/users/user-notification-setting.model.ts | |||
@@ -24,4 +24,7 @@ export interface UserNotificationSetting { | |||
24 | 24 | ||
25 | abuseStateChange: UserNotificationSettingValue | 25 | abuseStateChange: UserNotificationSettingValue |
26 | abuseNewMessage: UserNotificationSettingValue | 26 | abuseNewMessage: UserNotificationSettingValue |
27 | |||
28 | newPeerTubeVersion: UserNotificationSettingValue | ||
29 | newPluginVersion: UserNotificationSettingValue | ||
27 | } | 30 | } |
diff --git a/shared/models/users/user-notification.model.ts b/shared/models/users/user-notification.model.ts index b04619685..8b33e3fbd 100644 --- a/shared/models/users/user-notification.model.ts +++ b/shared/models/users/user-notification.model.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { FollowState } from '../actors' | 1 | import { FollowState } from '../actors' |
2 | import { AbuseState } from '../moderation' | 2 | import { AbuseState } from '../moderation' |
3 | import { PluginType } from '../plugins' | ||
3 | 4 | ||
4 | export const enum UserNotificationType { | 5 | export const enum UserNotificationType { |
5 | NEW_VIDEO_FROM_SUBSCRIPTION = 1, | 6 | NEW_VIDEO_FROM_SUBSCRIPTION = 1, |
@@ -26,7 +27,10 @@ export const enum UserNotificationType { | |||
26 | 27 | ||
27 | ABUSE_STATE_CHANGE = 15, | 28 | ABUSE_STATE_CHANGE = 15, |
28 | 29 | ||
29 | ABUSE_NEW_MESSAGE = 16 | 30 | ABUSE_NEW_MESSAGE = 16, |
31 | |||
32 | NEW_PLUGIN_VERSION = 17, | ||
33 | NEW_PEERTUBE_VERSION = 18 | ||
30 | } | 34 | } |
31 | 35 | ||
32 | export interface VideoInfo { | 36 | export interface VideoInfo { |
@@ -108,6 +112,16 @@ export interface UserNotification { | |||
108 | } | 112 | } |
109 | } | 113 | } |
110 | 114 | ||
115 | plugin?: { | ||
116 | name: string | ||
117 | type: PluginType | ||
118 | latestVersion: string | ||
119 | } | ||
120 | |||
121 | peertube?: { | ||
122 | latestVersion: string | ||
123 | } | ||
124 | |||
111 | createdAt: string | 125 | createdAt: string |
112 | updatedAt: string | 126 | updatedAt: string |
113 | } | 127 | } |