Add ability to redirect users on external auth

pull/4616/head
Chocobozzz 2021-12-03 17:04:47 +01:00
parent d1a233d8d8
commit 0bc53e2029
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
18 changed files with 166 additions and 4 deletions

View File

@ -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>

View File

@ -36,6 +36,10 @@ export class EditBasicConfigurationComponent implements OnInit, OnChanges {
}
}
countExternalAuth () {
return this.serverConfig.plugin.registeredExternalAuths.length
}
getVideoQuotaOptions () {
return this.configService.videoQuotaOptions
}

View File

@ -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_VALIDATOR

View File

@ -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 () {

View File

@ -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>

View File

@ -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 false

View File

@ -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)

View File

@ -82,6 +82,12 @@ client:
# By default PeerTube client displays author username
prefer_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 directory
storage:
tmp: 'storage/tmp/' # Use to download data (imports etc), store uploaded files before and during processing...

View File

@ -80,6 +80,12 @@ client:
# By default PeerTube client displays author username
prefer_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 directory
storage:
tmp: '/var/www/peertube/storage/tmp/' # Use to download data (imports etc), store uploaded files before and during processing...

View File

@ -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.SIZE

View File

@ -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',

View File

@ -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') }
}
}
},

View File

@ -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
}
}
},

View File

@ -54,6 +54,18 @@ describe('Test config API validators', function () {
whitelisted: true
}
},
client: {
videos: {
miniature: {
preferAuthorDisplayName: false
}
},
menu: {
login: {
redirectOnSingleExternalAuth: false
}
}
},
cache: {
previews: {
size: 2

View File

@ -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: 2

View File

@ -194,6 +194,18 @@ export class ConfigCommand extends AbstractCommand {
whitelisted: true
}
},
client: {
videos: {
miniature: {
preferAuthorDisplayName: false
}
},
menu: {
login: {
redirectOnSingleExternalAuth: false
}
}
},
cache: {
previews: {
size: 2

View File

@ -52,6 +52,20 @@ export interface CustomConfig {
}
}
client: {
videos: {
miniature: {
preferAuthorDisplayName: boolean
}
}
menu: {
login: {
redirectOnSingleExternalAuth: boolean
}
}
}
cache: {
previews: {
size: number

View File

@ -39,6 +39,12 @@ export interface ServerConfig {
preferAuthorDisplayName: boolean
}
}
menu: {
login: {
redirectOnSingleExternalAuth: boolean
}
}
}
webadmin: {