Add button to remove all datasync settings from DB

seems useful for someone testing, as prep to make the switch
This commit is contained in:
Lance Edgar 2021-11-29 19:28:07 -06:00
parent 8aff5d519d
commit 4229798c7b
2 changed files with 68 additions and 30 deletions

View file

@ -50,9 +50,57 @@
</b-button> </b-button>
${h.end_form()} ${h.end_form()}
</div> </div>
<div class="level-item">
<b-button type="is-danger"
@click="purgeSettingsInit()"
icon-pack="fas"
icon-left="trash">
Remove All Settings
</b-button>
</div>
</div> </div>
</div> </div>
<b-modal has-modal-card
:active.sync="purgeSettingsShowDialog">
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Remove All Settings</p>
</header>
<section class="modal-card-body">
<p class="block">
If you like we can remove all DataSync settings from the DB.
</p>
<p class="block">
Note that this tool normally removes all settings first,
every time you click "Save Settings".&nbsp; Here though you
can "just remove" and <span class="is-italic">not</span>
save the current settings.
</p>
</section>
<footer class="modal-card-foot">
<b-button @click="purgeSettingsShowDialog = false">
Cancel
</b-button>
${h.form(request.current_route_url())}
${h.csrf_token(request)}
${h.hidden('purge_settings', 'true')}
<b-button type="is-danger"
native-type="submit"
:disabled="purgingSettings"
icon-pack="fas"
icon-left="trash"
@click="purgingSettings = true">
{{ purgingSettings ? "Working, please wait..." : "Remove All Settings" }}
</b-button>
${h.end_form()}
</footer>
</div>
</b-modal>
<b-notification type="is-warning" <b-notification type="is-warning"
:active.sync="showConfigFilesNote"> :active.sync="showConfigFilesNote">
## TODO: should link to some ratman page here, yes? ## TODO: should link to some ratman page here, yes?
@ -448,6 +496,9 @@
ThisPageData.restartCommand = ${json.dumps(restart_command)|n} ThisPageData.restartCommand = ${json.dumps(restart_command)|n}
ThisPageData.purgeSettingsShowDialog = false
ThisPageData.purgingSettings = false
ThisPageData.settingsNeedSaved = false ThisPageData.settingsNeedSaved = false
ThisPageData.undoChanges = false ThisPageData.undoChanges = false
ThisPageData.savingSettings = false ThisPageData.savingSettings = false
@ -692,6 +743,10 @@
} }
} }
ThisPage.methods.purgeSettingsInit = function() {
this.purgeSettingsShowDialog = true
}
ThisPage.methods.saveSettings = function() { ThisPage.methods.saveSettings = function() {
this.savingSettings = true this.savingSettings = true
let url = ${json.dumps(request.current_route_url())|n} let url = ${json.dumps(request.current_route_url())|n}

View file

@ -30,11 +30,9 @@ import getpass
import subprocess import subprocess
import logging import logging
import sqlalchemy as sa
from rattail.db import model from rattail.db import model
from rattail.datasync.config import load_profiles from rattail.datasync.config import load_profiles
from rattail.datasync.util import get_lastrun from rattail.datasync.util import get_lastrun, purge_datasync_settings
from tailbone.views import MasterView from tailbone.views import MasterView
from tailbone.util import csrf_token from tailbone.util import csrf_token
@ -100,11 +98,17 @@ class DataSyncChangeView(MasterView):
View for configuring the DataSync daemon. View for configuring the DataSync daemon.
""" """
if self.request.method == 'POST': if self.request.method == 'POST':
data = self.request.json_body # if self.request.is_xhr and not self.request.POST:
self.save_settings(data) if self.request.POST.get('purge_settings'):
self.request.session.flash("Settings have been saved. " self.delete_settings()
"You should probably restart DataSync now.") self.request.session.flash("Settings have been removed.")
return self.json_response({'success': True}) return self.redirect(self.request.current_route_url())
else:
data = self.request.json_body
self.save_settings(data)
self.request.session.flash("Settings have been saved. "
"You should probably restart DataSync now.")
return self.json_response({'success': True})
profiles = load_profiles(self.rattail_config, profiles = load_profiles(self.rattail_config,
include_disabled=True, include_disabled=True,
@ -221,28 +225,7 @@ class DataSyncChangeView(MasterView):
value=setting['value'])) value=setting['value']))
def delete_settings(self): def delete_settings(self):
model = self.model purge_datasync_settings(self.rattail_config, self.Session())
to_delete = [
'rattail.datasync.watch',
'tailbone.datasync.restart',
]
for setting in to_delete:
setting = self.Session.query(model.Setting).get(setting)
if setting:
self.Session.delete(setting)
self.Session.query(model.Setting)\
.filter(sa.or_(
model.Setting.name.like('rattail.datasync.%.watcher'),
model.Setting.name.like('rattail.datasync.%.watcher.db'),
model.Setting.name.like('rattail.datasync.%.watcher.delay'),
model.Setting.name.like('rattail.datasync.%.watcher.retry_attempts'),
model.Setting.name.like('rattail.datasync.%.watcher.retry_delay'),
model.Setting.name.like('rattail.datasync.%.consumers'),
model.Setting.name.like('rattail.datasync.%.consumers.runas'),
model.Setting.name.like('rattail.datasync.%.consumer.%')))\
.delete(synchronize_session=False)
@classmethod @classmethod
def defaults(cls, config): def defaults(cls, config):