ActivityPub-federated video streaming platform using P2P directly in your web browser
Add ability to redirect users on external auth
Chocobozzz0bc53e20296d
diff --git a/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html b/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.htmlindex 318c8e2c28..c9533208a1 100644--- a/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html+++ b/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.html@@ -56,6 +56,36 @@</ng-container></div>+ <ng-container formGroupName="client">++ <ng-container formGroupName="videos">+ <ng-container formGroupName="miniature">+ <div class="form-group">+ <my-peertube-checkbox+ inputName="clientVideosMiniaturePreferAuthorDisplayName" formControlName="preferAuthorDisplayName"+ i18n-labelText labelText="Prefer author display name in video miniature"+ ></my-peertube-checkbox>+ </div>+ </ng-container>+ </ng-container>++ <ng-container formGroupName="menu">+ <ng-container formGroupName="login">+ <div class="form-group">+ <my-peertube-checkbox+ inputName="clientMenuLoginRedirectOnSingleExternalAuth" formControlName="redirectOnSingleExternalAuth"+ i18n-labelText labelText="Redirect users on single external auth when users click on the login button in menu"+ >+ <ng-container ngProjectAs="description">+ <span *ngIf="countExternalAuth() === 0" i18n>⚠️ You don't have any external auth plugin enabled.</span>+ <span *ngIf="countExternalAuth() > 1" i18n>⚠️ You have multiple external auth plugins enabled.</span>+ </ng-container>+ </my-peertube-checkbox>+ </div>+ </ng-container>+ </ng-container>+ </ng-container>+</div></div>@@ -276,7 +306,7 @@<div class="form-group col-12 col-lg-4 col-xl-3"><div i18n class="inner-form-title">VIDEO CHANNELS</div></div>-+<div class="form-group form-group-right col-12 col-lg-8 col-xl-9"><div class="form-group" formGroupName="videoChannels"><label i18n for="videoChannelsMaxPerUser">Max video channels per user</label>diff --git a/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts b/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.tsindex 7a8258820c..81457bd367 100644--- a/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts+++ b/client/src/app/+admin/config/edit-custom-config/edit-basic-configuration.component.ts@@ -36,6 +36,10 @@ export class EditBasicConfigurationComponent implements OnInit, OnChanges {}}+ countExternalAuth () {+ return this.serverConfig.plugin.registeredExternalAuths.length+ }+getVideoQuotaOptions () {return this.configService.videoQuotaOptions}diff --git a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.tsindex fdb0a75327..f2eaa30339 100644--- a/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts+++ b/client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts@@ -106,6 +106,18 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {whitelisted: null}},+ client: {+ videos: {+ miniature: {+ preferAuthorDisplayName: null+ }+ },+ menu: {+ login: {+ redirectOnSingleExternalAuth: null+ }+ }+ },cache: {previews: {size: CACHE_PREVIEWS_SIZE_VALIDATORdiff --git a/client/src/app/+login/login.component.ts b/client/src/app/+login/login.component.tsindex 1fa4bd3b5f..648b8db36a 100644--- a/client/src/app/+login/login.component.ts+++ b/client/src/app/+login/login.component.ts@@ -1,4 +1,4 @@-import { environment } from 'src/environments/environment'+import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core'import { ActivatedRoute } from '@angular/router'import { AuthService, Notifier, RedirectService, UserService } from '@app/core'@@ -7,6 +7,7 @@ import { LOGIN_PASSWORD_VALIDATOR, LOGIN_USERNAME_VALIDATOR } from '@app/shared/import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'import { InstanceAboutAccordionComponent } from '@app/shared/shared-instance'import { NgbAccordion, NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'+import { PluginsManager } from '@root-helpers/plugins-manager'import { RegisteredExternalAuthConfig, ServerConfig } from '@shared/models'@Component({@@ -98,7 +99,7 @@ export class LoginComponent extends FormReactive implements OnInit, AfterViewIni}getAuthHref (auth: RegisteredExternalAuthConfig) {- return environment.apiUrl + `/plugins/${auth.name}/${auth.version}/auth/${auth.authName}`+ return PluginsManager.getExternalAuthHref(auth)}login () {diff --git a/client/src/app/menu/menu.component.html b/client/src/app/menu/menu.component.htmlindex 55fc27b5f4..9ea9910429 100644--- a/client/src/app/menu/menu.component.html+++ b/client/src/app/menu/menu.component.html@@ -99,7 +99,9 @@</div><div *ngIf="!isLoggedIn" class="login-buttons-block">- <a i18n routerLink="/login" class="peertube-button-link orange-button">Login</a>+ <a i18n *ngIf="!getExternalLoginHref()" routerLink="/login" class="peertube-button-link orange-button">Login</a>+ <a i18n *ngIf="getExternalLoginHref()" [href]="getExternalLoginHref()" class="peertube-button-link orange-button">Login</a>+<a i18n *ngIf="isRegistrationAllowed()" routerLink="/signup" class="peertube-button-link create-account-button">Create an account</a></div>diff --git a/client/src/app/menu/menu.component.ts b/client/src/app/menu/menu.component.tsindex 97f07c956e..bcc8848785 100644--- a/client/src/app/menu/menu.component.ts+++ b/client/src/app/menu/menu.component.ts@@ -21,6 +21,7 @@ import { LanguageChooserComponent } from '@app/menu/language-chooser.component'import { QuickSettingsModalComponent } from '@app/modal/quick-settings-modal.component'import { PeertubeModalService } from '@app/shared/shared-main/peertube-modal/peertube-modal.service'import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap'+import { PluginsManager } from '@root-helpers/plugins-manager'import { HTMLServerConfig, ServerConfig, UserRight, VideoConstant } from '@shared/models'const logger = debug('peertube:menu:MenuComponent')@@ -129,6 +130,15 @@ export class MenuComponent implements OnInit {.subscribe(() => this.openQuickSettings())}+ getExternalLoginHref () {+ if (this.serverConfig.client.menu.login.redirectOnSingleExternalAuth !== true) return undefined++ const externalAuths = this.serverConfig.plugin.registeredExternalAuths+ if (externalAuths.length !== 1) return undefined++ return PluginsManager.getExternalAuthHref(externalAuths[0])+ }+isRegistrationAllowed () {if (!this.serverConfig) return falsediff --git a/client/src/root-helpers/plugins-manager.ts b/client/src/root-helpers/plugins-manager.tsindex a1b763ff23..9cba633738 100644--- a/client/src/root-helpers/plugins-manager.ts+++ b/client/src/root-helpers/plugins-manager.ts@@ -15,6 +15,7 @@ import {RegisterClientHookOptions,RegisterClientSettingsScript,RegisterClientVideoFieldOptions,+ RegisteredExternalAuthConfig,ServerConfigPlugin} from '../../../shared/models'import { environment } from '../environments/environment'@@ -78,6 +79,11 @@ class PluginsManager {return isTheme ? '/themes' : '/plugins'}+ static getExternalAuthHref (auth: RegisteredExternalAuthConfig) {+ return environment.apiUrl + `/plugins/${auth.name}/${auth.version}/auth/${auth.authName}`++ }+loadPluginsList (config: HTMLServerConfig) {for (const plugin of config.plugin.registered) {this.addPlugin(plugin)diff --git a/config/default.yaml b/config/default.yamlindex b9c725cea1..0749511174 100644--- a/config/default.yaml+++ b/config/default.yaml@@ -82,6 +82,12 @@ client:# By default PeerTube client displays author usernameprefer_author_display_name: false+ menu:+ login:+ # If you enable only one external auth plugin+ # You can automatically redirect your users on this external platform when they click on the login button+ redirect_on_single_external_auth: false+# From the project root directorystorage:tmp: 'storage/tmp/' # Use to download data (imports etc), store uploaded files before and during processing...diff --git a/config/production.yaml.example b/config/production.yaml.exampleindex d67349c1dc..e38b79587c 100644--- a/config/production.yaml.example+++ b/config/production.yaml.example@@ -80,6 +80,12 @@ client:# By default PeerTube client displays author usernameprefer_author_display_name: false+ menu:+ login:+ # If you enable only one external auth plugin+ # You can automatically redirect your users on this external platform when they click on the login button+ redirect_on_single_external_auth: false+# From the project root directorystorage:tmp: '/var/www/peertube/storage/tmp/' # Use to download data (imports etc), store uploaded files before and during processing...diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.tsindex 805ad99c7e..b253db3970 100644--- a/server/controllers/api/config.ts+++ b/server/controllers/api/config.ts@@ -169,6 +169,18 @@ function customConfig (): CustomConfig {whitelisted: CONFIG.SERVICES.TWITTER.WHITELISTED}},+ client: {+ videos: {+ miniature: {+ preferAuthorDisplayName: CONFIG.CLIENT.VIDEOS.MINIATURE.PREFER_AUTHOR_DISPLAY_NAME+ }+ },+ menu: {+ login: {+ redirectOnSingleExternalAuth: CONFIG.CLIENT.MENU.LOGIN.REDIRECT_ON_SINGLE_EXTERNAL_AUTH+ }+ }+ },cache: {previews: {size: CONFIG.CACHE.PREVIEWS.SIZEdiff --git a/server/initializers/checker-before-init.ts b/server/initializers/checker-before-init.tsindex 51c3965483..c85c389cd9 100644--- a/server/initializers/checker-before-init.ts+++ b/server/initializers/checker-before-init.ts@@ -33,6 +33,7 @@ function checkMissedConfig () {'transcoding.resolutions.2160p','import.videos.http.enabled', 'import.videos.torrent.enabled', 'import.videos.concurrency', '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','instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route','instance.is_nsfw', 'instance.default_nsfw_policy', 'instance.robots', 'instance.securitytxt','services.twitter.username', 'services.twitter.whitelisted',diff --git a/server/initializers/config.ts b/server/initializers/config.tsindex f3a7c6b6b4..eb848be6b9 100644--- a/server/initializers/config.ts+++ b/server/initializers/config.ts@@ -63,6 +63,11 @@ const CONFIG = {MINIATURE: {get PREFER_AUTHOR_DISPLAY_NAME () { return config.get<boolean>('client.videos.miniature.prefer_author_display_name') }}+ },+ MENU: {+ LOGIN: {+ get REDIRECT_ON_SINGLE_EXTERNAL_AUTH () { return config.get<boolean>('client.menu.login.redirect_on_single_external_auth') }+ }}},diff --git a/server/lib/server-config-manager.ts b/server/lib/server-config-manager.tsindex bdf6492f98..6aa459f82d 100644--- a/server/lib/server-config-manager.ts+++ b/server/lib/server-config-manager.ts@@ -47,6 +47,11 @@ class ServerConfigManager {miniature: {preferAuthorDisplayName: CONFIG.CLIENT.VIDEOS.MINIATURE.PREFER_AUTHOR_DISPLAY_NAME}+ },+ menu: {+ login: {+ redirectOnSingleExternalAuth: CONFIG.CLIENT.MENU.LOGIN.REDIRECT_ON_SINGLE_EXTERNAL_AUTH+ }}},diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.tsindex d0cd7722b7..a6e87730a5 100644--- a/server/tests/api/check-params/config.ts+++ b/server/tests/api/check-params/config.ts@@ -54,6 +54,18 @@ describe('Test config API validators', function () {whitelisted: true}},+ client: {+ videos: {+ miniature: {+ preferAuthorDisplayName: false+ }+ },+ menu: {+ login: {+ redirectOnSingleExternalAuth: false+ }+ }+ },cache: {previews: {size: 2diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.tsindex ea524723cf..96ec17b0fc 100644--- a/server/tests/api/server/config.ts+++ b/server/tests/api/server/config.ts@@ -43,6 +43,9 @@ function checkInitialConfig (server: PeerTubeServer, data: CustomConfig) {expect(data.services.twitter.username).to.equal('@Chocobozzz')expect(data.services.twitter.whitelisted).to.be.false+ expect(data.client.videos.miniature.preferAuthorDisplayName).to.be.false+ expect(data.client.menu.login.redirectOnSingleExternalAuth).to.be.false+expect(data.cache.previews.size).to.equal(1)expect(data.cache.captions.size).to.equal(1)expect(data.cache.torrents.size).to.equal(1)@@ -138,6 +141,9 @@ function checkUpdatedConfig (data: CustomConfig) {expect(data.services.twitter.username).to.equal('@Kuja')expect(data.services.twitter.whitelisted).to.be.true+ expect(data.client.videos.miniature.preferAuthorDisplayName).to.be.true+ expect(data.client.menu.login.redirectOnSingleExternalAuth).to.be.true+expect(data.cache.previews.size).to.equal(2)expect(data.cache.captions.size).to.equal(3)expect(data.cache.torrents.size).to.equal(4)@@ -246,6 +252,18 @@ const newCustomConfig: CustomConfig = {whitelisted: true}},+ client: {+ videos: {+ miniature: {+ preferAuthorDisplayName: true+ }+ },+ menu: {+ login: {+ redirectOnSingleExternalAuth: true+ }+ }+ },cache: {previews: {size: 2diff --git a/shared/extra-utils/server/config-command.ts b/shared/extra-utils/server/config-command.tsindex 7a768b4df4..a061ca89e8 100644--- a/shared/extra-utils/server/config-command.ts+++ b/shared/extra-utils/server/config-command.ts@@ -194,6 +194,18 @@ export class ConfigCommand extends AbstractCommand {whitelisted: true}},+ client: {+ videos: {+ miniature: {+ preferAuthorDisplayName: false+ }+ },+ menu: {+ login: {+ redirectOnSingleExternalAuth: false+ }+ }+ },cache: {previews: {size: 2diff --git a/shared/models/server/custom-config.model.ts b/shared/models/server/custom-config.model.tsindex 3ed9324946..52d3d95888 100644--- a/shared/models/server/custom-config.model.ts+++ b/shared/models/server/custom-config.model.ts@@ -52,6 +52,20 @@ export interface CustomConfig {}}+ client: {+ videos: {+ miniature: {+ preferAuthorDisplayName: boolean+ }+ }++ menu: {+ login: {+ redirectOnSingleExternalAuth: boolean+ }+ }+ }+cache: {previews: {size: numberdiff --git a/shared/models/server/server-config.model.ts b/shared/models/server/server-config.model.tsindex e75eefd47b..9f17276e0a 100644--- a/shared/models/server/server-config.model.ts+++ b/shared/models/server/server-config.model.ts@@ -39,6 +39,12 @@ export interface ServerConfig {preferAuthorDisplayName: boolean}}++ menu: {+ login: {+ redirectOnSingleExternalAuth: boolean+ }+ }}webadmin: {