From d812e5465a4edc17a2533c7995773545601328f8 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 10 Dec 2016 14:55:36 -0600 Subject: [PATCH] Add overrides for email profiles, settings views to make feedback email config readonly --- rattail_demo/emails.py | 2 +- rattail_demo/web/views/__init__.py | 4 ++-- rattail_demo/web/views/email.py | 25 +++++++++++++++++++++++++ rattail_demo/web/views/settings.py | 27 +++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 rattail_demo/web/views/email.py create mode 100644 rattail_demo/web/views/settings.py diff --git a/rattail_demo/emails.py b/rattail_demo/emails.py index 31841d2..a60bf7b 100644 --- a/rattail_demo/emails.py +++ b/rattail_demo/emails.py @@ -5,5 +5,5 @@ Email definitions from __future__ import unicode_literals, absolute_import -# just tempmon emails for now +from rattail.emails import user_feedback from rattail_tempmon.emails import tempmon_low_temp, tempmon_high_temp, tempmon_critical_temp, tempmon_error diff --git a/rattail_demo/web/views/__init__.py b/rattail_demo/web/views/__init__.py index 0d10c6f..b8669db 100644 --- a/rattail_demo/web/views/__init__.py +++ b/rattail_demo/web/views/__init__.py @@ -33,14 +33,14 @@ def includeme(config): config.include('tailbone.views.brands') config.include('tailbone.views.customers') config.include('tailbone.views.departments') - config.include('tailbone.views.email') + config.include('rattail_demo.web.views.email') config.include('tailbone.views.employees') config.include('tailbone.views.families') config.include('rattail_demo.web.views.people') config.include('tailbone.views.products') config.include('tailbone.views.reportcodes') config.include('tailbone.views.roles') - config.include('tailbone.views.settings') + config.include('rattail_demo.web.views.settings') config.include('tailbone.views.stores') config.include('tailbone.views.subdepartments') config.include('rattail_demo.web.views.tempmon') diff --git a/rattail_demo/web/views/email.py b/rattail_demo/web/views/email.py new file mode 100644 index 0000000..7c2d1ca --- /dev/null +++ b/rattail_demo/web/views/email.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +""" +Email views +""" + +from __future__ import unicode_literals, absolute_import + +from tailbone.views import email as base + + +class ProfilesView(base.ProfilesView): + """ + Prevent edit/delete for 'feedback' email config + """ + + def editable_instance(self, profile): + return profile['key'] != 'user_feedback' + + def deletable_instance(self, profile): + return profile['key'] != 'user_feedback' + + +def includeme(config): + ProfilesView.defaults(config) + base.EmailPreview.defaults(config) diff --git a/rattail_demo/web/views/settings.py b/rattail_demo/web/views/settings.py new file mode 100644 index 0000000..9346227 --- /dev/null +++ b/rattail_demo/web/views/settings.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +""" +Settings views +""" + +from __future__ import unicode_literals, absolute_import + +import re + +from tailbone.views import settings as base + + +class SettingsView(base.SettingsView): + """ + Prevent edit/delete for 'feedback' email settings + """ + feedback = re.compile(r'^rattail\.mail\.user_feedback\..*') + + def editable_instance(self, setting): + return not bool(self.feedback.match(setting.name)) + + def deletable_instance(self, setting): + return not bool(self.feedback.match(setting.name)) + + +def includeme(config): + SettingsView.defaults(config)