Skip to content

Commit ed3ffa6

Browse files
authored
Add support for encrypted global settings (#359)
2 parents 6538c0c + 36e4c40 commit ed3ffa6

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎app/pages/super-admin/config/email.vue‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const globalSettingQuery = new GlobalSettingQuery();
2323
2424
const smtpSetting: Ref<SmtpConfig> = ref({});
2525
const smtpEnabled: Ref<boolean> = ref(false)
26+
const smtpPasswordConfigured: Ref<boolean> = ref(false)
2627
const testEmail = ref('')
2728
loadSmtpSettings()
2829
@@ -49,6 +50,14 @@ async function loadSmtpSettings() {
4950
for (const [key, value] of Object.entries(GLOBAL_SETTINGS_SMTP_STRING_MAPPING)) {
5051
const { retrieved } = await globalSettingQuery.get(value)
5152
if (retrieved) {
53+
// The password is never returned by the API, even encrypted: it's
54+
// always masked to null. Track whether one is configured instead of
55+
// prefilling the field with it.
56+
if (key === 'password') {
57+
smtpPasswordConfigured.value = !!retrieved.hasValue
58+
continue
59+
}
60+
5261
let setValue: string|null = null
5362
if (retrieved.value) {
5463
setValue = retrieved.value
@@ -148,8 +157,16 @@ async function testSmtp() {
148157
<UInput v-model="smtpSetting.username" />
149158
</UFormField>
150159

151-
<UFormField label="Mot de passe" name="password">
152-
<UInput v-model="smtpSetting.password" type="password" />
160+
<UFormField
161+
label="Mot de passe"
162+
name="password"
163+
:hint="smtpPasswordConfigured ? 'Laissez vide pour conserver le mot de passe actuel' : undefined"
164+
>
165+
<UInput
166+
v-model="smtpSetting.password"
167+
type="password"
168+
:placeholder="smtpPasswordConfigured ? '••••••••' : undefined"
169+
/>
153170
</UFormField>
154171

155172
<UFormField label="Email expéditeur" name="sender" required>

‎app/types/api/item/globalSetting.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ export enum GlobalSettingPublicEnum {
1010
export interface GlobalSetting extends Item {
1111
name?: string;
1212
value?: string;
13+
// Some settings (e.g. SMTP_PASSWORD) never return their value, even
14+
// encrypted; hasValue lets the UI know one is configured anyway.
15+
hasValue?: boolean;
1316
}

0 commit comments

Comments
 (0)