From e91858b5671ef798562c62e453faecaa3180ee5b Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 17 Aug 2018 13:08:48 -0500 Subject: [PATCH] Add (protected) email settings for upgrade success, failure --- rattail_demo/emails.py | 13 +++++++++++-- rattail_demo/web/views/email.py | 12 +++++++++--- rattail_demo/web/views/settings.py | 16 +++++++++++++--- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/rattail_demo/emails.py b/rattail_demo/emails.py index a60bf7b..b9c43c3 100644 --- a/rattail_demo/emails.py +++ b/rattail_demo/emails.py @@ -5,5 +5,14 @@ Email definitions from __future__ import unicode_literals, absolute_import -from rattail.emails import user_feedback -from rattail_tempmon.emails import tempmon_low_temp, tempmon_high_temp, tempmon_critical_temp, tempmon_error + +# bring in some common config from rattail +from rattail.emails import (upgrade_failure, + upgrade_success, + user_feedback) + +# bring in some common config from rattail_tempmon +from rattail.emails import (tempmon_low_temp, + tempmon_high_temp, + tempmon_critical_temp, + tempmon_error) diff --git a/rattail_demo/web/views/email.py b/rattail_demo/web/views/email.py index 7c2d1ca..4343a5b 100644 --- a/rattail_demo/web/views/email.py +++ b/rattail_demo/web/views/email.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8; -*- """ Email views """ @@ -13,11 +13,17 @@ class ProfilesView(base.ProfilesView): Prevent edit/delete for 'feedback' email config """ + protected = [ + 'user_feedback', + 'upgrade_success', + 'upgrade_failure', + ] + def editable_instance(self, profile): - return profile['key'] != 'user_feedback' + return profile['key'] not in self.protected def deletable_instance(self, profile): - return profile['key'] != 'user_feedback' + return profile['key'] not in self.protected def includeme(config): diff --git a/rattail_demo/web/views/settings.py b/rattail_demo/web/views/settings.py index 9346227..42bf9b1 100644 --- a/rattail_demo/web/views/settings.py +++ b/rattail_demo/web/views/settings.py @@ -14,13 +14,23 @@ class SettingsView(base.SettingsView): """ Prevent edit/delete for 'feedback' email settings """ - feedback = re.compile(r'^rattail\.mail\.user_feedback\..*') + protected = [ + re.compile(r'^rattail\.mail\.user_feedback\..*'), + re.compile(r'^rattail\.mail\.upgrade_success\..*'), + re.compile(r'^rattail\.mail\.upgrade_failure\..*'), + ] def editable_instance(self, setting): - return not bool(self.feedback.match(setting.name)) + for pattern in self.protected: + if pattern.match(setting.name): + return False + return True def deletable_instance(self, setting): - return not bool(self.feedback.match(setting.name)) + for pattern in self.protected: + if pattern.match(setting.name): + return False + return True def includeme(config):