-
Notifications
You must be signed in to change notification settings - Fork 13.7k
fix: External avatar url provider for rooms not respected. #28910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dd10af0
use setting
gabriellsh 09db4da
Add tests
gabriellsh 0ee68fe
that's what I get for copying code
gabriellsh 198750e
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into fix/…
gabriellsh 9540bd5
fix
gabriellsh 4961dc0
Merge branch 'develop' into fix/externalAvatarProvider
gabriellsh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import type { IRoom } from '@rocket.chat/core-typings'; | ||
|
|
||
| import { getAvatarURL } from './getAvatarURL'; | ||
| /* This import throws a lint error because the export is behind a conditional that is treated by meteor as a runtime check. | ||
| We can't specify client/server folder here because this function can be used by both */ | ||
| // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
| // @ts-ignore | ||
| import { settings } from '../../settings'; | ||
|
|
||
| export const getRoomAvatarURL = ({ roomId, cache = '' }: { roomId: IRoom['_id']; cache: IRoom['avatarETag'] }) => { | ||
| const externalSource = (settings.get('Accounts_RoomAvatarExternalProviderUrl') || '').trim().replace(/\/$/, ''); | ||
| if (externalSource !== '') { | ||
| return externalSource.replace('{roomId}', roomId); | ||
| } | ||
| if (roomId == null) { | ||
| return; | ||
| } | ||
|
|
||
| return getAvatarURL({ roomId, cache }); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import { Users } from './fixtures/userStates'; | ||
| import { HomeChannel } from './page-objects'; | ||
| import { createTargetChannel, createTargetPrivateChannel, createDirectMessage } from './utils'; | ||
| import { setSettingValueById } from './utils/setSettingValueById'; | ||
| import { test, expect } from './utils/test'; | ||
|
|
||
| test.use({ storageState: Users.admin.state }); | ||
|
|
||
| const testAvatars = (homeChannel: HomeChannel, channel: string, url: string) => { | ||
| test('expect sidebar avatar to have provider prefix', async () => { | ||
| expect(homeChannel.sidenav.getSidebarItemByName(channel).locator('img').getAttribute('src')).toBe(url); | ||
| }); | ||
|
|
||
| test('expect channel header avatar to have provider prefix', async () => { | ||
| await homeChannel.sidenav.openChat(channel); | ||
| expect(homeChannel.content.channelHeader.locator('img').getAttribute('src')).toBe(url); | ||
| }); | ||
|
|
||
| test('expect channel info avatar to have provider prefix', async () => { | ||
| await homeChannel.sidenav.openChat(channel); | ||
| expect(homeChannel.content.channelHeader.locator('img').getAttribute('src')).toBe(url); | ||
| }); | ||
| } | ||
|
|
||
| test.describe('avatar-settings', () => { | ||
| let poHomeChannel: HomeChannel; | ||
|
|
||
| test.beforeEach(async ({ page }) => { | ||
| poHomeChannel = new HomeChannel(page); | ||
|
|
||
| await page.goto('/home'); | ||
| }); | ||
|
|
||
| test.describe('external avatar provider', () => { | ||
| const providerUrlPrefix = 'https://example.com/avatar/'; | ||
|
|
||
| test.beforeAll(async ({ api }) => { | ||
| await setSettingValueById(api, 'Accounts_RoomAvatarExternalUrl', `${providerUrlPrefix}{username}`); | ||
| await setSettingValueById(api, 'Accounts_AvatarExternalUrl', `${providerUrlPrefix}{username}`); | ||
| }); | ||
|
|
||
| test.afterAll(async ({ api }) => { | ||
| await setSettingValueById(api, 'Accounts_RoomAvatarExternalUrl', ''); | ||
| await setSettingValueById(api, 'Accounts_AvatarExternalUrl', ''); | ||
| }) | ||
|
|
||
| test.describe('public channels', () => { | ||
| let channelName = ''; | ||
| let avatarUrl = ''; | ||
|
|
||
| test.beforeAll(async ({ api }) => { | ||
| channelName = await createTargetChannel(api); | ||
| avatarUrl = `${providerUrlPrefix}${channelName}`; | ||
| }); | ||
|
|
||
| testAvatars(poHomeChannel, channelName, avatarUrl); | ||
| }); | ||
|
|
||
| test.describe('private channels', () => { | ||
| let channelName = ''; | ||
| let avatarUrl = ''; | ||
|
|
||
| test.beforeAll(async ({ api }) => { | ||
| channelName = await createTargetPrivateChannel(api); | ||
| avatarUrl = `${providerUrlPrefix}${channelName}`; | ||
| }); | ||
|
|
||
| testAvatars(poHomeChannel, channelName, avatarUrl); | ||
| }); | ||
|
|
||
| test.describe('direct messages', () => { | ||
| const channelName = Users.user2.data.username; | ||
| const avatarUrl = `${providerUrlPrefix}${channelName}`; | ||
|
|
||
| test.beforeAll(async ({ api }) => { | ||
| await createDirectMessage(api); | ||
|
|
||
| // send a message as user 2 | ||
| test.use({ storageState: Users.user2.state }); | ||
| await poHomeChannel.sidenav.openChat(Users.user1.data.username); | ||
| await poHomeChannel.content.sendMessage('hello world'); | ||
|
|
||
| test.use({ storageState: Users.user1.state }); | ||
| }); | ||
|
|
||
| testAvatars(poHomeChannel, channelName, avatarUrl); | ||
|
|
||
| test('expect message avatar to have provider prefix', async () => { | ||
| expect(poHomeChannel.content.lastUserMessage.locator('img').getAttribute('src')).toBe(avatarUrl); | ||
| }); | ||
|
|
||
| test('expect user card avatar to have provider prefix', async () => { | ||
| await poHomeChannel.content.lastUserMessage.locator('.rcx-message-header__name-container').click(); | ||
| expect(poHomeChannel.content.userCard.locator('img').getAttribute('src')).toBe(avatarUrl); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.