]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Add ability to redirect users on external auth
authorChocobozzz <me@florianbigard.com>
Fri, 3 Dec 2021 16:04:47 +0000 (17:04 +0100)
committerChocobozzz <me@florianbigard.com>
Fri, 3 Dec 2021 16:04:47 +0000 (17:04 +0100)
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-basic-configuration.component.ts
client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts
client/src/app/+login/login.component.ts
client/src/app/menu/menu.component.html
client/src/app/menu/menu.component.ts
client/src/root-helpers/plugins-manager.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/server-config-manager.ts
server/tests/api/check-params/config.ts
server/tests/api/server/config.ts
shared/extra-utils/server/config-command.ts
shared/models/server/custom-config.model.ts
shared/models/server/server-config.model.ts

index 318c8e2c28847d73b755e3d1b7ade4e13bef8268..c9533208a14fb73a559c2feac0e2eeed7b48feed 100644 (file)
         </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>
 
     <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>
index 7a8258820cfcc635e2a0b7c8ae24d16d470358c8..81457bd3672a2e191af606f51c7744d3cf1de6ee 100644 (file)
@@ -36,6 +36,10 @@ export class EditBasicConfigurationComponent implements OnInit, OnChanges {
     }
   }
 
+  countExternalAuth () {
+    return this.serverConfig.plugin.registeredExternalAuths.length
+  }
+
   getVideoQuotaOptions () {
     return this.configService.videoQuotaOptions
   }
index fdb0a753270bce4c578bfdb523a1582c21b9c568..f2eaa30339f08bb903792cf2825f6e47e7033232 100644 (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
index 1fa4bd3b5f4092b08e6ad106b5a7e9d937ec8a82..648b8db36a8608b59f910f29efb52f68214e8b40 100644 (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 () {
index 55fc27b5f410b239ef6bbdcae5f29d4a2f14563a..9ea991042971021e8e1be60963f4bc7bd8269415 100644 (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>
 
index 97f07c956edcb8d612f05dfa604cd06150ba802c..bcc88487856d9aff1877b2bbcd9bdeb2e992e095 100644 (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
 
index a1b763ff2336e95d021dbc639a3781b082e04b96..9cba633738254321066562c6c314dab8ec3b87da 100644 (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)
index b9c725cea1eb846f2bc91645ad54e3e9c431c00e..0749511174d87ffb2dec02546782e6aacd08a88a 100644 (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...
index d67349c1dcb2e4fb9a152e922dd4c55a45db5cce..e38b79587c3813b577ec271bc5d326ab111cd922 100644 (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...
index 805ad99c7e0d48ddad6fec74f17ea0e440585cb3..b253db397056e510b1ae889af589f0ecaee44965 100644 (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
index 51c39654839709f5efa7d86a77047775e1818b49..c85c389cd98430da954f8cb564e1d839e951fceb 100644 (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',
index f3a7c6b6b42b9b8d6eb17f96f33ba5df3883e1be..eb848be6b9c5d0fd722b5474aa911caa22946aad 100644 (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') }
+      }
     }
   },
 
index bdf6492f98b3b540bbd19371cc6c96466a81915a..6aa459f82dd9b5b2f075a7473fd62a356e4fd8c3 100644 (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
+          }
         }
       },
 
index d0cd7722b7c48d8b8626af0164ee018bfee6077e..a6e87730a5c5ddfa19977db713395365dcbd3586 100644 (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
index ea524723cfee2d20976fba22ffd87c7fb8e80f92..96ec17b0fce77cb2be2ec9badf49454d1fb818a9 100644 (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
index 7a768b4df4151bd03e7d44f181cc2e7ffc8e4181..a061ca89e8e239523a5b8a85495d8affa96fed44 100644 (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
index 3ed93249460c7a553456d6d30df27e21c936112e..52d3d958884cc2a8a516826f966e983b876f4ac5 100644 (file)
@@ -52,6 +52,20 @@ export interface CustomConfig {
     }
   }
 
+  client: {
+    videos: {
+      miniature: {
+        preferAuthorDisplayName: boolean
+      }
+    }
+
+    menu: {
+      login: {
+        redirectOnSingleExternalAuth: boolean
+      }
+    }
+  }
+
   cache: {
     previews: {
       size: number
index e75eefd47b05922f3d9e3e0e1b9c786e439adb81..9f17276e0ae9fb6bdb90af9dcb5e73f604eba288 100644 (file)
@@ -39,6 +39,12 @@ export interface ServerConfig {
         preferAuthorDisplayName: boolean
       }
     }
+
+    menu: {
+      login: {
+        redirectOnSingleExternalAuth: boolean
+      }
+    }
   }
 
   webadmin: {