A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
fix: allow reacting with custom emojis from the same community (#3649)
Jiralitef2fde7745712
diff --git a/fluxer_api/src/api/channel/services/interaction/MessageReactionService.ts b/fluxer_api/src/api/channel/services/interaction/MessageReactionService.tsindex c93530c87..e46fa41c6 100644--- a/fluxer_api/src/api/channel/services/interaction/MessageReactionService.ts+++ b/fluxer_api/src/api/channel/services/interaction/MessageReactionService.ts@@ -406,10 +406,11 @@ export class MessageReactionService {if (!emoji) {throw InputValidationError.fromCode('emoji', ValidationErrorCodes.CUSTOM_EMOJI_NOT_FOUND);}- if (hasGlobalExpressions === 0 && emoji.guildId.toString() !== guildId) {+ const isExternalEmoji = emoji.guildId.toString() !== guildId;+ if (hasGlobalExpressions === 0 && isExternalEmoji) {throw InputValidationError.fromCode('emoji', ValidationErrorCodes.CUSTOM_EMOJIS_REQUIRE_PREMIUM_OUTSIDE_SOURCE);}- if (hasPermission) {+ if (hasPermission && isExternalEmoji) {const canUseExternalEmojis = await hasPermission(Permissions.USE_EXTERNAL_EMOJIS);if (!canUseExternalEmojis) {throw new MissingPermissionsError();diff --git a/fluxer_api/src/api/channel/tests/ReactionExternalEmojiPermissions.test.ts b/fluxer_api/src/api/channel/tests/ReactionExternalEmojiPermissions.test.tsnew file mode 100644index 000000000..7f437d60b--- /dev/null+++ b/fluxer_api/src/api/channel/tests/ReactionExternalEmojiPermissions.test.ts@@ -0,0 +1,61 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import {+ createPermissionOverwrite,+ sendChannelMessage,+ setupTestGuildWithMembers,+} from '@app/api/channel/tests/ChannelTestUtils';+import {createEmoji, createTestGuild, getPngDataUrl} from '@app/api/emoji/tests/EmojiTestUtils';+import {type ApiTestHarness, createApiTestHarness} from '@app/api/test/ApiTestHarness';+import {setLimitOverride} from '@app/api/test/LimitTestUtils';+import {HTTP_STATUS} from '@app/api/test/TestConstants';+import {createBuilder} from '@app/api/test/TestRequestBuilder';+import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';+import {Permissions} from '@fluxer/constants/src/ChannelConstants';+import {afterAll, beforeAll, beforeEach, describe, it} from 'vitest';++describe('Reactions without USE_EXTERNAL_EMOJIS', () => {+ let harness: ApiTestHarness;++ beforeAll(async () => {+ harness = await createApiTestHarness();+ });++ beforeEach(async () => {+ await harness.reset();+ });++ afterAll(async () => {+ await harness?.shutdown();+ });++ it('allows emojis from the same community', async () => {+ const {owner, members, guild, systemChannel} = await setupTestGuildWithMembers(harness, 1);+ const [reactor] = members;+ await createPermissionOverwrite(harness, owner.token, systemChannel.id, guild.id, {+ type: 0,+ allow: '0',+ deny: Permissions.USE_EXTERNAL_EMOJIS.toString(),+ });+ const message = await sendChannelMessage(harness, owner.token, systemChannel.id, 'react to me');+ const react = (emoji: {id: string; name: string}) =>+ createBuilder(harness, reactor.token)+ .put(`/channels/${systemChannel.id}/messages/${message.id}/reactions/${emoji.name}:${emoji.id}/@me`)+ .body(null);++ const localEmoji = await createEmoji(harness, owner.token, guild.id, {name: 'local', image: getPngDataUrl()});+ await react(localEmoji).expect(HTTP_STATUS.NO_CONTENT).execute();++ const restore = await setLimitOverride(harness, {feature_global_expressions: 1});+ try {+ const otherGuild = await createTestGuild(harness, reactor.token);+ const externalEmoji = await createEmoji(harness, reactor.token, otherGuild.id, {+ name: 'external',+ image: getPngDataUrl(),+ });+ await react(externalEmoji).expect(HTTP_STATUS.FORBIDDEN, APIErrorCodes.MISSING_PERMISSIONS).execute();+ } finally {+ await restore();+ }+ });+});