Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved comments on /App/FeatureSet/Notification/Config.ts #1737

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
18 changes: 9 additions & 9 deletions App/FeatureSet/Notification/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import GlobalConfig, {
EmailServerType,
} from "Common/Models/DatabaseModels/GlobalConfig";

// Load SMTP configuration from environment variables or use default values
export const InternalSmtpPassword: string =
process.env["INTERNAL_SMTP_PASSWORD"] || "";

Expand All @@ -22,24 +23,27 @@ export const InternalSmtpPort: Port = new Port(2525);

export const InternalSmtpSecure: boolean = false;

// Define default internal SMTP email address and sender name
export const InternalSmtpEmail: Email = new Email(
process.env["INTERNAL_SMTP_EMAIL"] || "[email protected]",
);

export const InternalSmtpFromName: string =
process.env["INTERNAL_SMTP_FROM_NAME"] || "OneUptime";

// Function type that returns a promise with an EmailServer object or null
type GetGlobalSMTPConfig = () => Promise<EmailServer | null>;

// Fetch global SMTP configuration from the database
export const getGlobalSMTPConfig: GetGlobalSMTPConfig =
async (): Promise<EmailServer | null> => {
const globalConfig: GlobalConfig | null =
await GlobalConfigService.findOneBy({
query: {
_id: ObjectID.getZeroObjectID().toString(),
_id: ObjectID.getZeroObjectID().toString(), // Use a predefined zero object ID as the query
},
props: {
isRoot: true,
isRoot: true, // Indicate the operation is privileged
},
select: {
smtpFromEmail: true,
Expand All @@ -52,10 +56,12 @@ export const getGlobalSMTPConfig: GetGlobalSMTPConfig =
},
});

// Throw an exception if no global configuration is found
if (!globalConfig) {
throw new BadDataException("Global Config not found");
}

// Return null if essential SMTP configuration is absent
if (
!globalConfig.smtpFromEmail &&
!globalConfig.smtpHost &&
Expand All @@ -67,14 +73,8 @@ export const getGlobalSMTPConfig: GetGlobalSMTPConfig =
return null;
}

// Check that 'smtpFromEmail' is defined, else throw an exception
if (!globalConfig.smtpFromEmail) {
throw new BadDataException(
"Global SMTP From Email not found. Please set this in the Admin Dashboard: " +
AdminDashboardClientURL.toString(),
);
}

if (!globalConfig.smtpHost) {
throw new BadDataException(
"SMTP Host not found. Please set this in the Admin Dashboard: " +
AdminDashboardClientURL.toString(),
Expand Down