]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
feature/ability to disable video history by default (#5728)
authorWicklow <123956049+wickloww@users.noreply.github.com>
Fri, 7 Apr 2023 08:09:54 +0000 (08:09 +0000)
committerGitHub <noreply@github.com>
Fri, 7 Apr 2023 08:09:54 +0000 (10:09 +0200)
* 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

18 files changed:
client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html
client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts
config/default.yaml
config/production.yaml.example
server/controllers/api/config.ts
server/initializers/checker-before-init.ts
server/initializers/config.ts
server/lib/user.ts
server/middlewares/validators/config.ts
server/middlewares/validators/users.ts
server/tests/api/check-params/config.ts
server/tests/api/check-params/users-admin.ts
server/tests/api/server/config-defaults.ts
server/tests/api/server/config.ts
shared/models/server/custom-config.model.ts
shared/server-commands/server/config-command.ts
shared/server-commands/users/users-command.ts
support/doc/api/openapi.yaml

index 8399b5d56bcb277f94d94a790f0767ff4a7af572..9fc3323087c6b9f19a66c5de43d04b953164a739 100644 (file)
 
           <div *ngIf="formErrors.user.videoQuotaDaily" class="form-error">{{ formErrors.user.videoQuotaDaily }}</div>
         </div>
+        <div class="form-group">
+          <ng-container formGroupName="history">
+            <ng-container formGroupName="videos">
+              <my-peertube-checkbox
+                inputName="videosHistoryEnabled" formControlName="enabled"
+                i18n-labelText labelText="Automatically enable video history for new users"
+              >
+              </my-peertube-checkbox>
+            </ng-container>
+          </ng-container>
+        </div>
       </ng-container>
 
     </div>
index 2afe80a037011d226fc24a98707daa6bb32d6ea4..0526ed8f11362344c7046ccb83d2afc3b3a5aa71 100644 (file)
@@ -165,6 +165,11 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
         enabled: null
       },
       user: {
+        history: {
+          videos: {
+            enabled: null
+          }
+        },
         videoQuota: USER_VIDEO_QUOTA_VALIDATOR,
         videoQuotaDaily: USER_VIDEO_QUOTA_DAILY_VALIDATOR
       },
index db014cc87e54f2a39ecb0d7b109875cdba65b1e1..dfa43a0aab331255968b0a90f8903a805276edf8 100644 (file)
@@ -408,6 +408,10 @@ signup:
       blacklist: []
 
 user:
+  history:
+    videos:
+      # Enable or disable video history by default for new users.
+      enabled: true
   # Default value of maximum video bytes the user can upload (does not take into account transcoded files)
   # Byte format is supported ("1GB" etc)
   # -1 == unlimited
index 9cb8add1f77a9ceb2971d495c159050303af2b87..744a14e91b93dede5292577bd02138f741afc1ea 100644 (file)
@@ -417,7 +417,11 @@ signup:
       whitelist: []
       blacklist: []
 
-user:
+user:  
+  history:
+    videos:
+      # Enable or disable video history by default for new users.
+      enabled: true
   # Default value of maximum video bytes the user can upload (does not take into account transcoded files)
   # Byte format is supported ("1GB" etc)
   # -1 == unlimited
index 86434f382fbf24799fa2a331425449ca131727ab..60d168d1218ceab5f1fcb80453d51ad653a54a65 100644 (file)
@@ -204,6 +204,11 @@ function customConfig (): CustomConfig {
       enabled: CONFIG.CONTACT_FORM.ENABLED
     },
     user: {
+      history: {
+        videos: {
+          enabled: CONFIG.USER.HISTORY.VIDEOS.ENABLED
+        }
+      },
       videoQuota: CONFIG.USER.VIDEO_QUOTA,
       videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY
     },
index 1351749a646062e91ae5ed027ebcd3037ceb4005..49010c0592f4b60c8f0f228919fc1385653e9cec 100644 (file)
@@ -24,7 +24,7 @@ function checkMissedConfig () {
     'open_telemetry.metrics.enabled', 'open_telemetry.metrics.prometheus_exporter.hostname',
     'open_telemetry.metrics.prometheus_exporter.port', 'open_telemetry.tracing.enabled', 'open_telemetry.tracing.jaeger_exporter.endpoint',
     'open_telemetry.metrics.http_request_duration.enabled',
-    'user.video_quota', 'user.video_quota_daily',
+    'user.history.videos.enabled', 'user.video_quota', 'user.video_quota_daily',
     'video_channels.max_per_user',
     'csp.enabled', 'csp.report_only', 'csp.report_uri',
     'security.frameguard.enabled', 'security.powered_by_header.enabled',
index eb9d0079cabc9f6af3ce817981a1a7af26f724df..e2442213cec17aaef9eb313dbeb0456b569974e7 100644 (file)
@@ -324,6 +324,11 @@ const CONFIG = {
     }
   },
   USER: {
+    HISTORY: {
+      VIDEOS: {
+        get ENABLED () { return config.get<boolean>('user.history.videos.enabled') }
+      }
+    },
     get VIDEO_QUOTA () { return parseBytes(config.get<number>('user.video_quota')) },
     get VIDEO_QUOTA_DAILY () { return parseBytes(config.get<number>('user.video_quota_daily')) }
   },
index ffb57944a3bccbc1ebb941a0a49d26ed466fb24a..56995cca33f5b527a2d8b6a489f3357e8b1feafa 100644 (file)
@@ -56,6 +56,8 @@ function buildUser (options: {
 
     nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY,
     p2pEnabled: CONFIG.DEFAULTS.P2P.WEBAPP.ENABLED,
+    videosHistoryEnabled: CONFIG.USER.HISTORY.VIDEOS.ENABLED,
+
     autoPlayVideo: true,
 
     role,
index c2dbfadb75dc4a70560c27739597e858dfdf7371..4a9d1cb5472cba777ea534461d231d5f77243b79 100644 (file)
@@ -35,6 +35,7 @@ const customConfigUpdateValidator = [
   body('admin.email').isEmail(),
   body('contactForm.enabled').isBoolean(),
 
+  body('user.history.videos.enabled').isBoolean(),
   body('user.videoQuota').custom(isUserVideoQuotaValid),
   body('user.videoQuotaDaily').custom(isUserVideoQuotaDailyValid),
 
index f7033f44a6c6605e26c93ed905bf34671fa28684..7ebea048d338905d2e2babd75149e5947d954533 100644 (file)
@@ -65,8 +65,11 @@ const usersAddValidator = [
     .custom(isVideoChannelUsernameValid),
 
   body('videoQuota')
+    .optional()
     .custom(isUserVideoQuotaValid),
+
   body('videoQuotaDaily')
+    .optional()
     .custom(isUserVideoQuotaDailyValid),
 
   body('role')
index 93a3f3eb9c3a18418e1b64f3050cc575bc830acc..f49a4b86814e4b10c0b70cc24af86b81bbf80c12 100644 (file)
@@ -90,6 +90,11 @@ describe('Test config API validators', function () {
       enabled: false
     },
     user: {
+      history: {
+        videos: {
+          enabled: true
+        }
+      },
       videoQuota: 5242881,
       videoQuotaDaily: 318742
     },
index be2496bb47be80b9b9394289ee82977e238e6bd6..819da0bb2d0368c4e75c969c286ccccf7e608560 100644 (file)
@@ -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 }
 
index d3b3a24475ee16ad0c60b6ee373e5da37b59631c..041032f2bd0bf8dad4129f682930cfeb4c67af7d 100644 (file)
@@ -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 ])
   })
index de7c2f6e28320e379865123cf0e4e3be8954e82a..3683c4ae12b5d2ac192a19fe2b6ea5fe041f6b50 100644 (file)
@@ -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
   },
index 846bf6159f9364ba40d2adda3a8e7f582557618f..6ffe3a676a4a732d57544411fe14be25832fc07b 100644 (file)
@@ -97,6 +97,11 @@ export interface CustomConfig {
   }
 
   user: {
+    history: {
+      videos: {
+        enabled: boolean
+      }
+    }
     videoQuota: number
     videoQuotaDaily: number
   }
@@ -229,4 +234,5 @@ export interface CustomConfig {
       isDefaultSearch: boolean
     }
   }
+
 }
index eb6bb95a5a46971156bec778199b856a4b263b16..303fcab88adc02e8d1fc85877791a9e0410cd90c 100644 (file)
@@ -350,6 +350,11 @@ export class ConfigCommand extends AbstractCommand {
         enabled: true
       },
       user: {
+        history: {
+          videos: {
+            enabled: true
+          }
+        },
         videoQuota: 5242881,
         videoQuotaDaily: 318742
       },
index 8a42fafc817a65503e59ac5f5acad2e68cc0c6d7..5b39d3488751383852136bd13dadd61bd753d653 100644 (file)
@@ -165,8 +165,8 @@ export class UsersCommand extends AbstractCommand {
       username,
       adminFlags,
       password = 'password',
-      videoQuota = 42000000,
-      videoQuotaDaily = -1,
+      videoQuota,
+      videoQuotaDaily,
       role = UserRole.USER
     } = options
 
index 959a70438fc145dd2abe3c9548b8c028f1014bde..046eec5445a23f8ac8fb793449916bd849aa9b20 100644 (file)
@@ -7894,8 +7894,6 @@ components:
         - username
         - password
         - email
-        - videoQuota
-        - videoQuotaDaily
         - role
     UpdateUser:
       properties: