From 9a7fd9600bf513adffbf2127be7c3a8b4d31073f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 20 May 2020 10:04:44 +0200 Subject: Fix external auth email/password update Also check if an actor does not already exist when creating the user --- .../my-account-change-email.component.html | 3 ++- .../my-account-settings/my-account-settings.component.html | 2 +- server/lib/oauth-model.ts | 8 ++++++++ server/middlewares/validators/users.ts | 9 +++++++-- server/tests/api/check-params/users.ts | 2 +- server/tests/api/videos/video-imports.ts | 2 +- server/tests/plugins/external-auth.ts | 10 ++++++++++ shared/extra-utils/users/users.ts | 4 ++-- 8 files changed, 32 insertions(+), 8 deletions(-) diff --git a/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.html b/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.html index f39f66696..ce176d682 100644 --- a/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.html +++ b/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.html @@ -9,7 +9,7 @@ {{ user.pendingEmail }} is awaiting email verification -
+
@@ -23,6 +23,7 @@
+
-
+
diff --git a/server/lib/oauth-model.ts b/server/lib/oauth-model.ts index e5ea4636e..db546efb1 100644 --- a/server/lib/oauth-model.ts +++ b/server/lib/oauth-model.ts @@ -14,6 +14,7 @@ import { UserAdminFlag } from '@shared/models/users/user-flag.model' import { createUserAccountAndChannelAndPlaylist } from './user' import { UserRole } from '@shared/models/users/user-role' import { PluginManager } from '@server/lib/plugins/plugin-manager' +import { ActorModel } from '@server/models/activitypub/actor' type TokenInfo = { accessToken: string, refreshToken: string, accessTokenExpiresAt: Date, refreshTokenExpiresAt: Date } @@ -109,6 +110,9 @@ async function getUser (usernameOrEmail?: string, password?: string) { let user = await UserModel.loadByEmail(obj.user.email) if (!user) user = await createUserFromExternal(obj.pluginName, obj.user) + // Cannot create a user + if (!user) throw new AccessDeniedError('Cannot create such user: an actor with that name already exists.') + // If the user does not belongs to a plugin, it was created before its installation // Then we just go through a regular login process if (user.pluginAuth !== null) { @@ -208,6 +212,10 @@ async function createUserFromExternal (pluginAuth: string, options: { role: UserRole displayName: string }) { + // Check an actor does not already exists with that name (removed user) + const actor = await ActorModel.loadLocalByName(options.username) + if (actor) return null + const userToCreate = new UserModel({ username: options.username, password: null, diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index 840b9fc74..3bdbcdf6a 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts @@ -234,14 +234,19 @@ const usersUpdateMeValidator = [ async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking usersUpdateMe parameters', { parameters: omit(req.body, 'password') }) + const user = res.locals.oauth.token.User + if (req.body.password || req.body.email) { + if (user.pluginAuth !== null) { + return res.status(400) + .json({ error: 'You cannot update your email or password that is associated with an external auth system.' }) + } + if (!req.body.currentPassword) { return res.status(400) .json({ error: 'currentPassword parameter is missing.' }) - .end() } - const user = res.locals.oauth.token.User if (await user.isPasswordMatch(req.body.currentPassword) !== true) { return res.status(401) .json({ error: 'currentPassword is invalid.' }) diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 4d597f0a3..6e737af15 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -1044,7 +1044,7 @@ describe('Test users API validators', function () { } await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() })) await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() })) - await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' })) + await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' as any })) await waitJobs([ server ]) diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index 4d5989f43..d211859e4 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -175,7 +175,7 @@ Ajouter un sous-titre est vraiment facile`) { const attributes = immutableAssign(baseAttributes, { - torrentfile: 'video-720p.torrent', + torrentfile: 'video-720p.torrent' as any, description: 'this is a super torrent description', tags: [ 'tag_torrent1', 'tag_torrent2' ] }) diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts index a85672782..57361be05 100644 --- a/server/tests/plugins/external-auth.ts +++ b/server/tests/plugins/external-auth.ts @@ -255,6 +255,16 @@ describe('Test external auth plugins', function () { expect(body.role).to.equal(UserRole.USER) }) + it('Should not update an external auth email', async function () { + await updateMyUser({ + url: server.url, + accessToken: cyanAccessToken, + email: 'toto@example.com', + currentPassword: 'toto', + statusCodeExpected: 400 + }) + }) + it('Should reject token of Kefka by the plugin hook', async function () { this.timeout(10000) diff --git a/shared/extra-utils/users/users.ts b/shared/extra-utils/users/users.ts index 54b506bce..08b7743a6 100644 --- a/shared/extra-utils/users/users.ts +++ b/shared/extra-utils/users/users.ts @@ -216,7 +216,7 @@ function unblockUser (url: string, userId: number | string, accessToken: string, .expect(expectedStatus) } -function updateMyUser (options: { url: string, accessToken: string } & UserUpdateMe) { +function updateMyUser (options: { url: string, accessToken: string, statusCodeExpected?: number } & UserUpdateMe) { const path = '/api/v1/users/me' const toSend: UserUpdateMe = omit(options, 'url', 'accessToken') @@ -226,7 +226,7 @@ function updateMyUser (options: { url: string, accessToken: string } & UserUpdat path, token: options.accessToken, fields: toSend, - statusCodeExpected: 204 + statusCodeExpected: options.statusCodeExpected || 204 }) } -- cgit v1.2.3 From 619443a3f68d9415754dcf89a025bde407bf16fd Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 20 May 2020 10:22:18 +0200 Subject: Fix sort icons in table --- client/src/sass/primeng-custom.scss | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client/src/sass/primeng-custom.scss b/client/src/sass/primeng-custom.scss index d48f2dfc4..33483533e 100644 --- a/client/src/sass/primeng-custom.scss +++ b/client/src/sass/primeng-custom.scss @@ -140,13 +140,13 @@ p-table { font-size: 11px !important; top: 0 !important; - &.pi-sort-up { + &.pi-sort-amount-up-alt { @extend .glyphicon-triangle-top; color: var(--mainForegroundColor) !important; } - &.pi-sort-down { + &.pi-sort-amount-down { @extend .glyphicon-triangle-bottom; color: var(--mainForegroundColor) !important; @@ -302,12 +302,12 @@ p-table { @if $mobile-paginator { p-paginator .ui-paginator-bottom { display: block; - + .ui-paginator-current { position: relative; display: block; } - + a, .ui-paginator-pages { vertical-align: middle; } @@ -345,7 +345,7 @@ p-multiselect { } } - .pi.pi-chevron-down{ + .pi.pi-chevron-down { margin-left: 0 !important; &::after { -- cgit v1.2.3 From 572bf73be68f63ac28beb27bde289925c15be239 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 20 May 2020 10:29:40 +0200 Subject: Fix action button overflow in tables --- .../src/app/+admin/follows/followers-list/followers-list.component.html | 2 +- .../video-redundancies-list/video-redundancies-list.component.html | 2 +- .../instance-blocklist/instance-account-blocklist.component.html | 2 +- .../instance-blocklist/instance-server-blocklist.component.html | 2 +- .../+admin/moderation/video-abuse-list/video-abuse-list.component.html | 2 +- .../moderation/video-blacklist-list/video-blacklist-list.component.html | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client/src/app/+admin/follows/followers-list/followers-list.component.html b/client/src/app/+admin/follows/followers-list/followers-list.component.html index 93378a533..298871fce 100644 --- a/client/src/app/+admin/follows/followers-list/followers-list.component.html +++ b/client/src/app/+admin/follows/followers-list/followers-list.component.html @@ -23,7 +23,7 @@ State Score Created - + diff --git a/client/src/app/+admin/follows/video-redundancies-list/video-redundancies-list.component.html b/client/src/app/+admin/follows/video-redundancies-list/video-redundancies-list.component.html index 28d57f83c..c08154bcd 100644 --- a/client/src/app/+admin/follows/video-redundancies-list/video-redundancies-list.component.html +++ b/client/src/app/+admin/follows/video-redundancies-list/video-redundancies-list.component.html @@ -22,7 +22,7 @@ Strategy Video Total size - + diff --git a/client/src/app/+admin/moderation/instance-blocklist/instance-account-blocklist.component.html b/client/src/app/+admin/moderation/instance-blocklist/instance-account-blocklist.component.html index a4ab2a58c..b7d40be60 100644 --- a/client/src/app/+admin/moderation/instance-blocklist/instance-account-blocklist.component.html +++ b/client/src/app/+admin/moderation/instance-blocklist/instance-account-blocklist.component.html @@ -21,7 +21,7 @@ Account Muted at - + diff --git a/client/src/app/+admin/moderation/instance-blocklist/instance-server-blocklist.component.html b/client/src/app/+admin/moderation/instance-blocklist/instance-server-blocklist.component.html index dab068dd6..589a11b7b 100644 --- a/client/src/app/+admin/moderation/instance-blocklist/instance-server-blocklist.component.html +++ b/client/src/app/+admin/moderation/instance-blocklist/instance-server-blocklist.component.html @@ -25,7 +25,7 @@ Instance Muted at - + diff --git a/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.html b/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.html index 1c9530152..d30475794 100644 --- a/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.html +++ b/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.html @@ -41,7 +41,7 @@ Video Created State - + diff --git a/client/src/app/+admin/moderation/video-blacklist-list/video-blacklist-list.component.html b/client/src/app/+admin/moderation/video-blacklist-list/video-blacklist-list.component.html index c4c4e765a..cfa04514f 100644 --- a/client/src/app/+admin/moderation/video-blacklist-list/video-blacklist-list.component.html +++ b/client/src/app/+admin/moderation/video-blacklist-list/video-blacklist-list.component.html @@ -25,7 +25,7 @@ Sensitive Unfederated Date - + -- cgit v1.2.3 From 6189b699fbc2d428d6baf09473356ed4568ea2a6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 20 May 2020 10:37:46 +0200 Subject: Fix broken client when cookies are disabled --- client/src/app/shared/misc/peertube-web-storage.ts | 42 ++++++++++++---------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/client/src/app/shared/misc/peertube-web-storage.ts b/client/src/app/shared/misc/peertube-web-storage.ts index fff209678..6a152dd98 100644 --- a/client/src/app/shared/misc/peertube-web-storage.ts +++ b/client/src/app/shared/misc/peertube-web-storage.ts @@ -47,26 +47,32 @@ try { peertubeLocalStorage = localStorage peertubeSessionStorage = sessionStorage } catch (err) { - const instance = new MemoryStorage() + const instanceLocalStorage = new MemoryStorage() + const instanceSessionStorage = new MemoryStorage() - peertubeLocalStorage = sessionStorage = new Proxy(instance, { - set: function (obj, prop: string | number, value) { - if (MemoryStorage.prototype.hasOwnProperty(prop)) { - instance[prop] = value - } else { - instance.setItem(prop, value) + function proxify (instance: MemoryStorage) { + return new Proxy(instance, { + set: function (obj, prop: string | number, value) { + if (MemoryStorage.prototype.hasOwnProperty(prop)) { + instance[prop] = value + } else { + instance.setItem(prop, value) + } + return true + }, + get: function (target, name: string | number) { + if (MemoryStorage.prototype.hasOwnProperty(name)) { + return instance[name] + } + if (valuesMap.has(name)) { + return instance.getItem(name) + } } - return true - }, - get: function (target, name: string | number) { - if (MemoryStorage.prototype.hasOwnProperty(name)) { - return instance[name] - } - if (valuesMap.has(name)) { - return instance.getItem(name) - } - } - }) + }) + } + + peertubeLocalStorage = proxify(instanceLocalStorage) + peertubeSessionStorage = proxify(instanceSessionStorage) } export { -- cgit v1.2.3 From b66c5e58f13c790a8933117b0f8ba73ed37c1855 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 20 May 2020 10:57:59 +0200 Subject: Fix upload button color in dark mode --- client/src/app/header/header.component.scss | 1 - 1 file changed, 1 deletion(-) diff --git a/client/src/app/header/header.component.scss b/client/src/app/header/header.component.scss index 91b390773..1e4ce2c56 100644 --- a/client/src/app/header/header.component.scss +++ b/client/src/app/header/header.component.scss @@ -10,7 +10,6 @@ my-search-typeahead { @include orange-button; @include button-with-icon(22px, 3px, -1px); - color: var(--mainBackgroundColor) !important; margin-right: 25px; @media screen and (max-width: 600px) { -- cgit v1.2.3 From 3bf07dd8c27aa6ef40111c6f055e8975b3f514f4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 20 May 2020 11:39:31 +0200 Subject: Explicit theme colors for inputs and textarea --- client/src/app/shared/forms/markdown-textarea.component.scss | 1 - client/src/sass/application.scss | 2 ++ client/src/sass/include/_mixins.scss | 4 ++++ client/src/sass/include/_variables.scss | 4 ++++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/client/src/app/shared/forms/markdown-textarea.component.scss b/client/src/app/shared/forms/markdown-textarea.component.scss index 8e5739e45..5c6657538 100644 --- a/client/src/app/shared/forms/markdown-textarea.component.scss +++ b/client/src/app/shared/forms/markdown-textarea.component.scss @@ -14,7 +14,6 @@ $input-border-radius: 3px; textarea { @include peertube-textarea(100%, 150px); - background-color: var(--textareaBackgroundColor); font-family: monospace; font-size: 13px; border-bottom: none; diff --git a/client/src/sass/application.scss b/client/src/sass/application.scss index d637c94d9..039353077 100644 --- a/client/src/sass/application.scss +++ b/client/src/sass/application.scss @@ -35,9 +35,11 @@ body { --menuForegroundColor: #{$menu-color}; --submenuColor: #{$sub-menu-color}; + --inputForegroundColor: #{$input-foreground-color}; --inputBackgroundColor: #{$input-background-color}; --inputPlaceholderColor: #{$input-placeholder-color}; + --textareaForegroundColor: #{$textarea-foreground-color}; --textareaBackgroundColor: #{$textarea-background-color}; --actionButtonColor: #{$grey-foreground-color}; diff --git a/client/src/sass/include/_mixins.scss b/client/src/sass/include/_mixins.scss index f157ded5e..87b7edaad 100644 --- a/client/src/sass/include/_mixins.scss +++ b/client/src/sass/include/_mixins.scss @@ -90,6 +90,7 @@ display: inline-block; height: $button-height; width: $width; + color: var(--inputForegroundColor); background: var(--inputBackgroundColor); border: 1px solid #C6C6C6; border-radius: 3px; @@ -121,6 +122,8 @@ @mixin peertube-textarea ($width, $height) { @include peertube-input-text($width); + color: var(--textareaForegroundColor); + background-color: var(--textareaBackgroundColor); height: $height; padding: 5px 15px; font-size: 15px; @@ -280,6 +283,7 @@ margin: 0; width: $width; border-radius: 3px; + color: var(--inputForegroundColor); background: var(--inputBackgroundColor); position: relative; font-size: 15px; diff --git a/client/src/sass/include/_variables.scss b/client/src/sass/include/_variables.scss index 46f1e99f7..9b441dcfe 100644 --- a/client/src/sass/include/_variables.scss +++ b/client/src/sass/include/_variables.scss @@ -63,9 +63,11 @@ $video-thumbnail-ratio: $video-thumbnail-width / $video-thumbnail-height; $theater-bottom-space: 115px; +$input-foreground-color: $fg-color; $input-background-color: $bg-color; $input-placeholder-color: #898989; +$textarea-foreground-color: $fg-color; $textarea-background-color: $grey-background-hover-color; $sub-menu-margin-bottom: 30px; @@ -92,9 +94,11 @@ $variables: ( --menuForegroundColor: var(--menuForegroundColor), --submenuColor: var(--submenuColor), + --inputForegroundColor: var(--inputForegroundColor), --inputBackgroundColor: var(--inputBackgroundColor), --inputPlaceholderColor: var(--inputPlaceholderColor), + --textareaForegroundColor: var(--textareaForegroundColor), --textareaBackgroundColor: var(--textareaBackgroundColor), --actionButtonColor: var(--actionButtonColor), -- cgit v1.2.3 From e0433a5f8f9346080b24d73d17c9f8fcb660a5d1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 20 May 2020 11:58:03 +0200 Subject: Fix dropdown menu overflow --- .../app/videos/+video-watch/comment/video-comments.component.html | 8 ++++---- .../app/videos/+video-watch/comment/video-comments.component.scss | 4 ++-- client/src/sass/bootstrap.scss | 2 ++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/client/src/app/videos/+video-watch/comment/video-comments.component.html b/client/src/app/videos/+video-watch/comment/video-comments.component.html index a21042f09..affbd4793 100644 --- a/client/src/app/videos/+video-watch/comment/video-comments.component.html +++ b/client/src/app/videos/+video-watch/comment/video-comments.component.html @@ -12,10 +12,10 @@
- -
+
@@ -72,7 +72,7 @@ >
- + @@ -83,7 +83,7 @@ View {{ comment.totalReplies }} replies - +
diff --git a/client/src/app/videos/+video-watch/comment/video-comments.component.scss b/client/src/app/videos/+video-watch/comment/video-comments.component.scss index 5ed1ac629..df42fae73 100644 --- a/client/src/app/videos/+video-watch/comment/video-comments.component.scss +++ b/client/src/app/videos/+video-watch/comment/video-comments.component.scss @@ -21,7 +21,7 @@ .title-page { margin-right: 0; } - + my-feed { display: inline-block; margin-left: 5px; @@ -33,7 +33,7 @@ } } -#dropdownSortComments { +#dropdown-sort-comments { font-weight: 600; text-transform: uppercase; border: none; diff --git a/client/src/sass/bootstrap.scss b/client/src/sass/bootstrap.scss index cb266cc68..7985472ed 100644 --- a/client/src/sass/bootstrap.scss +++ b/client/src/sass/bootstrap.scss @@ -37,6 +37,8 @@ $icon-font-path: '~@neos21/bootstrap3-glyphicons/assets/fonts/'; } .dropdown-menu { + z-index: z(dropdown) + 1 !important; + border-radius: 3px; box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12), 0 3px 1px -2px rgba(0, 0, 0, 0.2); font-size: 15px; -- cgit v1.2.3 From f33dc6ab2db1c733f09dcb039b8bf46c69854753 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 20 May 2020 13:52:12 +0200 Subject: Fix input/textarea themes --- client/src/app/shared/forms/markdown-textarea.component.scss | 2 ++ client/src/sass/application.scss | 1 + client/src/sass/include/_mixins.scss | 2 +- client/src/sass/include/_variables.scss | 4 +++- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/client/src/app/shared/forms/markdown-textarea.component.scss b/client/src/app/shared/forms/markdown-textarea.component.scss index 5c6657538..16f319587 100644 --- a/client/src/app/shared/forms/markdown-textarea.component.scss +++ b/client/src/app/shared/forms/markdown-textarea.component.scss @@ -14,6 +14,8 @@ $input-border-radius: 3px; textarea { @include peertube-textarea(100%, 150px); + background-color: var(--markdownTextareaBackgroundColor); + font-family: monospace; font-size: 13px; border-bottom: none; diff --git a/client/src/sass/application.scss b/client/src/sass/application.scss index 039353077..17ed5c8f8 100644 --- a/client/src/sass/application.scss +++ b/client/src/sass/application.scss @@ -41,6 +41,7 @@ body { --textareaForegroundColor: #{$textarea-foreground-color}; --textareaBackgroundColor: #{$textarea-background-color}; + --markdownTextareaBackgroundColor: #{$markdown-textarea-background-color}; --actionButtonColor: #{$grey-foreground-color}; --supportButtonBackgroundColor: #{transparent}; diff --git a/client/src/sass/include/_mixins.scss b/client/src/sass/include/_mixins.scss index 87b7edaad..99ca25f9c 100644 --- a/client/src/sass/include/_mixins.scss +++ b/client/src/sass/include/_mixins.scss @@ -91,7 +91,7 @@ height: $button-height; width: $width; color: var(--inputForegroundColor); - background: var(--inputBackgroundColor); + background-color: var(--inputBackgroundColor); border: 1px solid #C6C6C6; border-radius: 3px; padding-left: 15px; diff --git a/client/src/sass/include/_variables.scss b/client/src/sass/include/_variables.scss index 9b441dcfe..cdac8ae6f 100644 --- a/client/src/sass/include/_variables.scss +++ b/client/src/sass/include/_variables.scss @@ -68,7 +68,8 @@ $input-background-color: $bg-color; $input-placeholder-color: #898989; $textarea-foreground-color: $fg-color; -$textarea-background-color: $grey-background-hover-color; +$textarea-background-color: $bg-color; +$markdown-textarea-background-color: $grey-background-hover-color; $sub-menu-margin-bottom: 30px; $sub-menu-margin-bottom-small-view: 10px; @@ -100,6 +101,7 @@ $variables: ( --textareaForegroundColor: var(--textareaForegroundColor), --textareaBackgroundColor: var(--textareaBackgroundColor), + --markdownTextareaBackgroundColor: var(--markdownTextareaBackgroundColor), --actionButtonColor: var(--actionButtonColor), --supportButtonColor: var(--supportButtonColor), -- cgit v1.2.3