aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
Diffstat (limited to 'shared')
-rw-r--r--shared/extra-utils/index.ts1
-rw-r--r--shared/extra-utils/instances-index/mock-instances-index.ts38
-rw-r--r--shared/extra-utils/server/config.ts29
-rw-r--r--shared/extra-utils/users/user-notifications.ts41
-rw-r--r--shared/extra-utils/users/users.ts29
-rw-r--r--shared/models/activitypub/activity.ts2
-rw-r--r--shared/models/activitypub/objects/video-abuse-object.ts2
-rw-r--r--shared/models/i18n/i18n.ts4
-rw-r--r--shared/models/server/about.model.ts12
-rw-r--r--shared/models/server/custom-config.model.ts24
-rw-r--r--shared/models/users/user-notification-setting.model.ts1
-rw-r--r--shared/models/users/user-notification.model.ts8
-rw-r--r--shared/models/users/user-update-me.model.ts3
-rw-r--r--shared/models/users/user.model.ts10
14 files changed, 165 insertions, 39 deletions
diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts
index 53ddaa681..78acf72aa 100644
--- a/shared/extra-utils/index.ts
+++ b/shared/extra-utils/index.ts
@@ -24,4 +24,5 @@ export * from './videos/video-streaming-playlists'
24export * from './videos/videos' 24export * from './videos/videos'
25export * from './videos/video-change-ownership' 25export * from './videos/video-change-ownership'
26export * from './feeds/feeds' 26export * from './feeds/feeds'
27export * from './instances-index/mock-instances-index'
27export * from './search/videos' 28export * from './search/videos'
diff --git a/shared/extra-utils/instances-index/mock-instances-index.ts b/shared/extra-utils/instances-index/mock-instances-index.ts
new file mode 100644
index 000000000..cfa4523c1
--- /dev/null
+++ b/shared/extra-utils/instances-index/mock-instances-index.ts
@@ -0,0 +1,38 @@
1import * as express from 'express'
2
3export class MockInstancesIndex {
4 private indexInstances: { host: string, createdAt: string }[] = []
5
6 initialize () {
7 return new Promise(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('/api/v1/instances/hosts', (req: express.Request, res: express.Response) => {
17 const since = req.query.since
18
19 const filtered = this.indexInstances.filter(i => {
20 if (!since) return true
21
22 return i.createdAt > since
23 })
24
25 return res.json({
26 total: filtered.length,
27 data: filtered
28 })
29 })
30
31 app.listen(42100, () => res())
32 })
33 }
34
35 addInstance (host: string) {
36 this.indexInstances.push({ host, createdAt: new Date().toISOString() })
37 }
38}
diff --git a/shared/extra-utils/server/config.ts b/shared/extra-utils/server/config.ts
index 8736f083f..578dd35cf 100644
--- a/shared/extra-utils/server/config.ts
+++ b/shared/extra-utils/server/config.ts
@@ -1,5 +1,7 @@
1import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests' 1import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests'
2import { CustomConfig } from '../../models/server/custom-config.model' 2import { CustomConfig } from '../../models/server/custom-config.model'
3import { DeepPartial } from '@server/typings/utils'
4import { merge } from 'lodash'
3 5
4function getConfig (url: string) { 6function getConfig (url: string) {
5 const path = '/api/v1/config' 7 const path = '/api/v1/config'
@@ -44,13 +46,25 @@ function updateCustomConfig (url: string, token: string, newCustomConfig: Custom
44 }) 46 })
45} 47}
46 48
47function updateCustomSubConfig (url: string, token: string, newConfig: any) { 49function updateCustomSubConfig (url: string, token: string, newConfig: DeepPartial<CustomConfig>) {
48 const updateParams: CustomConfig = { 50 const updateParams: CustomConfig = {
49 instance: { 51 instance: {
50 name: 'PeerTube updated', 52 name: 'PeerTube updated',
51 shortDescription: 'my short description', 53 shortDescription: 'my short description',
52 description: 'my super description', 54 description: 'my super description',
53 terms: 'my super terms', 55 terms: 'my super terms',
56 codeOfConduct: 'my super coc',
57
58 creationReason: 'my super creation reason',
59 moderationInformation: 'my super moderation information',
60 administrator: 'Kuja',
61 maintenanceLifetime: 'forever',
62 businessModel: 'my super business model',
63 hardwareInformation: '2vCore 3GB RAM',
64
65 languages: [ 'en', 'es' ],
66 categories: [ 1, 2 ],
67
54 defaultClientRoute: '/videos/recently-added', 68 defaultClientRoute: '/videos/recently-added',
55 isNSFW: true, 69 isNSFW: true,
56 defaultNSFWPolicy: 'blur', 70 defaultNSFWPolicy: 'blur',
@@ -130,10 +144,21 @@ function updateCustomSubConfig (url: string, token: string, newConfig: any) {
130 enabled: true, 144 enabled: true,
131 manualApproval: false 145 manualApproval: false
132 } 146 }
147 },
148 followings: {
149 instance: {
150 autoFollowBack: {
151 enabled: false
152 },
153 autoFollowIndex: {
154 indexUrl: 'https://instances.joinpeertube.org',
155 enabled: false
156 }
157 }
133 } 158 }
134 } 159 }
135 160
136 Object.assign(updateParams, newConfig) 161 merge(updateParams, newConfig)
137 162
138 return updateCustomConfig(url, token, updateParams) 163 return updateCustomConfig(url, token, updateParams)
139} 164}
diff --git a/shared/extra-utils/users/user-notifications.ts b/shared/extra-utils/users/user-notifications.ts
index f7de542bf..9a5fd7e86 100644
--- a/shared/extra-utils/users/user-notifications.ts
+++ b/shared/extra-utils/users/user-notifications.ts
@@ -279,8 +279,9 @@ async function checkNewActorFollow (
279 expect(notification.actorFollow.follower.name).to.equal(followerName) 279 expect(notification.actorFollow.follower.name).to.equal(followerName)
280 expect(notification.actorFollow.follower.host).to.not.be.undefined 280 expect(notification.actorFollow.follower.host).to.not.be.undefined
281 281
282 expect(notification.actorFollow.following.displayName).to.equal(followingDisplayName) 282 const following = notification.actorFollow.following
283 expect(notification.actorFollow.following.type).to.equal(followType) 283 expect(following.displayName).to.equal(followingDisplayName)
284 expect(following.type).to.equal(followType)
284 } else { 285 } else {
285 expect(notification).to.satisfy(n => { 286 expect(notification).to.satisfy(n => {
286 return n.type !== notificationType || 287 return n.type !== notificationType ||
@@ -327,6 +328,37 @@ async function checkNewInstanceFollower (base: CheckerBaseParams, followerHost:
327 await checkNotification(base, notificationChecker, emailFinder, type) 328 await checkNotification(base, notificationChecker, emailFinder, type)
328} 329}
329 330
331async function checkAutoInstanceFollowing (base: CheckerBaseParams, followerHost: string, followingHost: string, type: CheckerType) {
332 const notificationType = UserNotificationType.AUTO_INSTANCE_FOLLOWING
333
334 function notificationChecker (notification: UserNotification, type: CheckerType) {
335 if (type === 'presence') {
336 expect(notification).to.not.be.undefined
337 expect(notification.type).to.equal(notificationType)
338
339 const following = notification.actorFollow.following
340 checkActor(following)
341 expect(following.name).to.equal('peertube')
342 expect(following.host).to.equal(followingHost)
343
344 expect(notification.actorFollow.follower.name).to.equal('peertube')
345 expect(notification.actorFollow.follower.host).to.equal(followerHost)
346 } else {
347 expect(notification).to.satisfy(n => {
348 return n.type !== notificationType || n.actorFollow.following.host !== followingHost
349 })
350 }
351 }
352
353 function emailFinder (email: object) {
354 const text: string = email[ 'text' ]
355
356 return text.includes(' automatically followed a new instance') && text.includes(followingHost)
357 }
358
359 await checkNotification(base, notificationChecker, emailFinder, type)
360}
361
330async function checkCommentMention ( 362async function checkCommentMention (
331 base: CheckerBaseParams, 363 base: CheckerBaseParams,
332 uuid: string, 364 uuid: string,
@@ -427,8 +459,8 @@ async function checkVideoAutoBlacklistForModerators (base: CheckerBaseParams, vi
427 expect(notification).to.not.be.undefined 459 expect(notification).to.not.be.undefined
428 expect(notification.type).to.equal(notificationType) 460 expect(notification.type).to.equal(notificationType)
429 461
430 expect(notification.video.id).to.be.a('number') 462 expect(notification.videoBlacklist.video.id).to.be.a('number')
431 checkVideo(notification.video, videoName, videoUUID) 463 checkVideo(notification.videoBlacklist.video, videoName, videoUUID)
432 } else { 464 } else {
433 expect(notification).to.satisfy((n: UserNotification) => { 465 expect(notification).to.satisfy((n: UserNotification) => {
434 return n === undefined || n.video === undefined || n.video.uuid !== videoUUID 466 return n === undefined || n.video === undefined || n.video.uuid !== videoUUID
@@ -480,6 +512,7 @@ export {
480 markAsReadAllNotifications, 512 markAsReadAllNotifications,
481 checkMyVideoImportIsFinished, 513 checkMyVideoImportIsFinished,
482 checkUserRegistered, 514 checkUserRegistered,
515 checkAutoInstanceFollowing,
483 checkVideoIsPublished, 516 checkVideoIsPublished,
484 checkNewVideoFromSubscription, 517 checkNewVideoFromSubscription,
485 checkNewActorFollow, 518 checkNewActorFollow,
diff --git a/shared/extra-utils/users/users.ts b/shared/extra-utils/users/users.ts
index 30ed1bf4a..9959fd074 100644
--- a/shared/extra-utils/users/users.ts
+++ b/shared/extra-utils/users/users.ts
@@ -1,12 +1,12 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2import { makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../requests/requests' 2import { makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../requests/requests'
3import { NSFWPolicyType } from '../../models/videos/nsfw-policy.type'
4import { UserAdminFlag } from '../../models/users/user-flag.model' 3import { UserAdminFlag } from '../../models/users/user-flag.model'
5import { UserRegister } from '../../models/users/user-register.model' 4import { UserRegister } from '../../models/users/user-register.model'
6import { UserRole } from '../../models/users/user-role' 5import { UserRole } from '../../models/users/user-role'
7import { ServerInfo } from '../server/servers' 6import { ServerInfo } from '../server/servers'
8import { userLogin } from './login' 7import { userLogin } from './login'
9import { UserUpdateMe } from '../../models/users' 8import { UserUpdateMe } from '../../models/users'
9import { omit } from 'lodash'
10 10
11type CreateUserArgs = { url: string, 11type CreateUserArgs = { url: string,
12 accessToken: string, 12 accessToken: string,
@@ -214,33 +214,10 @@ function unblockUser (url: string, userId: number | string, accessToken: string,
214 .expect(expectedStatus) 214 .expect(expectedStatus)
215} 215}
216 216
217function updateMyUser (options: { 217function updateMyUser (options: { url: string, accessToken: string } & UserUpdateMe) {
218 url: string
219 accessToken: string
220 currentPassword?: string
221 newPassword?: string
222 nsfwPolicy?: NSFWPolicyType
223 email?: string
224 autoPlayVideo?: boolean
225 displayName?: string
226 description?: string
227 videosHistoryEnabled?: boolean
228 theme?: string
229}) {
230 const path = '/api/v1/users/me' 218 const path = '/api/v1/users/me'
231 219
232 const toSend: UserUpdateMe = {} 220 const toSend: UserUpdateMe = omit(options, 'url', 'accessToken')
233 if (options.currentPassword !== undefined && options.currentPassword !== null) toSend.currentPassword = options.currentPassword
234 if (options.newPassword !== undefined && options.newPassword !== null) toSend.password = options.newPassword
235 if (options.nsfwPolicy !== undefined && options.nsfwPolicy !== null) toSend.nsfwPolicy = options.nsfwPolicy
236 if (options.autoPlayVideo !== undefined && options.autoPlayVideo !== null) toSend.autoPlayVideo = options.autoPlayVideo
237 if (options.email !== undefined && options.email !== null) toSend.email = options.email
238 if (options.description !== undefined && options.description !== null) toSend.description = options.description
239 if (options.displayName !== undefined && options.displayName !== null) toSend.displayName = options.displayName
240 if (options.theme !== undefined && options.theme !== null) toSend.theme = options.theme
241 if (options.videosHistoryEnabled !== undefined && options.videosHistoryEnabled !== null) {
242 toSend.videosHistoryEnabled = options.videosHistoryEnabled
243 }
244 221
245 return makePutBodyRequest({ 222 return makePutBodyRequest({
246 url: options.url, 223 url: options.url,
diff --git a/shared/models/activitypub/activity.ts b/shared/models/activitypub/activity.ts
index 95801190d..492b672c7 100644
--- a/shared/models/activitypub/activity.ts
+++ b/shared/models/activitypub/activity.ts
@@ -91,5 +91,5 @@ export interface ActivityDislike extends BaseActivity {
91export interface ActivityFlag extends BaseActivity { 91export interface ActivityFlag extends BaseActivity {
92 type: 'Flag', 92 type: 'Flag',
93 content: string, 93 content: string,
94 object: APObject 94 object: APObject | APObject[]
95} 95}
diff --git a/shared/models/activitypub/objects/video-abuse-object.ts b/shared/models/activitypub/objects/video-abuse-object.ts
index 40e7abd57..5f1264a76 100644
--- a/shared/models/activitypub/objects/video-abuse-object.ts
+++ b/shared/models/activitypub/objects/video-abuse-object.ts
@@ -1,5 +1,5 @@
1export interface VideoAbuseObject { 1export interface VideoAbuseObject {
2 type: 'Flag', 2 type: 'Flag',
3 content: string 3 content: string
4 object: string 4 object: string | string[]
5} 5}
diff --git a/shared/models/i18n/i18n.ts b/shared/models/i18n/i18n.ts
index 218fd09ba..03a5d858a 100644
--- a/shared/models/i18n/i18n.ts
+++ b/shared/models/i18n/i18n.ts
@@ -39,7 +39,9 @@ const I18N_LOCALE_ALIAS = {
39 'pl': 'pl-PL', 39 'pl': 'pl-PL',
40 'ru': 'ru-RU', 40 'ru': 'ru-RU',
41 'nl': 'nl-NL', 41 'nl': 'nl-NL',
42 'zh': 'zh-Hans-CN' 42 'zh': 'zh-Hans-CN',
43 'zh-CN': 'zh-Hans-CN',
44 'zh-TW': 'zh-Hant-TW'
43} 45}
44 46
45export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES) 47export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES)
diff --git a/shared/models/server/about.model.ts b/shared/models/server/about.model.ts
index 10dff8b8f..6d4ba63c4 100644
--- a/shared/models/server/about.model.ts
+++ b/shared/models/server/about.model.ts
@@ -4,5 +4,17 @@ export interface About {
4 shortDescription: string 4 shortDescription: string
5 description: string 5 description: string
6 terms: string 6 terms: string
7
8 codeOfConduct: string
9 hardwareInformation: string
10
11 creationReason: string
12 moderationInformation: string
13 administrator: string
14 maintenanceLifetime: string
15 businessModel: string
16
17 languages: string[]
18 categories: number[]
7 } 19 }
8} 20}
diff --git a/shared/models/server/custom-config.model.ts b/shared/models/server/custom-config.model.ts
index a0541f5b6..c9957f825 100644
--- a/shared/models/server/custom-config.model.ts
+++ b/shared/models/server/custom-config.model.ts
@@ -6,6 +6,18 @@ export interface CustomConfig {
6 shortDescription: string 6 shortDescription: string
7 description: string 7 description: string
8 terms: string 8 terms: string
9 codeOfConduct: string
10
11 creationReason: string
12 moderationInformation: string
13 administrator: string
14 maintenanceLifetime: string
15 businessModel: string
16 hardwareInformation: string
17
18 languages: string[]
19 categories: number[]
20
9 isNSFW: boolean 21 isNSFW: boolean
10 defaultClientRoute: string 22 defaultClientRoute: string
11 defaultNSFWPolicy: NSFWPolicyType 23 defaultNSFWPolicy: NSFWPolicyType
@@ -99,4 +111,16 @@ export interface CustomConfig {
99 } 111 }
100 } 112 }
101 113
114 followings: {
115 instance: {
116 autoFollowBack: {
117 enabled: boolean
118 }
119
120 autoFollowIndex: {
121 enabled: boolean
122 indexUrl: string
123 }
124 }
125 }
102} 126}
diff --git a/shared/models/users/user-notification-setting.model.ts b/shared/models/users/user-notification-setting.model.ts
index e2a882b69..451f40d58 100644
--- a/shared/models/users/user-notification-setting.model.ts
+++ b/shared/models/users/user-notification-setting.model.ts
@@ -16,4 +16,5 @@ export interface UserNotificationSetting {
16 newFollow: UserNotificationSettingValue 16 newFollow: UserNotificationSettingValue
17 commentMention: UserNotificationSettingValue 17 commentMention: UserNotificationSettingValue
18 newInstanceFollower: UserNotificationSettingValue 18 newInstanceFollower: UserNotificationSettingValue
19 autoInstanceFollowing: UserNotificationSettingValue
19} 20}
diff --git a/shared/models/users/user-notification.model.ts b/shared/models/users/user-notification.model.ts
index fafc2b7d7..e9be1ca7f 100644
--- a/shared/models/users/user-notification.model.ts
+++ b/shared/models/users/user-notification.model.ts
@@ -19,7 +19,9 @@ export enum UserNotificationType {
19 19
20 VIDEO_AUTO_BLACKLIST_FOR_MODERATORS = 12, 20 VIDEO_AUTO_BLACKLIST_FOR_MODERATORS = 12,
21 21
22 NEW_INSTANCE_FOLLOWER = 13 22 NEW_INSTANCE_FOLLOWER = 13,
23
24 AUTO_INSTANCE_FOLLOWING = 14
23} 25}
24 26
25export interface VideoInfo { 27export interface VideoInfo {
@@ -78,10 +80,12 @@ export interface UserNotification {
78 id: number 80 id: number
79 follower: ActorInfo 81 follower: ActorInfo
80 state: FollowState 82 state: FollowState
83
81 following: { 84 following: {
82 type: 'account' | 'channel' 85 type: 'account' | 'channel' | 'instance'
83 name: string 86 name: string
84 displayName: string 87 displayName: string
88 host: string
85 } 89 }
86 } 90 }
87 91
diff --git a/shared/models/users/user-update-me.model.ts b/shared/models/users/user-update-me.model.ts
index b6c0002e5..99b9a65bd 100644
--- a/shared/models/users/user-update-me.model.ts
+++ b/shared/models/users/user-update-me.model.ts
@@ -15,4 +15,7 @@ export interface UserUpdateMe {
15 password?: string 15 password?: string
16 16
17 theme?: string 17 theme?: string
18
19 noInstanceConfigWarningModal?: boolean
20 noWelcomeModal?: boolean
18} 21}
diff --git a/shared/models/users/user.model.ts b/shared/models/users/user.model.ts
index de9825e1f..f67d262b0 100644
--- a/shared/models/users/user.model.ts
+++ b/shared/models/users/user.model.ts
@@ -10,6 +10,7 @@ export interface User {
10 username: string 10 username: string
11 email: string 11 email: string
12 pendingEmail: string | null 12 pendingEmail: string | null
13
13 emailVerified: boolean 14 emailVerified: boolean
14 nsfwPolicy: NSFWPolicyType 15 nsfwPolicy: NSFWPolicyType
15 16
@@ -18,13 +19,15 @@ export interface User {
18 autoPlayVideo: boolean 19 autoPlayVideo: boolean
19 webTorrentEnabled: boolean 20 webTorrentEnabled: boolean
20 videosHistoryEnabled: boolean 21 videosHistoryEnabled: boolean
22 videoLanguages: string[]
21 23
22 role: UserRole 24 role: UserRole
23 roleLabel: string 25 roleLabel: string
24 26
25 videoQuota: number 27 videoQuota: number
26 videoQuotaDaily: number 28 videoQuotaDaily: number
27 createdAt: Date 29 videoQuotaUsed?: number
30 videoQuotaUsedDaily?: number
28 31
29 theme: string 32 theme: string
30 33
@@ -35,5 +38,8 @@ export interface User {
35 blocked: boolean 38 blocked: boolean
36 blockedReason?: string 39 blockedReason?: string
37 40
38 videoQuotaUsed?: number 41 noInstanceConfigWarningModal: boolean
42 noWelcomeModal: boolean
43
44 createdAt: Date
39} 45}