Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions apps/meteor/app/utils/lib/getRoomAvatarURL.ts
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) {
Comment thread
gabriellsh marked this conversation as resolved.
Outdated
return;
}

return getAvatarURL({ roomId, cache });
};
4 changes: 2 additions & 2 deletions apps/meteor/client/lib/rooms/roomTypes/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { hasPermission } from '../../../../app/authorization/client';
import { ChatRoom } from '../../../../app/models/client';
import { settings } from '../../../../app/settings/client';
import { getUserPreference } from '../../../../app/utils/client';
import { getAvatarURL } from '../../../../app/utils/lib/getAvatarURL';
import { getRoomAvatarURL } from '../../../../app/utils/lib/getRoomAvatarURL';
import type { IRoomTypeClientDirectives } from '../../../../definition/IRoomTypeConfig';
import { RoomSettingsEnum, RoomMemberActions, UiTextContext } from '../../../../definition/IRoomTypeConfig';
import { getPrivateRoomType } from '../../../../lib/rooms/roomTypes/private';
Expand Down Expand Up @@ -87,7 +87,7 @@ roomCoordinator.add(
},

getAvatarPath(room) {
return getAvatarURL({ roomId: room._id, cache: room.avatarETag }) as string;
return getRoomAvatarURL({ roomId: room._id, cache: room.avatarETag }) as string;
Comment thread
gabriellsh marked this conversation as resolved.
Outdated
},

getIcon(room) {
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/client/lib/rooms/roomTypes/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { hasAtLeastOnePermission } from '../../../../app/authorization/client';
import { ChatRoom } from '../../../../app/models/client';
import { settings } from '../../../../app/settings/client';
import { getUserPreference } from '../../../../app/utils/client';
import { getAvatarURL } from '../../../../app/utils/lib/getAvatarURL';
import { getRoomAvatarURL } from '../../../../app/utils/lib/getRoomAvatarURL';
import type { IRoomTypeClientDirectives } from '../../../../definition/IRoomTypeConfig';
import { RoomSettingsEnum, RoomMemberActions, UiTextContext } from '../../../../definition/IRoomTypeConfig';
import { getPublicRoomType } from '../../../../lib/rooms/roomTypes/public';
Expand Down Expand Up @@ -87,7 +87,7 @@ roomCoordinator.add(
},

getAvatarPath(room) {
return getAvatarURL({ roomId: room._id, cache: room.avatarETag }) as string;
return getRoomAvatarURL({ roomId: room._id, cache: room.avatarETag }) as string;
Comment thread
gabriellsh marked this conversation as resolved.
Outdated
},

getIcon(room) {
Expand Down
98 changes: 98 additions & 0 deletions apps/meteor/tests/e2e/avatar-settings.ts
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);
});
});
});
});
14 changes: 13 additions & 1 deletion apps/meteor/tests/e2e/page-objects/fragments/home-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export class HomeContent {
this.page = page;
}

get channelHeader(): Locator {
return this.page.locator('main header');
}

get inputMessage(): Locator {
return this.page.locator('[name="msg"]');
}
Expand Down Expand Up @@ -37,6 +41,10 @@ export class HomeContent {
return this.page.locator('//button[contains(text(), "Join")]');
}

async openRoomInfo(): Promise<void> {
await this.channelHeader.locator('button[data-qa-id="ToolBoxAction-info-circled"]').click();
}

async joinRoom(): Promise<void> {
await this.btnJoinRoom.click();
}
Expand Down Expand Up @@ -136,8 +144,12 @@ export class HomeContent {
return this.page.locator('[data-qa-id="menu-more-actions"]');
}

get userCard(): Locator {
return this.page.locator('[data-qa="UserCard"]');
}

get linkUserCard(): Locator {
return this.page.locator('[data-qa="UserCard"] a');
return this.userCard.locator('a');
}

get btnContactInformation(): Locator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export class HomeSidenav {
return this.page.locator('//*[@id="modal-root"]//button[contains(text(), "Create")]');
}

getSidebarItemByName(name: string): Locator {
return this.page.locator(`[data-qa="sidebar-item"][aria-label="${name}"]`);
}

async openAdministrationByLabel(text: string): Promise<void> {
await this.page.locator('role=button[name="Administration"]').click();
await this.page.locator(`li.rcx-option >> text="${text}"`).click();
Expand Down
9 changes: 8 additions & 1 deletion apps/meteor/tests/e2e/utils/create-target-channel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import faker from '@faker-js/faker';
import type { ChannelsCreateProps } from '@rocket.chat/rest-typings';
import type { ChannelsCreateProps, GroupsCreateProps } from '@rocket.chat/rest-typings';

import type { BaseTest } from './test';

Expand All @@ -14,6 +14,13 @@ export async function createTargetChannel(api: BaseTest['api'], options?: Omit<C
return name;
}

export async function createTargetPrivateChannel(api: BaseTest['api'], options?: Omit<GroupsCreateProps, 'name'>): Promise<string> {
const name = faker.datatype.uuid();
await api.post('/groups.create', { name, ...options });

return name;
}

export async function createTargetTeam(api: BaseTest['api']): Promise<string> {
const name = faker.datatype.uuid();
await api.post('/teams.create', { name, type: 1, members: ['user2', 'user1'] });
Expand Down