Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/ability to disable video history by default #5728

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,17 @@

<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="Enable video history for new users"
wickloww marked this conversation as resolved.
Show resolved Hide resolved
>
</my-peertube-checkbox>
</ng-container>
</ng-container>
</div>
</ng-container>

</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
3 changes: 3 additions & 0 deletions config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,9 @@ signup:
blacklist: []

user:
history:
videos:
enabled: true
wickloww marked this conversation as resolved.
Show resolved Hide resolved
# 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
Expand Down
5 changes: 4 additions & 1 deletion config/production.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,10 @@ signup:
whitelist: []
blacklist: []

user:
user:
history:
videos:
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
Expand Down
5 changes: 5 additions & 0 deletions server/controllers/api/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
2 changes: 1 addition & 1 deletion server/initializers/checker-before-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 5 additions & 0 deletions server/initializers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')) }
},
Expand Down
2 changes: 2 additions & 0 deletions server/lib/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions server/middlewares/validators/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand Down
5 changes: 5 additions & 0 deletions server/tests/api/check-params/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ describe('Test config API validators', function () {
enabled: false
},
user: {
history: {
videos: {
enabled: true
}
},
videoQuota: 5242881,
videoQuotaDaily: 318742
},
Expand Down
7 changes: 7 additions & 0 deletions server/tests/api/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -298,6 +300,11 @@ const newCustomConfig: CustomConfig = {
enabled: false
},
user: {
history: {
videos: {
enabled: false
}
},
videoQuota: 5242881,
videoQuotaDaily: 318742
},
Expand Down
39 changes: 39 additions & 0 deletions server/tests/api/users/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,45 @@ describe('Test users', function () {
})
})

describe('Server configuration', function () {
const user2 = { username: 'user_2', password: 'super password' }
const user3 = { username: 'user_3', password: 'super password' }

let user2Token: string
let user3Token: string

it('Should create a new user with the default config', async function () {
await server.users.create({ ...user2 })
user2Token = await server.login.getAccessToken(user2)
wickloww marked this conversation as resolved.
Show resolved Hide resolved
const userMe = await server.users.getMyInfo({ token: user2Token })

expect(userMe.videosHistoryEnabled).to.be.true
})

it('Should update server config and create a new user', async function () {
await server.config.updateCustomSubConfig({
newConfig: {
user: {
history: {
videos: {
enabled: false
}
}
}
}
})

await server.users.create({ ...user3 })
})

it('Should have the new config in the new user information', async function () {
user3Token = await server.login.getAccessToken(user3)
const userMe = await server.users.getMyInfo({ token: user3Token })

expect(userMe.videosHistoryEnabled).to.be.false
})
})

after(async function () {
await cleanupTests([ server ])
})
Expand Down
6 changes: 6 additions & 0 deletions shared/models/server/custom-config.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ export interface CustomConfig {
}

user: {
history: {
videos: {
enabled: boolean
}
}
videoQuota: number
videoQuotaDaily: number
}
Expand Down Expand Up @@ -229,4 +234,5 @@ export interface CustomConfig {
isDefaultSearch: boolean
}
}

}
5 changes: 5 additions & 0 deletions shared/server-commands/server/config-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,11 @@ export class ConfigCommand extends AbstractCommand {
enabled: true
},
user: {
history: {
videos: {
enabled: true
}
},
videoQuota: 5242881,
videoQuotaDaily: 318742
},
Expand Down