Removed CapaAdminStore

This commit is contained in:
djmaze 2021-03-16 10:46:22 +01:00
parent 4a8d516123
commit eda0ee695d
5 changed files with 97 additions and 196 deletions

View file

@ -3,7 +3,6 @@ import 'External/Admin/ko';
import { Settings, SettingsGet } from 'Common/Globals'; import { Settings, SettingsGet } from 'Common/Globals';
import { AppAdminStore } from 'Stores/Admin/App'; import { AppAdminStore } from 'Stores/Admin/App';
import { CapaAdminStore } from 'Stores/Admin/Capa';
import Remote from 'Remote/Admin/Fetch'; import Remote from 'Remote/Admin/Fetch';
import { SettingsAdminScreen } from 'Screen/Admin/Settings'; import { SettingsAdminScreen } from 'Screen/Admin/Settings';
@ -29,7 +28,6 @@ class AdminApp extends AbstractApp {
super.bootstart(); super.bootstart();
AppAdminStore.populate(); AppAdminStore.populate();
CapaAdminStore.populate();
this.hideLoading(); this.hideLoading();

View file

@ -28,19 +28,6 @@ class RemoteAdminFetch extends AbstractFetchRemote {
this.defaultRequest(fCallback, 'AdminSettingsUpdate', oData); this.defaultRequest(fCallback, 'AdminSettingsUpdate', oData);
} }
/**
* @param {string} key
* @param {?Function} valueFn
* @param {?Function} fn
*/
saveAdminConfigHelper(key, valueFn, fn) {
return (value) => {
const data = {};
data[key] = valueFn ? valueFn(value) : value;
this.saveAdminConfig(fn || null, data);
};
}
/** /**
* @param {?Function} fCallback * @param {?Function} fCallback
* @param {boolean=} bIncludeAliases = true * @param {boolean=} bIncludeAliases = true

View file

@ -7,7 +7,7 @@ import {
convertThemeName convertThemeName
} from 'Common/Utils'; } from 'Common/Utils';
import { SaveSettingsStep } from 'Common/Enums'; import { Capa, SaveSettingsStep } from 'Common/Enums';
import { Settings, SettingsGet } from 'Common/Globals'; import { Settings, SettingsGet } from 'Common/Globals';
import { reload as translatorReload, convertLangName } from 'Common/Translator'; import { reload as translatorReload, convertLangName } from 'Common/Translator';
@ -18,7 +18,6 @@ import Remote from 'Remote/Admin/Fetch';
import { ThemeStore } from 'Stores/Theme'; import { ThemeStore } from 'Stores/Theme';
import { LanguageStore } from 'Stores/Language'; import { LanguageStore } from 'Stores/Language';
import { AppAdminStore } from 'Stores/Admin/App'; import { AppAdminStore } from 'Stores/Admin/App';
import { CapaAdminStore } from 'Stores/Admin/Capa';
import LanguagesPopupView from 'View/Popup/Languages'; import LanguagesPopupView from 'View/Popup/Languages';
export class GeneralAdminSettings { export class GeneralAdminSettings {
@ -35,19 +34,18 @@ export class GeneralAdminSettings {
this.theme = ThemeStore.theme; this.theme = ThemeStore.theme;
this.themes = ThemeStore.themes; this.themes = ThemeStore.themes;
this.capaThemes = CapaAdminStore.themes;
this.capaUserBackground = CapaAdminStore.userBackground;
this.capaAdditionalAccounts = CapaAdminStore.additionalAccounts;
this.capaIdentities = CapaAdminStore.identities;
this.capaAttachmentThumbnails = CapaAdminStore.attachmentThumbnails;
this.capaTemplates = CapaAdminStore.templates;
ko.addObservablesTo(this, { ko.addObservablesTo(this, {
allowLanguagesOnSettings: !!SettingsGet('AllowLanguagesOnSettings'), allowLanguagesOnSettings: !!SettingsGet('AllowLanguagesOnSettings'),
newMoveToFolder: !!SettingsGet('NewMoveToFolder'), newMoveToFolder: !!SettingsGet('NewMoveToFolder'),
attachmentLimitTrigger: SaveSettingsStep.Idle, attachmentLimitTrigger: SaveSettingsStep.Idle,
languageTrigger: SaveSettingsStep.Idle, languageTrigger: SaveSettingsStep.Idle,
themeTrigger: SaveSettingsStep.Idle themeTrigger: SaveSettingsStep.Idle,
capaThemes: Settings.capa(Capa.Themes),
capaUserBackground: Settings.capa(Capa.UserBackground),
capaAdditionalAccounts: Settings.capa(Capa.AdditionalAccounts),
capaIdentities: Settings.capa(Capa.Identities),
capaAttachmentThumbnails: Settings.capa(Capa.AttachmentThumbnails),
capaTemplates: Settings.capa(Capa.Templates)
}); });
this.weakPassword = AppAdminStore.weakPassword; this.weakPassword = AppAdminStore.weakPassword;
@ -77,96 +75,61 @@ export class GeneralAdminSettings {
this.languageAdminFullName = ko.computed(() => convertLangName(this.languageAdmin())); this.languageAdminFullName = ko.computed(() => convertLangName(this.languageAdmin()));
this.languageAdminTrigger = ko.observable(SaveSettingsStep.Idle).extend({ debounce: 100 }); this.languageAdminTrigger = ko.observable(SaveSettingsStep.Idle).extend({ debounce: 100 });
}
onBuild() { const fReloadLanguageHelper = (saveSettingsStep) => () => {
setTimeout(() => { this.languageAdminTrigger(saveSettingsStep);
const f1 = settingsSaveHelperSimpleFunction(this.attachmentLimitTrigger, this), setTimeout(() => this.languageAdminTrigger(SaveSettingsStep.Idle), 1000);
f2 = settingsSaveHelperSimpleFunction(this.languageTrigger, this), },
f3 = settingsSaveHelperSimpleFunction(this.themeTrigger, this), fSaveBoolHelper = (key, fn) =>
fReloadLanguageHelper = (saveSettingsStep) => () => { value => {
this.languageAdminTrigger(saveSettingsStep); const data = {};
setTimeout(() => this.languageAdminTrigger(SaveSettingsStep.Idle), 1000); data[key] = value ? 1 : 0;
}; Remote.saveAdminConfig(fn, data);
};
this.mainAttachmentLimit.subscribe(value => { ko.addSubscribablesTo(this, {
Remote.saveAdminConfig(f1, { mainAttachmentLimit: value =>
Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.attachmentLimitTrigger, this), {
'AttachmentLimit': pInt(value) 'AttachmentLimit': pInt(value)
}); }),
});
this.language.subscribe(value => { language: value =>
Remote.saveAdminConfig(f2, { Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.languageTrigger, this), {
'Language': value.trim() 'Language': value.trim()
}); }),
});
this.languageAdmin.subscribe(value => { languageAdmin: value => {
this.languageAdminTrigger(SaveSettingsStep.Animate); this.languageAdminTrigger(SaveSettingsStep.Animate);
translatorReload(true, value) translatorReload(true, value)
.then(fReloadLanguageHelper(SaveSettingsStep.TrueResult), fReloadLanguageHelper(SaveSettingsStep.FalseResult)) .then(fReloadLanguageHelper(SaveSettingsStep.TrueResult), fReloadLanguageHelper(SaveSettingsStep.FalseResult))
.then(() => { .then(() => Remote.saveAdminConfig(null, {
Remote.saveAdminConfig(null, { 'LanguageAdmin': value.trim()
'LanguageAdmin': value.trim() }));
}); },
});
});
this.theme.subscribe(value => { theme: value => {
changeTheme(value, this.themeTrigger); changeTheme(value, this.themeTrigger);
Remote.saveAdminConfig(f3, { Remote.saveAdminConfig(settingsSaveHelperSimpleFunction(this.themeTrigger, this), {
'Theme': value.trim() 'Theme': value.trim()
}); });
}); },
this.capaAdditionalAccounts.subscribe(value => { capaAdditionalAccounts: fSaveBoolHelper('CapaAdditionalAccounts'),
Remote.saveAdminConfig(null, {
'CapaAdditionalAccounts': value ? '1' : '0'
});
});
this.capaIdentities.subscribe(value => { capaIdentities: fSaveBoolHelper('CapaIdentities'),
Remote.saveAdminConfig(null, {
'CapaIdentities': value ? '1' : '0'
});
});
this.capaTemplates.subscribe(value => { capaTemplates: fSaveBoolHelper('CapaTemplates'),
Remote.saveAdminConfig(null, {
'CapaTemplates': value ? '1' : '0'
});
});
this.capaAttachmentThumbnails.subscribe(value => { capaAttachmentThumbnails: fSaveBoolHelper('CapaAttachmentThumbnails'),
Remote.saveAdminConfig(null, {
'CapaAttachmentThumbnails': value ? '1' : '0'
});
});
this.capaThemes.subscribe(value => { capaThemes: fSaveBoolHelper('CapaThemes'),
Remote.saveAdminConfig(null, {
'CapaThemes': value ? '1' : '0'
});
});
this.capaUserBackground.subscribe(value => { capaUserBackground: fSaveBoolHelper('CapaUserBackground'),
Remote.saveAdminConfig(null, {
'CapaUserBackground': value ? '1' : '0'
});
});
this.allowLanguagesOnSettings.subscribe(value => { allowLanguagesOnSettings: fSaveBoolHelper('AllowLanguagesOnSettings'),
Remote.saveAdminConfig(null, {
'AllowLanguagesOnSettings': value ? '1' : '0'
});
});
this.newMoveToFolder.subscribe(value => { newMoveToFolder: fSaveBoolHelper('NewMoveToFolder')
Remote.saveAdminConfig(null, { });
'NewMoveToFolder': value ? '1' : '0'
});
});
}, 50);
} }
selectLanguage() { selectLanguage() {

View file

@ -1,9 +1,9 @@
import ko from 'ko'; import ko from 'ko';
import { SettingsGet } from 'Common/Globals'; import { Capa } from 'Common/Enums';
import { Settings, SettingsGet } from 'Common/Globals';
import { AppAdminStore } from 'Stores/Admin/App'; import { AppAdminStore } from 'Stores/Admin/App';
import { CapaAdminStore } from 'Stores/Admin/Capa';
import Remote from 'Remote/Admin/Fetch'; import Remote from 'Remote/Admin/Fetch';
@ -13,11 +13,6 @@ export class SecurityAdminSettings {
constructor() { constructor() {
this.weakPassword = AppAdminStore.weakPassword; this.weakPassword = AppAdminStore.weakPassword;
this.capaOpenPGP = CapaAdminStore.openPGP;
this.capaTwoFactorAuth = CapaAdminStore.twoFactorAuth;
this.capaTwoFactorAuthForce = CapaAdminStore.twoFactorAuthForce;
ko.addObservablesTo(this, { ko.addObservablesTo(this, {
useLocalProxyForExternalImages: !!SettingsGet('UseLocalProxyForExternalImages'), useLocalProxyForExternalImages: !!SettingsGet('UseLocalProxyForExternalImages'),
@ -36,40 +31,66 @@ export class SecurityAdminSettings {
adminPasswordNewError: false, adminPasswordNewError: false,
adminPasswordUpdateError: false, adminPasswordUpdateError: false,
adminPasswordUpdateSuccess: false adminPasswordUpdateSuccess: false,
capaOpenPGP: Settings.capa(Capa.OpenPGP),
capaTwoFactorAuth: Settings.capa(Capa.TwoFactor),
capaTwoFactorAuthForce: Settings.capa(Capa.TwoFactorForce)
}); });
this.capaTwoFactorAuth.subscribe(value => { ko.addSubscribablesTo(this, {
if (!value) { adminPassword: () => {
this.capaTwoFactorAuthForce(false); this.adminPasswordUpdateError(false);
} this.adminPasswordUpdateSuccess(false);
}); },
this.verifySslCertificate.subscribe(value => { adminLogin: () => this.adminLoginError(false),
if (!value) {
this.allowSelfSigned(true);
}
});
this.adminPassword.subscribe(() => { adminPasswordNew: () => {
this.adminPasswordUpdateError(false); this.adminPasswordUpdateError(false);
this.adminPasswordUpdateSuccess(false); this.adminPasswordUpdateSuccess(false);
}); this.adminPasswordNewError(false);
},
this.adminLogin.subscribe(() => { adminPasswordNew2: () => {
this.adminLoginError(false); this.adminPasswordUpdateError(false);
}); this.adminPasswordUpdateSuccess(false);
this.adminPasswordNewError(false);
},
this.adminPasswordNew.subscribe(() => { capaOpenPGP: value =>
this.adminPasswordUpdateError(false); Remote.saveAdminConfig(null, {
this.adminPasswordUpdateSuccess(false); 'CapaOpenPGP': value ? 1 : 0
this.adminPasswordNewError(false); }),
});
this.adminPasswordNew2.subscribe(() => { capaTwoFactorAuth: value => {
this.adminPasswordUpdateError(false); value || this.capaTwoFactorAuthForce(false);
this.adminPasswordUpdateSuccess(false); Remote.saveAdminConfig(null, {
this.adminPasswordNewError(false); 'CapaTwoFactorAuth': value ? 1 : 0
});
},
capaTwoFactorAuthForce: value =>
Remote.saveAdminConfig(null, {
'CapaTwoFactorAuthForce': value ? 1 : 0
}),
useLocalProxyForExternalImages: value =>
Remote.saveAdminConfig(null, {
'UseLocalProxyForExternalImages': value ? 1 : 0
}),
verifySslCertificate: value => {
value => value || this.allowSelfSigned(true);
Remote.saveAdminConfig(null, {
'VerifySslCertificate': value ? 1 : 0
});
},
allowSelfSigned: value =>
Remote.saveAdminConfig(null, {
'AllowSelfSigned': value ? 1 : 0
})
}); });
this.onNewAdminPasswordResponse = this.onNewAdminPasswordResponse.bind(this); this.onNewAdminPasswordResponse = this.onNewAdminPasswordResponse.bind(this);
@ -125,44 +146,6 @@ export class SecurityAdminSettings {
} }
} }
onBuild() {
this.capaOpenPGP.subscribe(value => {
Remote.saveAdminConfig(null, {
'CapaOpenPGP': value ? '1' : '0'
});
});
this.capaTwoFactorAuth.subscribe(value => {
Remote.saveAdminConfig(null, {
'CapaTwoFactorAuth': value ? '1' : '0'
});
});
this.capaTwoFactorAuthForce.subscribe(value => {
Remote.saveAdminConfig(null, {
'CapaTwoFactorAuthForce': value ? '1' : '0'
});
});
this.useLocalProxyForExternalImages.subscribe(value => {
Remote.saveAdminConfig(null, {
'UseLocalProxyForExternalImages': value ? '1' : '0'
});
});
this.verifySslCertificate.subscribe(value => {
Remote.saveAdminConfig(null, {
'VerifySslCertificate': value ? '1' : '0'
});
});
this.allowSelfSigned.subscribe(value => {
Remote.saveAdminConfig(null, {
'AllowSelfSigned': value ? '1' : '0'
});
});
}
onHide() { onHide() {
this.adminPassword(''); this.adminPassword('');
this.adminPasswordNew(''); this.adminPasswordNew('');

View file

@ -1,30 +0,0 @@
import ko from 'ko';
import { Capa } from 'Common/Enums';
import { Settings } from 'Common/Globals';
export const CapaAdminStore = {
populate: function() {
const capa = Settings.capa;
this.additionalAccounts(capa(Capa.AdditionalAccounts));
this.identities(capa(Capa.Identities));
this.attachmentThumbnails(capa(Capa.AttachmentThumbnails));
this.themes(capa(Capa.Themes));
this.userBackground(capa(Capa.UserBackground));
this.openPGP(capa(Capa.OpenPGP));
this.twoFactorAuth(capa(Capa.TwoFactor));
this.twoFactorAuthForce(capa(Capa.TwoFactorForce));
this.templates(capa(Capa.Templates));
}
};
ko.addObservablesTo(CapaAdminStore, {
additionalAccounts: false,
identities: false,
attachmentThumbnails: false,
themes: true,
userBackground: false,
openPGP: false,
twoFactorAuth: false,
twoFactorAuthForce: false,
templates: false
});