2 Commits

Author SHA1 Message Date
284d9b2efc getSetting: add an optional scope parameter
settings are stored in 3 places:
- login (.gpg file)
- store (.browserpass-settings.json)
- extension-level config (browser UI)

but we don't want each setting to be settable everywhere, so scope
allows one to control which of these 3 places to search for a given
setting.
2022-11-06 00:38:47 -07:00
f70e0cc838 export SettingScope 2022-11-06 00:38:47 -07:00

View File

@@ -14,13 +14,9 @@ module.exports = {
getSetting, getSetting,
ignoreFiles, ignoreFiles,
makeTOTP, makeTOTP,
expTest, SettingScope,
}; };
function expTest(foo) {
return foo * 2;
}
const SettingScope = { const SettingScope = {
// query a setting first from the login, then the store, then globally // query a setting first from the login, then the store, then globally
Login: "login", Login: "login",
@@ -36,10 +32,11 @@ const SettingScope = {
* @param string key Setting key * @param string key Setting key
* @param object login Login object * @param object login Login object
* @param object settings Settings object * @param object settings Settings object
* @param string scope SettingScope value to specify where to search for the setting (optional)
* @return object Setting value * @return object Setting value
*/ */
function getSetting(key, login, settings) { function getSetting(key, login, settings, scope = SettingScope.Login) {
if (typeof login.settings[key] !== "undefined") { if (scope === SettingScope.Login && typeof login.settings[key] !== "undefined") {
return login.settings[key]; return login.settings[key];
} }
if (typeof settings.stores[login.store.id].settings[key] !== "undefined") { if (typeof settings.stores[login.store.id].settings[key] !== "undefined") {