Commit 00ebc224 authored by Benjamin Bouvier's avatar Benjamin Bouvier
Browse files

UI: don't allow setting emails if they haven't been enabled by the administrator;

parent 5e1f20a9
Pipeline #24263 failed with stages
in 12 minutes and 1 second
......@@ -11,6 +11,10 @@ const EmailConfig = props => {
return null;
}
if (!props.emailsEnabled) {
return <div className="top-panel">{ $t('client.settings.emails.emails_not_enabled') }</div>;
}
let toEmail = null;
let refToEmail = node => {
......@@ -89,6 +93,7 @@ const EmailConfig = props => {
export default connect(state => {
return {
standalone: get.boolSetting(state, 'standalone-mode'),
emailsEnabled: get.boolSetting(state, 'emails-enabled'),
toEmail: get.setting(state, 'email-recipient'),
sendingEmail: get.isSendingTestEmail(state)
};
......
......@@ -100,12 +100,4 @@ module.exports = function prepareProcessKresus(standalone, config) {
- KRESUS_EMAIL_FORCE_TLS = ${process.kresus.smtpForceTLS}
- KRESUS_EMAIL_REJECT_UNAUTHORIZED_TLS = ${process.kresus.smtpRejectUnauthorizedTLS}
`);
if (standalone) {
if (!process.kresus.emailFrom.length ||
!process.kresus.smtpHost ||
!process.kresus.smtpPort) {
log.warn("One of emailFrom, smtpHost or smtpPort is missing: emails won't work.");
}
}
};
......@@ -13,6 +13,12 @@ import Config from '../models/config';
let log = makeLogger('emailer');
class Emailer {
isEnabled() {
return !!(process.kresus.emailFrom.length &&
process.kresus.smtpHost &&
process.kresus.smtpPort);
}
forceReinit(recipientEmail) {
assert(process.kresus.standalone);
this.toEmail = recipientEmail;
......@@ -29,9 +35,8 @@ class Emailer {
}
_initStandalone() {
if (!process.kresus.emailFrom.length ||
!process.kresus.smtpHost ||
!process.kresus.smtpPort) {
if (!this.isEnabled()) {
log.warn("One of emailFrom, smtpHost or smtpPort is missing: emails won't work.");
this.internalSendToUser = () => {
log.warn('Trying to send an email although emails are not configured, aborting.');
};
......
......@@ -13,6 +13,8 @@ import {
getVersion as getWeboobVersion
} from '../lib/sources/weboob';
import Emailer from '../lib/emailer';
import DefaultSettings from '../shared/default-settings';
let log = makeLogger('models/config');
......@@ -92,7 +94,8 @@ Config.ghostSettings = new Set([
'weboob-installed',
'weboob-version',
'standalone-mode',
'url-prefix'
'url-prefix',
'emails-enabled'
]);
// Returns all the config name/value pairs, except for the ghost ones that are
......@@ -145,6 +148,12 @@ Config.all = async function() {
value: String(process.kresus.urlPrefix)
});
// Have emails been enabled by the administrator?
values.push({
name: 'emails-enabled',
value: String(Emailer.isEnabled())
});
return values;
};
......
const DefaultSettings = new Map;
// Ghost settings: can't be defined by the user, aren't present in exports.
DefaultSettings.set('weboob-installed', 'false');
DefaultSettings.set('weboob-version', '?');
DefaultSettings.set('standalone-mode', 'false');
DefaultSettings.set('url-prefix', '/');
DefaultSettings.set('emails-enabled', 'false');
// User settings.
DefaultSettings.set('locale', 'en');
DefaultSettings.set('migration-version', '0');
DefaultSettings.set('weboob-auto-update', 'true');
......
......@@ -242,7 +242,8 @@
"monthly": "monthly",
"send_to": "Recipient's email address",
"delete_email": "Delete email address",
"send_test_email": "Send test email"
"send_test_email": "Send test email",
"emails_not_enabled": "Emails haven't been enabled by your administrator. Thus, it is not possible to set any email reports or alerts at this time."
}
},
"similarity": {
......
......@@ -242,7 +242,8 @@
"monthly": "tous les mois",
"send_to": "Envoyer à l'adresse email",
"delete_email": "Supprimer l'adresse email",
"send_test_email": "Envoyer un email de test"
"send_test_email": "Envoyer un email de test",
"emails_not_enabled": "Les emails n'ont pas été activés par votre administrateur : il n'est donc pas possible d'envoyer des rapports emails ou des alertes pour le moment."
}
},
"similarity": {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment