mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-07 19:22:14 +09:00
fix(guild): treat very high as high without phone verification (#3095)
This commit is contained in:
@@ -286,6 +286,7 @@ export interface MasterConfig {
|
||||
};
|
||||
instance: {
|
||||
self_hosted: boolean;
|
||||
phone_verification_enabled?: boolean;
|
||||
auto_join_invite_code?: string;
|
||||
visionaries_guild_id?: string;
|
||||
visionaries_guild_visionary_role_id?: string;
|
||||
|
||||
@@ -290,6 +290,15 @@ describe('buildNamedFluxerEnvOverrides', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('maps the phone verification switch onto instance.phone_verification_enabled', () => {
|
||||
expect(buildNamedFluxerEnvOverrides({FLUXER_PHONE_VERIFICATION_ENABLED: 'true'})).toEqual({
|
||||
instance: {phone_verification_enabled: true},
|
||||
});
|
||||
expect(buildNamedFluxerEnvOverrides({FLUXER_PHONE_VERIFICATION_ENABLED: 'false'})).toEqual({
|
||||
instance: {phone_verification_enabled: false},
|
||||
});
|
||||
});
|
||||
|
||||
test('rejects a store enabled flag that is not a boolean', () => {
|
||||
expect(() => buildNamedFluxerEnvOverrides({FLUXER_APP_STORE_ENABLED: 'yes'})).toThrow(
|
||||
'FLUXER_APP_STORE_ENABLED must be true or false',
|
||||
|
||||
@@ -265,6 +265,7 @@ const NAMED_FLUXER_ENV_OVERRIDES: Record<string, NamedEnvOverride> = {
|
||||
parse: parseBoolean,
|
||||
},
|
||||
FLUXER_SELF_HOSTED: {path: ['instance', 'self_hosted'], parse: parseBoolean},
|
||||
FLUXER_PHONE_VERIFICATION_ENABLED: {path: ['instance', 'phone_verification_enabled'], parse: parseBoolean},
|
||||
FLUXER_AUTO_JOIN_INVITE_CODE: {path: ['instance', 'auto_join_invite_code']},
|
||||
FLUXER_VISIONARIES_GUILD_ID: {path: ['instance', 'visionaries_guild_id']},
|
||||
FLUXER_VISIONARIES_GUILD_VISIONARY_ROLE_ID: {path: ['instance', 'visionaries_guild_visionary_role_id']},
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
import {
|
||||
clampVoiceChannelBitrate,
|
||||
GuildFeatures,
|
||||
GuildVerificationLevel,
|
||||
getEffectiveGuildVerificationLevel,
|
||||
getMaxVoiceChannelBitrate,
|
||||
resolveVoiceChannelBitrate,
|
||||
} from '@fluxer/constants/src/GuildConstants';
|
||||
@@ -59,3 +61,33 @@ describe('resolveVoiceChannelBitrate', () => {
|
||||
expect(resolveVoiceChannelBitrate(384000, [GuildFeatures.AUDIO_BITRATE_256_KBPS])).toBe(256000);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getEffectiveGuildVerificationLevel', () => {
|
||||
it('returns the stored level when phone verification is available', () => {
|
||||
expect(getEffectiveGuildVerificationLevel(GuildVerificationLevel.VERY_HIGH, false, true)).toBe(
|
||||
GuildVerificationLevel.VERY_HIGH,
|
||||
);
|
||||
expect(getEffectiveGuildVerificationLevel(GuildVerificationLevel.NONE, false, true)).toBe(
|
||||
GuildVerificationLevel.NONE,
|
||||
);
|
||||
});
|
||||
it('treats very high as high when phone verification is unavailable', () => {
|
||||
expect(getEffectiveGuildVerificationLevel(GuildVerificationLevel.VERY_HIGH, false, false)).toBe(
|
||||
GuildVerificationLevel.HIGH,
|
||||
);
|
||||
expect(getEffectiveGuildVerificationLevel(GuildVerificationLevel.VERY_HIGH, true, false)).toBe(
|
||||
GuildVerificationLevel.HIGH,
|
||||
);
|
||||
expect(getEffectiveGuildVerificationLevel(GuildVerificationLevel.MEDIUM, false, false)).toBe(
|
||||
GuildVerificationLevel.MEDIUM,
|
||||
);
|
||||
});
|
||||
it('raises a discoverable guild to at least low', () => {
|
||||
expect(getEffectiveGuildVerificationLevel(GuildVerificationLevel.NONE, true, true)).toBe(
|
||||
GuildVerificationLevel.LOW,
|
||||
);
|
||||
expect(getEffectiveGuildVerificationLevel(GuildVerificationLevel.NONE, true, false)).toBe(
|
||||
GuildVerificationLevel.LOW,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -20,11 +20,16 @@ export const GuildVerificationLevel = {
|
||||
|
||||
export type GuildVerificationLevelValue = ValueOf<typeof GuildVerificationLevel>;
|
||||
|
||||
export function getEffectiveGuildVerificationLevel(verificationLevel: number, isDiscoverable: boolean): number {
|
||||
export function getEffectiveGuildVerificationLevel(
|
||||
verificationLevel: number,
|
||||
isDiscoverable: boolean,
|
||||
phoneVerificationEnabled: boolean,
|
||||
): number {
|
||||
const level = phoneVerificationEnabled ? verificationLevel : Math.min(verificationLevel, GuildVerificationLevel.HIGH);
|
||||
if (!isDiscoverable) {
|
||||
return verificationLevel;
|
||||
return level;
|
||||
}
|
||||
return Math.max(verificationLevel, GuildVerificationLevel.LOW);
|
||||
return Math.max(level, GuildVerificationLevel.LOW);
|
||||
}
|
||||
|
||||
export const GuildMFALevel = {
|
||||
|
||||
@@ -113,6 +113,9 @@ export const InstanceFeaturesSchema = z
|
||||
self_hosted: z.boolean().describe('Whether this is a self-hosted instance'),
|
||||
presigned_attachment_uploads: z.boolean().describe('Whether clients can request presigned attachment upload URLs'),
|
||||
emails_enabled: z.boolean().describe('Whether the instance sends emails (verification, password reset, etc.)'),
|
||||
phone_verification_enabled: z
|
||||
.boolean()
|
||||
.describe('Whether users can verify a phone number, so the very high guild verification level applies'),
|
||||
})
|
||||
.describe('Feature flags for this instance');
|
||||
export type InstanceFeatures = z.infer<typeof InstanceFeaturesSchema>;
|
||||
|
||||
Reference in New Issue
Block a user