Skip to content

Commit

Permalink
feat: 6167 Add autoplay setting in the admin settings section (#6788)
Browse files Browse the repository at this point in the history
* feat-6167: Add autoplay setting for new users in GUI admin section

* feat-6167: Add new localization for admin GUI

* Fix user configuration not taking default auto play setting into account when creating a new user

* Revert "feat-6167: Add new localization for admin GUI"

This reverts commit fcdb05c.

* Move autoplay in defaults section

---------

Co-authored-by: Chocobozzz <[email protected]>
  • Loading branch information
Khyvodul and Chocobozzz authored Jan 14, 2025
1 parent e4b6021 commit 1a568cc
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 2 deletions.
3 changes: 2 additions & 1 deletion client/src/app/core/users/user-local-storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,15 @@ export class UserLocalStorageService {

const defaultNSFWPolicy = htmlConfig.instance.defaultNSFWPolicy
const defaultP2PEnabled = htmlConfig.defaults.p2p.webapp.enabled
const defaultAutoPlay = htmlConfig.defaults.player.autoPlay

return {
nsfwPolicy: this.localStorageService.getItem<NSFWPolicyType>(UserLocalStorageKeys.NSFW_POLICY) || defaultNSFWPolicy,
p2pEnabled: getBoolOrDefault(this.localStorageService.getItem(UserLocalStorageKeys.P2P_ENABLED), defaultP2PEnabled),
theme: this.localStorageService.getItem(UserLocalStorageKeys.THEME) || 'instance-default',
videoLanguages,

autoPlayVideo: getBoolOrDefault(this.localStorageService.getItem(UserLocalStorageKeys.AUTO_PLAY_VIDEO), true),
autoPlayVideo: getBoolOrDefault(this.localStorageService.getItem(UserLocalStorageKeys.AUTO_PLAY_VIDEO), defaultAutoPlay),
autoPlayNextVideo: getBoolOrDefault(this.localStorageService.getItem(UserLocalStorageKeys.AUTO_PLAY_NEXT_VIDEO), false),
autoPlayNextVideoPlaylist: getBoolOrDefault(this.localStorageService.getItem(UserLocalStorageKeys.AUTO_PLAY_VIDEO_PLAYLIST), true)
}
Expand Down
4 changes: 4 additions & 0 deletions config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ defaults:
embed:
enabled: true

player:
# By default, playback starts automatically when opening a video
auto_play: true

# From the project root directory
storage:
tmp: 'storage/tmp/' # Use to download data (imports etc), store uploaded files before and during processing...
Expand Down
4 changes: 4 additions & 0 deletions config/production.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ defaults:
embed:
enabled: true

player:
# By default, playback starts automatically when opening a video
auto_play: true

# From the project root directory
storage:
tmp: '/var/www/peertube/storage/tmp/' # Use to download data (imports etc), store uploaded files before and during processing...
Expand Down
4 changes: 4 additions & 0 deletions packages/models/src/server/server-config.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export interface ServerConfig {
enabled: boolean
}
}

player: {
autoPlay: boolean
}
}

webadmin: {
Expand Down
43 changes: 43 additions & 0 deletions packages/tests/src/api/server/config-defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,50 @@ describe('Test config defaults', function () {
})
})

describe('Default player value', function () {

before(async function () {
const overrideConfig = {
defaults: {
player: {
auto_play: false
}
},
signup: {
limit: 15
}
}

await server.kill()
await server.run(overrideConfig)
})

it('Should have appropriate autoplay config', async function () {
const config = await server.config.getConfig()

expect(config.defaults.player.autoPlay).to.be.false
})

it('Should create a user with this default setting', async function () {
await server.users.create({ username: 'user_autoplay_1' })
const userToken = await server.login.getAccessToken('user_autoplay_1')

const { autoPlayVideo } = await server.users.getMyInfo({ token: userToken })
expect(autoPlayVideo).to.be.false
})

it('Should register a user with this default setting', async function () {
await server.registrations.register({ username: 'user_autoplay_2' })

const userToken = await server.login.getAccessToken('user_autoplay_2')

const { autoPlayVideo } = await server.users.getMyInfo({ token: userToken })
expect(autoPlayVideo).to.be.false
})
})

describe('Default user attributes', function () {

it('Should create a user and register a user with the default config', async function () {
await server.config.updateExistingConfig({
newConfig: {
Expand Down
1 change: 1 addition & 0 deletions server/core/initializers/checker-before-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function checkMissedConfig () {
'auto_blacklist.videos.of_users.enabled', 'trending.videos.interval_days',
'client.videos.miniature.prefer_author_display_name', 'client.menu.login.redirect_on_single_external_auth',
'defaults.publish.download_enabled', 'defaults.publish.comments_policy', 'defaults.publish.privacy', 'defaults.publish.licence',
'defaults.player.auto_play',
'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route',
'instance.is_nsfw', 'instance.default_nsfw_policy', 'instance.robots', 'instance.securitytxt',
'instance.server_country', 'instance.support.text', 'instance.social.external_link', 'instance.social.mastodon_link',
Expand Down
3 changes: 3 additions & 0 deletions server/core/initializers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ const CONFIG = {
EMBED: {
ENABLED: config.get<boolean>('defaults.p2p.embed.enabled')
}
},
PLAYER: {
get AUTO_PLAY () { return config.get<boolean>('defaults.player.auto_play') }
}
},

Expand Down
3 changes: 3 additions & 0 deletions server/core/lib/server-config-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class ServerConfigManager {
embed: {
enabled: CONFIG.DEFAULTS.P2P.EMBED.ENABLED
}
},
player: {
autoPlay: CONFIG.DEFAULTS.PLAYER.AUTO_PLAY
}
},

Expand Down
2 changes: 1 addition & 1 deletion server/core/lib/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function buildUser (options: {
p2pEnabled: CONFIG.DEFAULTS.P2P.WEBAPP.ENABLED,
videosHistoryEnabled: CONFIG.USER.HISTORY.VIDEOS.ENABLED,

autoPlayVideo: true,
autoPlayVideo: CONFIG.DEFAULTS.PLAYER.AUTO_PLAY,

role,
emailVerified,
Expand Down

0 comments on commit 1a568cc

Please sign in to comment.