mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-19 05:55:34 +09:00
feat(guild): require opt-in for emoji and sticker cloning (#2712)
This commit is contained in:
1 parent
7b15e5be0f
commit
3affd295e8
63 files changed
+4189
-1752
No files matched your search
@@ -0,0 +1,58 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {Guild} from '@app/features/guild/models/Guild';
|
||||
import {GuildFeatures} from '@fluxer/constants/src/GuildConstants';
|
||||
import type {Guild as WireGuild} from '@fluxer/schema/src/domains/guild/GuildResponseSchemas';
|
||||
import {describe, expect, test, vi} from 'vitest';
|
||||
|
||||
vi.mock('@app/features/app/state/RuntimeConfig', () => ({default: {localInstanceDomain: 'fluxer.test'}}));
|
||||
|
||||
const createGuild = (features: Array<string>): Guild =>
|
||||
new Guild({
|
||||
id: '1',
|
||||
name: 'Test Community',
|
||||
icon: null,
|
||||
features,
|
||||
roles: [],
|
||||
owner_id: '2',
|
||||
} as unknown as WireGuild);
|
||||
|
||||
describe('Guild clone permissions', () => {
|
||||
test('no features means cloning is not allowed', () => {
|
||||
const guild = createGuild([]);
|
||||
expect(guild.cloneEmojiAllowed).toBe(false);
|
||||
expect(guild.cloneStickerAllowed).toBe(false);
|
||||
});
|
||||
|
||||
test('the enabled features allow cloning', () => {
|
||||
const guild = createGuild([GuildFeatures.CLONE_EMOJI_ENABLED, GuildFeatures.CLONE_STICKER_ENABLED]);
|
||||
expect(guild.cloneEmojiAllowed).toBe(true);
|
||||
expect(guild.cloneStickerAllowed).toBe(true);
|
||||
});
|
||||
|
||||
test('each enabled feature only allows its own kind', () => {
|
||||
const emojiOnly = createGuild([GuildFeatures.CLONE_EMOJI_ENABLED]);
|
||||
expect(emojiOnly.cloneEmojiAllowed).toBe(true);
|
||||
expect(emojiOnly.cloneStickerAllowed).toBe(false);
|
||||
const stickerOnly = createGuild([GuildFeatures.CLONE_STICKER_ENABLED]);
|
||||
expect(stickerOnly.cloneEmojiAllowed).toBe(false);
|
||||
expect(stickerOnly.cloneStickerAllowed).toBe(true);
|
||||
});
|
||||
|
||||
test('the deprecated disabled features do not allow cloning', () => {
|
||||
const guild = createGuild([GuildFeatures.CLONE_EMOJI_DISABLED, GuildFeatures.CLONE_STICKER_DISABLED]);
|
||||
expect(guild.cloneEmojiAllowed).toBe(false);
|
||||
expect(guild.cloneStickerAllowed).toBe(false);
|
||||
});
|
||||
|
||||
test('the deprecated disabled features do not override the enabled features', () => {
|
||||
const guild = createGuild([
|
||||
GuildFeatures.CLONE_EMOJI_DISABLED,
|
||||
GuildFeatures.CLONE_STICKER_DISABLED,
|
||||
GuildFeatures.CLONE_EMOJI_ENABLED,
|
||||
GuildFeatures.CLONE_STICKER_ENABLED,
|
||||
]);
|
||||
expect(guild.cloneEmojiAllowed).toBe(true);
|
||||
expect(guild.cloneStickerAllowed).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -451,11 +451,11 @@ export class Guild {
|
||||
}
|
||||
|
||||
get cloneEmojiAllowed(): boolean {
|
||||
return !this.features.has(GuildFeatures.CLONE_EMOJI_DISABLED);
|
||||
return this.features.has(GuildFeatures.CLONE_EMOJI_ENABLED);
|
||||
}
|
||||
|
||||
get cloneStickerAllowed(): boolean {
|
||||
return !this.features.has(GuildFeatures.CLONE_STICKER_DISABLED);
|
||||
return this.features.has(GuildFeatures.CLONE_STICKER_ENABLED);
|
||||
}
|
||||
|
||||
get isLargeGuild(): boolean {
|
||||
|
||||
Reference in new issue
Block a user