fix: clarify why SMS delivery is skipped when a channel gate is off
Surface env vs dashboard disable reasons in SMS logs so password reset and other sends are easier to diagnose when only one layer is enabled.
This commit is contained in:
@@ -4,7 +4,7 @@ const config = require('../../config/config');
|
||||
const logger = require('../../utils/logger');
|
||||
const { Setting, SETTINGS_KEY } = require('./settingModel');
|
||||
const {
|
||||
isChannelEnabled,
|
||||
isDbChannelEnabled,
|
||||
isEnvChannelEnabled,
|
||||
toPublicMessaging
|
||||
} = require('../../utils/messagingChannels');
|
||||
@@ -35,20 +35,46 @@ const invalidateMessagingCache = () => {
|
||||
cacheAt = 0;
|
||||
};
|
||||
|
||||
const isMessagingChannelEnabled = async (channel) => {
|
||||
if (!isEnvChannelEnabled(channel, config)) return false;
|
||||
const getMessagingChannelState = async (channel) => {
|
||||
const envEnabled = isEnvChannelEnabled(channel, config);
|
||||
if (!envEnabled) {
|
||||
return {
|
||||
enabled: false,
|
||||
envEnabled: false,
|
||||
dbEnabled: null,
|
||||
blockReason: 'env_disabled'
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const db = await getDbMessagingFlags();
|
||||
return isChannelEnabled(channel, { env: config, db });
|
||||
const dbEnabled = isDbChannelEnabled(channel, db);
|
||||
return {
|
||||
enabled: dbEnabled,
|
||||
envEnabled: true,
|
||||
dbEnabled,
|
||||
blockReason: dbEnabled ? null : 'dashboard_disabled'
|
||||
};
|
||||
} catch (err) {
|
||||
logger.warn(`[Messaging] Failed to read settings for ${channel}, using env only: ${err.message}`);
|
||||
return true;
|
||||
return {
|
||||
enabled: true,
|
||||
envEnabled: true,
|
||||
dbEnabled: null,
|
||||
blockReason: null
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const isMessagingChannelEnabled = async (channel) => {
|
||||
const state = await getMessagingChannelState(channel);
|
||||
return state.enabled;
|
||||
};
|
||||
|
||||
const getPublicMessaging = (doc) => toPublicMessaging(readDbFlags(doc), config);
|
||||
|
||||
module.exports = {
|
||||
getMessagingChannelState,
|
||||
isMessagingChannelEnabled,
|
||||
invalidateMessagingCache,
|
||||
getPublicMessaging,
|
||||
|
||||
Reference in New Issue
Block a user