From b302c80dc0d9ba8eabef9ef6576efe36afc57584 Mon Sep 17 00:00:00 2001 From: Wicklow <123956049+wickloww@users.noreply.github.com> Date: Fri, 7 Apr 2023 08:09:54 +0000 Subject: feature/ability to disable video history by default (#5728) * draft: ability to disable video history by default * Update configuration and add tests * Updated code based on review comments * Add tests on registration and video quota * Remove required video quotas in query * Fix tests --- server/tests/api/check-params/config.ts | 5 ++ server/tests/api/check-params/users-admin.ts | 12 ----- server/tests/api/server/config-defaults.ts | 78 ++++++++++++++++++++++++++++ server/tests/api/server/config.ts | 7 +++ 4 files changed, 90 insertions(+), 12 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index 93a3f3eb9..f49a4b868 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts @@ -90,6 +90,11 @@ describe('Test config API validators', function () { enabled: false }, user: { + history: { + videos: { + enabled: true + } + }, videoQuota: 5242881, videoQuotaDaily: 318742 }, diff --git a/server/tests/api/check-params/users-admin.ts b/server/tests/api/check-params/users-admin.ts index be2496bb4..819da0bb2 100644 --- a/server/tests/api/check-params/users-admin.ts +++ b/server/tests/api/check-params/users-admin.ts @@ -216,18 +216,6 @@ describe('Test users admin API validators', function () { }) }) - it('Should fail without a videoQuota', async function () { - const fields = omit(baseCorrectParams, [ 'videoQuota' ]) - - await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) - }) - - it('Should fail without a videoQuotaDaily', async function () { - const fields = omit(baseCorrectParams, [ 'videoQuotaDaily' ]) - - await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) - }) - it('Should fail with an invalid videoQuota', async function () { const fields = { ...baseCorrectParams, videoQuota: -5 } diff --git a/server/tests/api/server/config-defaults.ts b/server/tests/api/server/config-defaults.ts index d3b3a2447..041032f2b 100644 --- a/server/tests/api/server/config-defaults.ts +++ b/server/tests/api/server/config-defaults.ts @@ -204,6 +204,84 @@ describe('Test config defaults', function () { }) }) + describe('Default user attributes', function () { + it('Should create a user and register a user with the default config', async function () { + await server.config.updateCustomSubConfig({ + newConfig: { + user: { + history: { + videos: { + enabled: true + } + }, + videoQuota : -1, + videoQuotaDaily: -1 + }, + signup: { + enabled: true, + requiresApproval: false + } + } + }) + + const config = await server.config.getConfig() + + expect(config.user.videoQuota).to.equal(-1) + expect(config.user.videoQuotaDaily).to.equal(-1) + + const user1Token = await server.users.generateUserAndToken('user1') + const user1 = await server.users.getMyInfo({ token: user1Token }) + + const user = { displayName: 'super user 2', username: 'user2', password: 'super password' } + const channel = { name: 'my_user_2_channel', displayName: 'my channel' } + await server.registrations.register({ ...user, channel }) + const user2Token = await server.login.getAccessToken(user) + const user2 = await server.users.getMyInfo({ token: user2Token }) + + for (const user of [ user1, user2 ]) { + expect(user.videosHistoryEnabled).to.be.true + expect(user.videoQuota).to.equal(-1) + expect(user.videoQuotaDaily).to.equal(-1) + } + }) + + it('Should update config and create a user and register a user with the new default config', async function () { + await server.config.updateCustomSubConfig({ + newConfig: { + user: { + history: { + videos: { + enabled: false + } + }, + videoQuota : 5242881, + videoQuotaDaily: 318742 + }, + signup: { + enabled: true, + requiresApproval: false + } + } + }) + + const user3Token = await server.users.generateUserAndToken('user3') + const user3 = await server.users.getMyInfo({ token: user3Token }) + + const user = { displayName: 'super user 4', username: 'user4', password: 'super password' } + const channel = { name: 'my_user_4_channel', displayName: 'my channel' } + await server.registrations.register({ ...user, channel }) + const user4Token = await server.login.getAccessToken(user) + const user4 = await server.users.getMyInfo({ token: user4Token }) + + for (const user of [ user3, user4 ]) { + expect(user.videosHistoryEnabled).to.be.false + expect(user.videoQuota).to.equal(5242881) + expect(user.videoQuotaDaily).to.equal(318742) + } + }) + + }) + after(async function () { await cleanupTests([ server ]) }) diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index de7c2f6e2..3683c4ae1 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -56,6 +56,7 @@ function checkInitialConfig (server: PeerTubeServer, data: CustomConfig) { expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com') expect(data.contactForm.enabled).to.be.true + expect(data.user.history.videos.enabled).to.be.true expect(data.user.videoQuota).to.equal(5242880) expect(data.user.videoQuotaDaily).to.equal(-1) @@ -164,6 +165,7 @@ function checkUpdatedConfig (data: CustomConfig) { expect(data.contactForm.enabled).to.be.false + expect(data.user.history.videos.enabled).to.be.false expect(data.user.videoQuota).to.equal(5242881) expect(data.user.videoQuotaDaily).to.equal(318742) @@ -298,6 +300,11 @@ const newCustomConfig: CustomConfig = { enabled: false }, user: { + history: { + videos: { + enabled: false + } + }, videoQuota: 5242881, videoQuotaDaily: 318742 }, -- cgit v1.2.3