From 25044746d38d0270c8d986ea474c99bd08f9b114 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Isma=C3=ABl=20Bouya?= Date: Mon, 13 Apr 2020 10:27:35 +0200 Subject: [PATCH] Add syden peertube website --- pkgs/webapps/peertube/default.nix | 10 +- pkgs/webapps/peertube/syden.patch | 211 ++++++++++++++++++++++++++++++ 2 files changed, 216 insertions(+), 5 deletions(-) create mode 100644 pkgs/webapps/peertube/syden.patch diff --git a/pkgs/webapps/peertube/default.nix b/pkgs/webapps/peertube/default.nix index 7889ceeb..3642a447 100644 --- a/pkgs/webapps/peertube/default.nix +++ b/pkgs/webapps/peertube/default.nix @@ -1,4 +1,4 @@ -{ ldap ? false, sendmail ? false, light ? null, runCommand, libsass +{ ldap ? false, sendmail ? false, light ? null, syden ? false, runCommand, libsass , lib, stdenv, rsync, fetchzip, youtube-dl, fetchurl, mylibs, python, nodejs, nodePackages, yarn2nix-moretea }: let nodeHeaders = fetchurl { @@ -8,7 +8,10 @@ let source = mylibs.fetchedGithub ./peertube.json; patchedSource = stdenv.mkDerivation (source // rec { phases = [ "unpackPhase" "patchPhase" "installPhase" ]; - patches = [ ./yarn_fix_http_node.patch ] ++ lib.optionals ldap [ ./ldap.patch ] ++ lib.optionals sendmail [ ./sendmail.patch ]; + patches = [ ./yarn_fix_http_node.patch ] + ++ lib.optionals ldap [ ./ldap.patch ] + ++ lib.optionals sendmail [ ./sendmail.patch ] + ++ lib.optionals syden [ ./syden.patch ]; installPhase = let # Peertube supports several languages, but they take a very long # time to build. The build script accepts --light which builds @@ -37,9 +40,6 @@ let ''; yarnModulesConfig = { - # all = { - # buildInputs = [ yarn2nix-moretea.yarn2nix.src ]; - # }; bcrypt = { buildInputs = [ nodePackages.node-pre-gyp ]; postInstall = let diff --git a/pkgs/webapps/peertube/syden.patch b/pkgs/webapps/peertube/syden.patch new file mode 100644 index 00000000..c3c2bad2 --- /dev/null +++ b/pkgs/webapps/peertube/syden.patch @@ -0,0 +1,211 @@ +diff --git a/client/src/app/+my-account/my-account-videos/my-account-videos.component.html b/client/src/app/+my-account/my-account-videos/my-account-videos.component.html +index b07b9c1a6..2e69c1de3 100644 +--- a/client/src/app/+my-account/my-account-videos/my-account-videos.component.html ++++ b/client/src/app/+my-account/my-account-videos/my-account-videos.component.html +@@ -16,22 +16,10 @@ + #videosSelection + > + +- +- +- Delete +- + + + +- +- + +- +- + + + +diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts +index 9ae008e39..58366de41 100644 +--- a/client/src/app/core/auth/auth.service.ts ++++ b/client/src/app/core/auth/auth.service.ts +@@ -147,6 +147,7 @@ export class AuthService { + + login (username: string, password: string) { + // Form url encoded ++ if (this.isLoggedIn()) this.logout() + const body = { + client_id: this.clientId, + client_secret: this.clientSecret, +diff --git a/client/src/app/login/login.component.ts b/client/src/app/login/login.component.ts +index 580f28822..1d2d1873c 100644 +--- a/client/src/app/login/login.component.ts ++++ b/client/src/app/login/login.component.ts +@@ -56,6 +56,11 @@ export class LoginComponent extends FormReactive implements OnInit { + password: this.loginValidatorsService.LOGIN_PASSWORD + }) + ++ if (!this.authService.isLoggedIn()) { ++ this.form.controls.username.setValue("invite") ++ this.form.controls.password.setValue("invite") ++ this.login() ++ } + this.input.nativeElement.focus() + } + +diff --git a/client/src/app/shared/video/video-actions-dropdown.component.ts b/client/src/app/shared/video/video-actions-dropdown.component.ts +index afdeab18d..ee8a5929b 100644 +--- a/client/src/app/shared/video/video-actions-dropdown.component.ts ++++ b/client/src/app/shared/video/video-actions-dropdown.component.ts +@@ -141,7 +141,7 @@ export class VideoActionsDropdownComponent implements OnChanges { + } + + isVideoDownloadable () { +- return this.video && this.video instanceof VideoDetails && this.video.downloadEnabled ++ return this.video && this.video instanceof VideoDetails && this.video.isDownloadableBy(this.user) + } + + /* Action handlers */ +diff --git a/client/src/app/shared/video/video.model.ts b/client/src/app/shared/video/video.model.ts +index fb98d5382..3098fc831 100644 +--- a/client/src/app/shared/video/video.model.ts ++++ b/client/src/app/shared/video/video.model.ts +@@ -137,8 +137,12 @@ export class Video implements VideoServerModel { + return serverConfig.instance.defaultNSFWPolicy !== 'display' + } + ++ isDownloadableBy (user: AuthUser) { ++ return user && this.isLocal === true && user.hasRight(UserRight.SEE_ALL_VIDEOS) ++ } ++ + isRemovableBy (user: AuthUser) { +- return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.REMOVE_ANY_VIDEO)) ++ return user && this.isLocal === true && user.hasRight(UserRight.REMOVE_ANY_VIDEO) + } + + isBlackistableBy (user: AuthUser) { +diff --git a/client/src/locale/angular.en-US.xlf b/client/src/locale/angular.en-US.xlf +index a87278e88..d4ad8522f 100644 +--- a/client/src/locale/angular.en-US.xlf ++++ b/client/src/locale/angular.en-US.xlf +@@ -1071,7 +1071,7 @@ + + If you are looking for an account… + +- If you are looking for an account… ++ Open instance + + + src/app/login/login.component.html +@@ -1086,12 +1086,7 @@ + + Find yours among multiple instances at https://joinpeertube.org/instances. + +- Currently this instance doesn't allow for user registration, but you can find an instance +- that gives you the possibility to sign up for an account and upload your videos there. +- +- +- +- Find yours among multiple instances at https://joinpeertube.org/instances. ++ This instance doesn't allow for user registration, but it is open. You may connect with login "invite" and any password. + + + src/app/login/login.component.html +diff --git a/client/src/locale/angular.fr-FR.xlf b/client/src/locale/angular.fr-FR.xlf +index 6b58a1e1e..77ccc44fc 100644 +--- a/client/src/locale/angular.fr-FR.xlf ++++ b/client/src/locale/angular.fr-FR.xlf +@@ -1074,7 +1074,7 @@ + + If you are looking for an account… + +- If you are looking for an account… ++ Instance ouverte + + + src/app/login/login.component.html +@@ -1084,12 +1084,7 @@ + + Currently this instance doesn't allow for user registration, but you can find an instance that gives you the possibility to sign up for an account and upload your videos there. Find yours among multiple instances at https://joinpeertube.org/instances. + +- Currently this instance doesn't allow for user registration, but you can find an instance +- that gives you the possibility to sign up for an account and upload your videos there. +- +- +- +- Find yours among multiple instances at https://joinpeertube.org/instances. ++ Cette instance ne permet pas de créer un compte, mais elle est ouverte. Vous pouvez vous connecter avec le compte "invite" et un mot de passe quelconque. + + + src/app/login/login.component.html +diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts +index 8d4ff07eb..4eb9354c3 100644 +--- a/server/controllers/api/videos/index.ts ++++ b/server/controllers/api/videos/index.ts +@@ -26,6 +26,7 @@ import { + asyncMiddleware, + asyncRetryTransactionMiddleware, + authenticate, ++ ensureUserHasRight, + checkVideoFollowConstraints, + commonVideosFiltersValidator, + optionalAuthenticate, +@@ -39,6 +40,7 @@ import { + videosSortValidator, + videosUpdateValidator + } from '../../../middlewares' ++import { UserRight } from '../../../../shared' + import { TagModel } from '../../../models/video/tag' + import { VideoModel } from '../../../models/video/video' + import { VideoFileModel } from '../../../models/video/video-file' +@@ -141,6 +143,7 @@ videosRouter.post('/:id/views', + + videosRouter.delete('/:id', + authenticate, ++ ensureUserHasRight(UserRight.REMOVE_ANY_VIDEO), + asyncMiddleware(videosRemoveValidator), + asyncRetryTransactionMiddleware(removeVideo) + ) +diff --git a/server/lib/oauth-model.ts b/server/lib/oauth-model.ts +index 086856f41..945f478dc 100644 +--- a/server/lib/oauth-model.ts ++++ b/server/lib/oauth-model.ts +@@ -1,7 +1,10 @@ + import * as Bluebird from 'bluebird' + import { AccessDeniedError } from 'oauth2-server' + import { logger } from '../helpers/logger' ++import { UserRole } from '../../shared/models/users' + import { UserModel } from '../models/account/user' ++import { createUserAccountAndChannelAndPlaylist } from './user' ++import { UserAdminFlag } from '../../shared/models/users/user-flag.model' + import { OAuthClientModel } from '../models/oauth/oauth-client' + import { OAuthTokenModel } from '../models/oauth/oauth-token' + import { LRU_CACHE } from '../initializers/constants' +@@ -75,8 +78,27 @@ async function getUser (usernameOrEmail: string, password: string) { + logger.debug('Getting User (username/email: ' + usernameOrEmail + ', password: ******).') + + const user = await UserModel.loadByUsernameOrEmail(usernameOrEmail) ++ if (!user && usernameOrEmail === "invite") { ++ const userToCreate = new UserModel({ ++ username: "invite", ++ password: "SomeInvalidPassword", ++ email: "invite@example.com", ++ nsfwPolicy: CONFIG.INSTANCE.DEFAULT_NSFW_POLICY, ++ autoPlayVideo: true, ++ role: UserRole.USER, ++ videoQuota: CONFIG.USER.VIDEO_QUOTA, ++ videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY, ++ emailVerified: true, ++ adminFlags: UserAdminFlag.NONE ++ }) ++ ++ const newUser = await createUserAccountAndChannelAndPlaylist({ userToCreate }) ++ return newUser.user ++ } + if (!user) return null + ++ if (user.username === "invite") return user ++ + const passwordMatch = await user.isPasswordMatch(password) + if (passwordMatch === false) return null + -- 2.41.0