diff options
7 files changed, 125 insertions, 9 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 | |||
2 | import { PluginModel } from '@server/models/server/plugin' | 2 | import { PluginModel } from '@server/models/server/plugin' |
3 | import { PluginStorageManager } from '@shared/models/plugins/plugin-storage-manager.model' | 3 | import { PluginStorageManager } from '@shared/models/plugins/plugin-storage-manager.model' |
4 | import { PluginVideoLanguageManager } from '@shared/models/plugins/plugin-video-language-manager.model' | 4 | import { PluginVideoLanguageManager } from '@shared/models/plugins/plugin-video-language-manager.model' |
5 | import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES } from '@server/initializers/constants' | 5 | import { |
6 | VIDEO_CATEGORIES, | ||
7 | VIDEO_LANGUAGES, | ||
8 | VIDEO_LICENCES, | ||
9 | VIDEO_PLAYLIST_PRIVACIES, | ||
10 | VIDEO_PRIVACIES | ||
11 | } from '@server/initializers/constants' | ||
6 | import { PluginVideoLicenceManager } from '@shared/models/plugins/plugin-video-licence-manager.model' | 12 | import { PluginVideoLicenceManager } from '@shared/models/plugins/plugin-video-licence-manager.model' |
7 | import { PluginVideoCategoryManager } from '@shared/models/plugins/plugin-video-category-manager.model' | 13 | import { PluginVideoCategoryManager } from '@shared/models/plugins/plugin-video-category-manager.model' |
8 | import { RegisterServerOptions } from '@server/typings/plugins' | 14 | import { RegisterServerOptions } from '@server/typings/plugins' |
@@ -12,8 +18,10 @@ import { RegisterServerHookOptions } from '@shared/models/plugins/register-serve | |||
12 | import { serverHookObject } from '@shared/models/plugins/server-hook.model' | 18 | import { serverHookObject } from '@shared/models/plugins/server-hook.model' |
13 | import { RegisterServerSettingOptions } from '@shared/models/plugins/register-server-setting.model' | 19 | import { RegisterServerSettingOptions } from '@shared/models/plugins/register-server-setting.model' |
14 | import * as express from 'express' | 20 | import * as express from 'express' |
21 | import { PluginVideoPrivacyManager } from '@shared/models/plugins/plugin-video-privacy-manager.model' | ||
22 | import { PluginPlaylistPrivacyManager } from '@shared/models/plugins/plugin-playlist-privacy-manager.model' | ||
15 | 23 | ||
16 | type AlterableVideoConstant = 'language' | 'licence' | 'category' | 24 | type AlterableVideoConstant = 'language' | 'licence' | 'category' | 'privacy' | 'playlistPrivacy' |
17 | type VideoConstant = { [key in number | string]: string } | 25 | type VideoConstant = { [key in number | string]: string } |
18 | 26 | ||
19 | type UpdatedVideoConstant = { | 27 | type UpdatedVideoConstant = { |
@@ -25,6 +33,8 @@ type UpdatedVideoConstant = { | |||
25 | 33 | ||
26 | export class RegisterHelpersStore { | 34 | export 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 | ||
26 | async function unregister () { | 31 | async 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' | |||
4 | import 'mocha' | 4 | import 'mocha' |
5 | import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' | 5 | import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' |
6 | import { | 6 | import { |
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' |
17 | import { VideoDetails } from '../../../shared/models/videos' | 18 | import { VideoDetails, VideoPlaylistPrivacy } from '../../../shared/models/videos' |
18 | 19 | ||
19 | const expect = chai.expect | 20 | const 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 | |||
7 | import { PluginVideoLicenceManager } from '../../../shared/models/plugins/plugin-video-licence-manager.model' | 7 | import { PluginVideoLicenceManager } from '../../../shared/models/plugins/plugin-video-licence-manager.model' |
8 | import { Logger } from 'winston' | 8 | import { Logger } from 'winston' |
9 | import { Router } from 'express' | 9 | import { Router } from 'express' |
10 | import { PluginVideoPrivacyManager } from '@shared/models/plugins/plugin-video-privacy-manager.model' | ||
11 | import { PluginPlaylistPrivacyManager } from '@shared/models/plugins/plugin-playlist-privacy-manager.model' | ||
10 | 12 | ||
11 | export type PeerTubeHelpers = { | 13 | export 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/... |
diff --git a/shared/models/plugins/plugin-playlist-privacy-manager.model.ts b/shared/models/plugins/plugin-playlist-privacy-manager.model.ts new file mode 100644 index 000000000..f9630c77f --- /dev/null +++ b/shared/models/plugins/plugin-playlist-privacy-manager.model.ts | |||
@@ -0,0 +1,8 @@ | |||
1 | import { VideoPlaylistPrivacy } from '@shared/models' | ||
2 | |||
3 | export interface PluginPlaylistPrivacyManager { | ||
4 | // PUBLIC = 1, | ||
5 | // UNLISTED = 2, | ||
6 | // PRIVATE = 3 | ||
7 | deletePlaylistPrivacy: (privacyKey: VideoPlaylistPrivacy) => boolean | ||
8 | } | ||
diff --git a/shared/models/plugins/plugin-video-privacy-manager.model.ts b/shared/models/plugins/plugin-video-privacy-manager.model.ts new file mode 100644 index 000000000..d602ba297 --- /dev/null +++ b/shared/models/plugins/plugin-video-privacy-manager.model.ts | |||
@@ -0,0 +1,9 @@ | |||
1 | import { VideoPrivacy } from '@shared/models' | ||
2 | |||
3 | export interface PluginVideoPrivacyManager { | ||
4 | // PUBLIC = 1 | ||
5 | // UNLISTED = 2 | ||
6 | // PRIVATE = 3 | ||
7 | // INTERNAL = 4 | ||
8 | deletePrivacy: (privacyKey: VideoPrivacy) => boolean | ||
9 | } | ||
diff --git a/support/doc/plugins/guide.md b/support/doc/plugins/guide.md index 1bee1f611..fdad63087 100644 --- a/support/doc/plugins/guide.md +++ b/support/doc/plugins/guide.md | |||
@@ -14,7 +14,10 @@ | |||
14 | - [Update video constants](#update-video-constants) | 14 | - [Update video constants](#update-video-constants) |
15 | - [Add custom routes](#add-custom-routes) | 15 | - [Add custom routes](#add-custom-routes) |
16 | - [Client helpers (themes & plugins)](#client-helpers-themes--plugins) | 16 | - [Client helpers (themes & plugins)](#client-helpers-themes--plugins) |
17 | - [Plugin static route](#plugin-static-route) | 17 | - [Plugin static route](#plugin-static-route) |
18 | - [Notifier](#notifier) | ||
19 | - [Markdown Renderer](#markdown-renderer) | ||
20 | - [Custom Modal](#custom-modal) | ||
18 | - [Translate](#translate) | 21 | - [Translate](#translate) |
19 | - [Get public settings](#get-public-settings) | 22 | - [Get public settings](#get-public-settings) |
20 | - [Publishing](#publishing) | 23 | - [Publishing](#publishing) |
@@ -180,6 +183,9 @@ videoCategoryManager.deleteCategory(1) // Music | |||
180 | 183 | ||
181 | videoLicenceManager.addLicence(42, 'Best licence') | 184 | videoLicenceManager.addLicence(42, 'Best licence') |
182 | videoLicenceManager.deleteLicence(7) // Public domain | 185 | videoLicenceManager.deleteLicence(7) // Public domain |
186 | |||
187 | videoPrivacyManager.deletePrivacy(2) // Remove Unlisted video privacy | ||
188 | playlistPrivacyManager.deletePlaylistPrivacy(3) // Remove Private video playlist privacy | ||
183 | ``` | 189 | ``` |
184 | 190 | ||
185 | #### Add custom routes | 191 | #### Add custom routes |