From a9bfa85d2cdf13670aaced740da5b493fbeddfce Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 15 Dec 2021 15:58:10 +0100 Subject: Add ability for admins to set default p2p policy --- server/controllers/api/users/index.ts | 2 ++ server/controllers/api/users/me.ts | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'server/controllers/api/users') diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index 11d3525e4..f3b4508d9 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts @@ -183,6 +183,7 @@ async function createUser (req: express.Request, res: express.Response) { password: body.password, email: body.email, nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, + p2pEnabled: CONFIG.DEFAULTS.P2P.ENABLED, autoPlayVideo: true, role: body.role, videoQuota: body.videoQuota, @@ -232,6 +233,7 @@ async function registerUser (req: express.Request, res: express.Response) { password: body.password, email: body.email, nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, + p2pEnabled: CONFIG.DEFAULTS.P2P.ENABLED, autoPlayVideo: true, role: UserRole.USER, videoQuota: CONFIG.USER.VIDEO_QUOTA, diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts index 6bacdbbb6..1125771d4 100644 --- a/server/controllers/api/users/me.ts +++ b/server/controllers/api/users/me.ts @@ -197,7 +197,7 @@ async function updateMe (req: express.Request, res: express.Response) { const keysToUpdate: (keyof UserUpdateMe & keyof AttributesOnly)[] = [ 'password', 'nsfwPolicy', - 'webTorrentEnabled', + 'p2pEnabled', 'autoPlayVideo', 'autoPlayNextVideo', 'autoPlayNextVideoPlaylist', @@ -213,6 +213,12 @@ async function updateMe (req: express.Request, res: express.Response) { if (body[key] !== undefined) user.set(key, body[key]) } + if (body.p2pEnabled !== undefined) { + user.set('p2pEnabled', body.p2pEnabled) + } else if (body.webTorrentEnabled !== undefined) { // FIXME: deprecated in 4.1 + user.set('p2pEnabled', body.webTorrentEnabled) + } + if (body.email !== undefined) { if (CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION) { user.pendingEmail = body.email -- cgit v1.2.3