From cb94cbdb74cd4ad1785c37a6365ee711ddc62ee0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= <fpeters@entrouvert.com>
Date: Fri, 10 Sep 2021 15:45:22 +0200
Subject: [PATCH] settings: remove option to set exception display style
 (#56802)

---
 tests/test_publisher.py      | 14 +++-----------
 wcs/qommon/admin/settings.py | 14 +-------------
 wcs/qommon/publisher.py      | 11 +----------
 3 files changed, 5 insertions(+), 34 deletions(-)

diff --git a/tests/test_publisher.py b/tests/test_publisher.py
index 4f4704da0..378181e38 100644
--- a/tests/test_publisher.py
+++ b/tests/test_publisher.py
@@ -87,7 +87,9 @@ def test_finish_failed_request():
     assert body == '{"err": 1}'
 
     req = get_request()
-    pub.config.display_exceptions = 'text'
+    pub.cfg['debug'] = {'debug_mode': True}
+    pub.write_cfg()
+    pub.set_config(request=req)
     pub._set_request(req)
     try:
         raise Exception()
@@ -96,16 +98,6 @@ def test_finish_failed_request():
         assert 'Traceback (most recent call last)' in str(body)
         assert '<div class="error-page">' not in str(body)
 
-    req = get_request()
-    pub.config.display_exceptions = 'text-in-html'
-    pub._set_request(req)
-    try:
-        raise Exception()
-    except Exception:
-        body = pub.finish_failed_request()
-        assert 'Traceback (most recent call last)' in str(body)
-        assert '<div class="error-page">' in str(body)
-
 
 def test_finish_interrupted_request():
     req = HTTPRequest(
diff --git a/wcs/qommon/admin/settings.py b/wcs/qommon/admin/settings.py
index b9f100af2..172b47586 100644
--- a/wcs/qommon/admin/settings.py
+++ b/wcs/qommon/admin/settings.py
@@ -73,18 +73,6 @@ class SettingsDirectory(AccessControlled, Directory):
             title=_('Email for Tracebacks'),
             value=debug_cfg.get('error_email', ''),
         )
-        form.add(
-            SingleSelectWidget,
-            'display_exceptions',
-            title=_('Display Exceptions'),
-            value=debug_cfg.get('display_exceptions', ''),
-            options=[
-                ('', _('No display')),
-                ('text', _('Display as Text')),
-                ('text-in-html', _('Display as Text in an HTML error page')),
-                ('html', _('Display as HTML')),
-            ],
-        )
         form.add(CheckboxWidget, 'logger', title=_('Logger'), value=debug_cfg.get('logger', True))
         form.add(
             CheckboxWidget,
@@ -116,6 +104,6 @@ class SettingsDirectory(AccessControlled, Directory):
             cfg_submit(
                 form,
                 'debug',
-                ('error_email', 'display_exceptions', 'logger', 'debug_mode', 'mail_redirection'),
+                ('error_email', 'logger', 'debug_mode', 'mail_redirection'),
             )
             return redirect('.')
diff --git a/wcs/qommon/publisher.py b/wcs/qommon/publisher.py
index e6ca3fa08..4ea72add6 100644
--- a/wcs/qommon/publisher.py
+++ b/wcs/qommon/publisher.py
@@ -313,15 +313,6 @@ class QommonPublisher(Publisher):
                 # DISPLAY_EXCEPTIONS is false, so return the most
                 # secure (and cryptic) page.
                 error_page = self._generate_internal_error(request)
-            elif self.config.display_exceptions == 'html':
-                # Generate a spiffy HTML display using cgitb
-                error_page = self._generate_cgitb_error(request, original_response, exc_type, exc_value, tb)
-            elif self.config.display_exceptions == 'text-in-html':
-                error_page = template.error_page(
-                    _('The server encountered an internal error and was unable to complete your request.'),
-                    error_title=_('Internal Server Error'),
-                    exception=plain_error_msg,
-                )
             else:
                 # Generate a plaintext page containing the traceback
                 request.response.set_header('Content-Type', 'text/plain')
@@ -438,7 +429,7 @@ class QommonPublisher(Publisher):
         debug_cfg = self.cfg.get('debug', {})
         self.logger.error_email = debug_cfg.get('error_email')
         self.logger.error_email_from = self.cfg.get('emails', {}).get('from')
-        self.config.display_exceptions = debug_cfg.get('display_exceptions')
+        self.config.display_exceptions = debug_cfg.get('debug_mode')
         self.config.form_tokens = True
         self.config.session_cookie_httponly = True
         self.config.allowed_methods = ['GET', 'HEAD', 'POST', 'PUT']
-- 
2.33.0

