fix: handle differing email profile keys for appinfo/configure

hopefully this all can improve some day soon..
This commit is contained in:
Lance Edgar 2024-08-26 16:11:32 -05:00
parent dffd951369
commit 7a9d5772db
2 changed files with 69 additions and 32 deletions

View file

@ -280,15 +280,14 @@
<b-button @click="purgeSettingsShowDialog = false"> <b-button @click="purgeSettingsShowDialog = false">
Cancel Cancel
</b-button> </b-button>
${h.form(request.current_route_url())} ${h.form(request.current_route_url(), **{'@submit': 'purgingSettings = true'})}
${h.csrf_token(request)} ${h.csrf_token(request)}
${h.hidden('remove_settings', 'true')} ${h.hidden('remove_settings', 'true')}
<b-button type="is-danger" <b-button type="is-danger"
native-type="submit" native-type="submit"
:disabled="purgingSettings" :disabled="purgingSettings"
icon-pack="fas" icon-pack="fas"
icon-left="trash" icon-left="trash">
@click="purgingSettings = true">
{{ purgingSettings ? "Working, please wait..." : "Remove All Settings" }} {{ purgingSettings ? "Working, please wait..." : "Remove All Settings" }}
</b-button> </b-button>
${h.end_form()} ${h.end_form()}

View file

@ -77,13 +77,41 @@ class AppInfoView(WuttaAppInfoView):
return context return context
# nb. these email settings require special handling below
configure_profile_key_mismatches = [
'default.subject',
'default.to',
'default.cc',
'default.bcc',
'feedback.subject',
'feedback.to',
]
def configure_get_simple_settings(self): def configure_get_simple_settings(self):
""" """ """ """
simple_settings = super().configure_get_simple_settings() simple_settings = super().configure_get_simple_settings()
# TODO:
# there are several email config keys which differ between
# wuttjamaican and rattail. basically all of the "profile" keys
# have a different prefix.
# after wuttaweb has declared its settings, we examine each and
# overwrite the value if one is defined with rattail config key.
# (nb. this happens even if wuttjamaican key has a value!)
# note that we *do* declare the profile mismatch keys for
# rattail, as part of simple settings. this ensures the
# parent logic will always remove them when saving. however
# we must also include them in gather_settings() to ensure
# they are saved to match wuttjamaican values.
# there are also a couple of flags where rattail's default is the
# opposite of wuttjamaican. so we overwrite those too as needed.
for setting in simple_settings: for setting in simple_settings:
# TODO: the update home page redirect setting is off by # nb. the update home page redirect setting is off by
# default for wuttaweb, but on for tailbone # default for wuttaweb, but on for tailbone
if setting['name'] == 'wuttaweb.home_redirect_to_login': if setting['name'] == 'wuttaweb.home_redirect_to_login':
value = self.config.get_bool('wuttaweb.home_redirect_to_login') value = self.config.get_bool('wuttaweb.home_redirect_to_login')
@ -91,55 +119,43 @@ class AppInfoView(WuttaAppInfoView):
value = self.config.get_bool('tailbone.login_is_home', default=True) value = self.config.get_bool('tailbone.login_is_home', default=True)
setting['value'] = value setting['value'] = value
# TODO: sending email is off by default for wuttjamaican, # nb. sending email is off by default for wuttjamaican,
# but on for rattail # but on for rattail
elif setting['name'] == 'rattail.mail.send_emails': elif setting['name'] == 'rattail.mail.send_emails':
value = self.config.get_bool('rattail.mail.send_emails', default=True) value = self.config.get_bool('rattail.mail.send_emails', default=True)
setting['value'] = value setting['value'] = value
# TODO: email defaults have different config keys in rattail # nb. this one is even more special, key is entirely different
elif setting['name'] == 'rattail.email.default.sender': elif setting['name'] == 'rattail.email.default.sender':
value = self.config.get('rattail.email.default.sender') value = self.config.get('rattail.email.default.sender')
if value is None: if value is None:
value = self.config.get('rattail.mail.default.from') value = self.config.get('rattail.mail.default.from')
setting['value'] = value setting['value'] = value
# TODO: email defaults have different config keys in rattail else:
elif setting['name'] == 'rattail.email.default.subject':
value = self.config.get('rattail.email.default.subject')
if value is None:
value = self.config.get('rattail.mail.default.subject')
setting['value'] = value
# TODO: email defaults have different config keys in rattail # nb. fetch alternate value for profile key mismatch
elif setting['name'] == 'rattail.email.default.to': for key in self.configure_profile_key_mismatches:
value = self.config.get('rattail.email.default.to') if setting['name'] == f'rattail.email.{key}':
value = self.config.get(f'rattail.email.{key}')
if value is None: if value is None:
value = self.config.get('rattail.mail.default.to') value = self.config.get(f'rattail.mail.{key}')
setting['value'] = value
# TODO: email defaults have different config keys in rattail
elif setting['name'] == 'rattail.email.default.cc':
value = self.config.get('rattail.email.default.cc')
if value is None:
value = self.config.get('rattail.mail.default.cc')
setting['value'] = value
# TODO: email defaults have different config keys in rattail
elif setting['name'] == 'rattail.email.default.bcc':
value = self.config.get('rattail.email.default.bcc')
if value is None:
value = self.config.get('rattail.mail.default.bcc')
setting['value'] = value setting['value'] = value
break
# nb. these are no longer used (deprecated), but we keep # nb. these are no longer used (deprecated), but we keep
# them defined here so the tool auto-deletes them # them defined here so the tool auto-deletes them
simple_settings.extend([ simple_settings.extend([
{'name': 'tailbone.login_is_home'},
{'name': 'tailbone.buefy_version'}, {'name': 'tailbone.buefy_version'},
{'name': 'tailbone.vue_version'}, {'name': 'tailbone.vue_version'},
]) ])
simple_settings.append({'name': 'rattail.mail.default.from'})
for key in self.configure_profile_key_mismatches:
simple_settings.append({'name': f'rattail.mail.{key}'})
for key in self.get_weblibs(): for key in self.get_weblibs():
simple_settings.extend([ simple_settings.extend([
{'name': f'tailbone.libver.{key}'}, {'name': f'tailbone.libver.{key}'},
@ -148,6 +164,28 @@ class AppInfoView(WuttaAppInfoView):
return simple_settings return simple_settings
def configure_gather_settings(self, data, simple_settings=None):
""" """
settings = super().configure_gather_settings(data, simple_settings=simple_settings)
# nb. must add legacy rattail profile settings to match new ones
for setting in list(settings):
if setting['name'] == 'rattail.email.default.sender':
value = setting['value']
settings.append({'name': 'rattail.mail.default.from',
'value': value})
else:
for key in self.configure_profile_key_mismatches:
if setting['name'] == f'rattail.email.{key}':
value = setting['value']
settings.append({'name': f'rattail.mail.{key}',
'value': value})
break
return settings
class SettingView(MasterView): class SettingView(MasterView):
""" """