aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-04-20 15:32:11 +0200
committerChocobozzz <me@florianbigard.com>2020-04-20 15:42:27 +0200
commitb3af2601da92a6c0835cb2473b4c7a41a0d86e98 (patch)
treea20984ec2df1c22f235d03909177629892721c54 /server
parent8c7725dc3c01a73bf56a48c8b192d144bfdc3ffe (diff)
downloadPeerTube-b3af2601da92a6c0835cb2473b4c7a41a0d86e98.tar.gz
PeerTube-b3af2601da92a6c0835cb2473b4c7a41a0d86e98.tar.zst
PeerTube-b3af2601da92a6c0835cb2473b4c7a41a0d86e98.zip
Add ability to remove privacies using plugins
Diffstat (limited to 'server')
-rw-r--r--server/lib/plugins/register-helpers-store.ts42
-rw-r--r--server/tests/fixtures/peertube-plugin-test-three/main.js7
-rw-r--r--server/tests/plugins/video-constants.ts55
-rw-r--r--server/typings/plugins/register-server-option.model.ts5
4 files changed, 101 insertions, 8 deletions
diff --git a/server/lib/plugins/register-helpers-store.ts b/server/lib/plugins/register-helpers-store.ts
index c76c0161a..5ca52b151 100644
--- a/server/lib/plugins/register-helpers-store.ts
+++ b/server/lib/plugins/register-helpers-store.ts
@@ -2,7 +2,13 @@ import { PluginSettingsManager } from '@shared/models/plugins/plugin-settings-ma
2import { PluginModel } from '@server/models/server/plugin' 2import { PluginModel } from '@server/models/server/plugin'
3import { PluginStorageManager } from '@shared/models/plugins/plugin-storage-manager.model' 3import { PluginStorageManager } from '@shared/models/plugins/plugin-storage-manager.model'
4import { PluginVideoLanguageManager } from '@shared/models/plugins/plugin-video-language-manager.model' 4import { PluginVideoLanguageManager } from '@shared/models/plugins/plugin-video-language-manager.model'
5import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES } from '@server/initializers/constants' 5import {
6 VIDEO_CATEGORIES,
7 VIDEO_LANGUAGES,
8 VIDEO_LICENCES,
9 VIDEO_PLAYLIST_PRIVACIES,
10 VIDEO_PRIVACIES
11} from '@server/initializers/constants'
6import { PluginVideoLicenceManager } from '@shared/models/plugins/plugin-video-licence-manager.model' 12import { PluginVideoLicenceManager } from '@shared/models/plugins/plugin-video-licence-manager.model'
7import { PluginVideoCategoryManager } from '@shared/models/plugins/plugin-video-category-manager.model' 13import { PluginVideoCategoryManager } from '@shared/models/plugins/plugin-video-category-manager.model'
8import { RegisterServerOptions } from '@server/typings/plugins' 14import { RegisterServerOptions } from '@server/typings/plugins'
@@ -12,8 +18,10 @@ import { RegisterServerHookOptions } from '@shared/models/plugins/register-serve
12import { serverHookObject } from '@shared/models/plugins/server-hook.model' 18import { serverHookObject } from '@shared/models/plugins/server-hook.model'
13import { RegisterServerSettingOptions } from '@shared/models/plugins/register-server-setting.model' 19import { RegisterServerSettingOptions } from '@shared/models/plugins/register-server-setting.model'
14import * as express from 'express' 20import * as express from 'express'
21import { PluginVideoPrivacyManager } from '@shared/models/plugins/plugin-video-privacy-manager.model'
22import { PluginPlaylistPrivacyManager } from '@shared/models/plugins/plugin-playlist-privacy-manager.model'
15 23
16type AlterableVideoConstant = 'language' | 'licence' | 'category' 24type AlterableVideoConstant = 'language' | 'licence' | 'category' | 'privacy' | 'playlistPrivacy'
17type VideoConstant = { [key in number | string]: string } 25type VideoConstant = { [key in number | string]: string }
18 26
19type UpdatedVideoConstant = { 27type UpdatedVideoConstant = {
@@ -25,6 +33,8 @@ type UpdatedVideoConstant = {
25 33
26export class RegisterHelpersStore { 34export class RegisterHelpersStore {
27 private readonly updatedVideoConstants: UpdatedVideoConstant = { 35 private readonly updatedVideoConstants: UpdatedVideoConstant = {
36 playlistPrivacy: { added: [], deleted: [] },
37 privacy: { added: [], deleted: [] },
28 language: { added: [], deleted: [] }, 38 language: { added: [], deleted: [] },
29 licence: { added: [], deleted: [] }, 39 licence: { added: [], deleted: [] },
30 category: { added: [], deleted: [] } 40 category: { added: [], deleted: [] }
@@ -56,6 +66,9 @@ export class RegisterHelpersStore {
56 const videoLicenceManager = this.buildVideoLicenceManager() 66 const videoLicenceManager = this.buildVideoLicenceManager()
57 const videoCategoryManager = this.buildVideoCategoryManager() 67 const videoCategoryManager = this.buildVideoCategoryManager()
58 68
69 const videoPrivacyManager = this.buildVideoPrivacyManager()
70 const playlistPrivacyManager = this.buildPlaylistPrivacyManager()
71
59 const peertubeHelpers = buildPluginHelpers(this.npmName) 72 const peertubeHelpers = buildPluginHelpers(this.npmName)
60 73
61 return { 74 return {
@@ -71,6 +84,9 @@ export class RegisterHelpersStore {
71 videoCategoryManager, 84 videoCategoryManager,
72 videoLicenceManager, 85 videoLicenceManager,
73 86
87 videoPrivacyManager,
88 playlistPrivacyManager,
89
74 peertubeHelpers 90 peertubeHelpers
75 } 91 }
76 } 92 }
@@ -79,9 +95,11 @@ export class RegisterHelpersStore {
79 const hash = { 95 const hash = {
80 language: VIDEO_LANGUAGES, 96 language: VIDEO_LANGUAGES,
81 licence: VIDEO_LICENCES, 97 licence: VIDEO_LICENCES,
82 category: VIDEO_CATEGORIES 98 category: VIDEO_CATEGORIES,
99 privacy: VIDEO_PRIVACIES,
100 playlistPrivacy: VIDEO_PLAYLIST_PRIVACIES
83 } 101 }
84 const types: AlterableVideoConstant[] = [ 'language', 'licence', 'category' ] 102 const types: AlterableVideoConstant[] = [ 'language', 'licence', 'category', 'privacy', 'playlistPrivacy' ]
85 103
86 for (const type of types) { 104 for (const type of types) {
87 const updatedConstants = this.updatedVideoConstants[type][npmName] 105 const updatedConstants = this.updatedVideoConstants[type][npmName]
@@ -168,6 +186,22 @@ export class RegisterHelpersStore {
168 } 186 }
169 } 187 }
170 188
189 private buildVideoPrivacyManager (): PluginVideoPrivacyManager {
190 return {
191 deletePrivacy: (key: number) => {
192 return this.deleteConstant({ npmName: this.npmName, type: 'privacy', obj: VIDEO_PRIVACIES, key })
193 }
194 }
195 }
196
197 private buildPlaylistPrivacyManager (): PluginPlaylistPrivacyManager {
198 return {
199 deletePlaylistPrivacy: (key: number) => {
200 return this.deleteConstant({ npmName: this.npmName, type: 'playlistPrivacy', obj: VIDEO_PLAYLIST_PRIVACIES, key })
201 }
202 }
203 }
204
171 private buildVideoLicenceManager (): PluginVideoLicenceManager { 205 private buildVideoLicenceManager (): PluginVideoLicenceManager {
172 return { 206 return {
173 addLicence: (key: number, label: string) => { 207 addLicence: (key: number, label: string) => {
diff --git a/server/tests/fixtures/peertube-plugin-test-three/main.js b/server/tests/fixtures/peertube-plugin-test-three/main.js
index 4945feb55..f2b89bcf0 100644
--- a/server/tests/fixtures/peertube-plugin-test-three/main.js
+++ b/server/tests/fixtures/peertube-plugin-test-three/main.js
@@ -5,7 +5,9 @@ async function register ({
5 storageManager, 5 storageManager,
6 videoCategoryManager, 6 videoCategoryManager,
7 videoLicenceManager, 7 videoLicenceManager,
8 videoLanguageManager 8 videoLanguageManager,
9 videoPrivacyManager,
10 playlistPrivacyManager
9}) { 11}) {
10 videoLanguageManager.addLanguage('al_bhed', 'Al Bhed') 12 videoLanguageManager.addLanguage('al_bhed', 'Al Bhed')
11 videoLanguageManager.addLanguage('al_bhed2', 'Al Bhed 2') 13 videoLanguageManager.addLanguage('al_bhed2', 'Al Bhed 2')
@@ -21,6 +23,9 @@ async function register ({
21 videoLicenceManager.addLicence(43, 'High best licence') 23 videoLicenceManager.addLicence(43, 'High best licence')
22 videoLicenceManager.deleteLicence(1) // Attribution 24 videoLicenceManager.deleteLicence(1) // Attribution
23 videoLicenceManager.deleteLicence(7) // Public domain 25 videoLicenceManager.deleteLicence(7) // Public domain
26
27 videoPrivacyManager.deletePrivacy(2)
28 playlistPrivacyManager.deletePlaylistPrivacy(3)
24} 29}
25 30
26async function unregister () { 31async function unregister () {
diff --git a/server/tests/plugins/video-constants.ts b/server/tests/plugins/video-constants.ts
index 5374b5ecc..fec9196e2 100644
--- a/server/tests/plugins/video-constants.ts
+++ b/server/tests/plugins/video-constants.ts
@@ -4,17 +4,18 @@ import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' 5import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'
6import { 6import {
7 createVideoPlaylist,
7 getPluginTestPath, 8 getPluginTestPath,
8 getVideo, 9 getVideo,
9 getVideoCategories, 10 getVideoCategories,
10 getVideoLanguages, 11 getVideoLanguages,
11 getVideoLicences, 12 getVideoLicences, getVideoPlaylistPrivacies, getVideoPrivacies,
12 installPlugin, 13 installPlugin,
13 setAccessTokensToServers, 14 setAccessTokensToServers,
14 uninstallPlugin, 15 uninstallPlugin,
15 uploadVideo 16 uploadVideo
16} from '../../../shared/extra-utils' 17} from '../../../shared/extra-utils'
17import { VideoDetails } from '../../../shared/models/videos' 18import { VideoDetails, VideoPlaylistPrivacy } from '../../../shared/models/videos'
18 19
19const expect = chai.expect 20const expect = chai.expect
20 21
@@ -67,6 +68,35 @@ describe('Test plugin altering video constants', function () {
67 expect(licences[43]).to.equal('High best licence') 68 expect(licences[43]).to.equal('High best licence')
68 }) 69 })
69 70
71 it('Should have updated video privacies', async function () {
72 const res = await getVideoPrivacies(server.url)
73 const privacies = res.body
74
75 expect(privacies[1]).to.exist
76 expect(privacies[2]).to.not.exist
77 expect(privacies[3]).to.exist
78 expect(privacies[4]).to.exist
79 })
80
81 it('Should have updated playlist privacies', async function () {
82 const res = await getVideoPlaylistPrivacies(server.url)
83 const playlistPrivacies = res.body
84
85 expect(playlistPrivacies[1]).to.exist
86 expect(playlistPrivacies[2]).to.exist
87 expect(playlistPrivacies[3]).to.not.exist
88 })
89
90 it('Should not be able to create a video with this privacy', async function () {
91 const attrs = { name: 'video', privacy: 2 }
92 await uploadVideo(server.url, server.accessToken, attrs, 400)
93 })
94
95 it('Should not be able to create a video with this privacy', async function () {
96 const attrs = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE }
97 await createVideoPlaylist({ url: server.url, token: server.accessToken, playlistAttrs: attrs, expectedStatus: 400 })
98 })
99
70 it('Should be able to upload a video with these values', async function () { 100 it('Should be able to upload a video with these values', async function () {
71 const attrs = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' } 101 const attrs = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' }
72 const resUpload = await uploadVideo(server.url, server.accessToken, attrs) 102 const resUpload = await uploadVideo(server.url, server.accessToken, attrs)
@@ -79,7 +109,7 @@ describe('Test plugin altering video constants', function () {
79 expect(video.category.label).to.equal('Best category') 109 expect(video.category.label).to.equal('Best category')
80 }) 110 })
81 111
82 it('Should uninstall the plugin and reset languages, categories and licences', async function () { 112 it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () {
83 await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-three' }) 113 await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-three' })
84 114
85 { 115 {
@@ -114,6 +144,25 @@ describe('Test plugin altering video constants', function () {
114 expect(licences[42]).to.not.exist 144 expect(licences[42]).to.not.exist
115 expect(licences[43]).to.not.exist 145 expect(licences[43]).to.not.exist
116 } 146 }
147
148 {
149 const res = await getVideoPrivacies(server.url)
150 const privacies = res.body
151
152 expect(privacies[1]).to.exist
153 expect(privacies[2]).to.exist
154 expect(privacies[3]).to.exist
155 expect(privacies[4]).to.exist
156 }
157
158 {
159 const res = await getVideoPlaylistPrivacies(server.url)
160 const playlistPrivacies = res.body
161
162 expect(playlistPrivacies[1]).to.exist
163 expect(playlistPrivacies[2]).to.exist
164 expect(playlistPrivacies[3]).to.exist
165 }
117 }) 166 })
118 167
119 after(async function () { 168 after(async function () {
diff --git a/server/typings/plugins/register-server-option.model.ts b/server/typings/plugins/register-server-option.model.ts
index 3d6217d1b..813e93003 100644
--- a/server/typings/plugins/register-server-option.model.ts
+++ b/server/typings/plugins/register-server-option.model.ts
@@ -7,6 +7,8 @@ import { PluginVideoLanguageManager } from '../../../shared/models/plugins/plugi
7import { PluginVideoLicenceManager } from '../../../shared/models/plugins/plugin-video-licence-manager.model' 7import { PluginVideoLicenceManager } from '../../../shared/models/plugins/plugin-video-licence-manager.model'
8import { Logger } from 'winston' 8import { Logger } from 'winston'
9import { Router } from 'express' 9import { Router } from 'express'
10import { PluginVideoPrivacyManager } from '@shared/models/plugins/plugin-video-privacy-manager.model'
11import { PluginPlaylistPrivacyManager } from '@shared/models/plugins/plugin-playlist-privacy-manager.model'
10 12
11export type PeerTubeHelpers = { 13export type PeerTubeHelpers = {
12 logger: Logger 14 logger: Logger
@@ -33,6 +35,9 @@ export type RegisterServerOptions = {
33 videoLanguageManager: PluginVideoLanguageManager 35 videoLanguageManager: PluginVideoLanguageManager
34 videoLicenceManager: PluginVideoLicenceManager 36 videoLicenceManager: PluginVideoLicenceManager
35 37
38 videoPrivacyManager: PluginVideoPrivacyManager
39 playlistPrivacyManager: PluginPlaylistPrivacyManager
40
36 // Get plugin router to create custom routes 41 // Get plugin router to create custom routes
37 // Base routes of this router are 42 // Base routes of this router are
38 // * /plugins/:pluginName/:pluginVersion/router/... 43 // * /plugins/:pluginName/:pluginVersion/router/...