From 37e9f6b4f6f2a5255b8132dd603c12bba910b5cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= <fpeters@entrouvert.com>
Date: Sun, 19 May 2019 08:13:12 +0200
Subject: [PATCH] misc: remove private status & history option (#33155)

---
 tests/test_admin_pages.py      | 11 -------
 tests/test_api.py              |  2 +-
 tests/test_backoffice_pages.py | 58 ----------------------------------
 tests/test_formdata.py         | 23 --------------
 wcs/admin/forms.py             | 19 ++---------
 wcs/formdef.py                 |  5 +--
 wcs/forms/root.py              |  1 -
 7 files changed, 5 insertions(+), 114 deletions(-)

diff --git a/tests/test_admin_pages.py b/tests/test_admin_pages.py
index d0bc3999b..b08a9f478 100644
--- a/tests/test_admin_pages.py
+++ b/tests/test_admin_pages.py
@@ -270,17 +270,6 @@ def test_forms_edit(pub):
     assert_option_display(resp, 'Confirmation Page', 'Disabled')
     assert FormDef.get(1).confirmation == False
 
-    # history and status
-    assert_option_display(resp, 'History and Status', 'Public')
-    resp = resp.click('History and Status')
-    assert resp.forms[0]['private_status_and_history'].checked is False
-    resp.forms[0]['private_status_and_history'].checked = True
-    resp = resp.forms[0].submit()
-    assert resp.location == 'http://example.net/backoffice/forms/1/'
-    resp = resp.follow()
-    assert_option_display(resp, 'History and Status', 'Private')
-    assert FormDef.get(1).private_status_and_history is True
-
     # Limit to one form
     assert_option_display(resp, 'Limit to one form', 'Disabled')
     resp = resp.click('Limit to one form')
diff --git a/tests/test_api.py b/tests/test_api.py
index dd84dfedb..e6f6c1899 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -534,7 +534,7 @@ def test_formdef_schema(pub):
                                          'workflow', 'expiration_date', 'discussion',
                                          'last_modification_time', 'has_captcha',
                                          'always_advertise', 'name', 'disabled', 'only_allow_one',
-                                         'private_status_and_history', 'fields', 'keywords',
+                                         'fields', 'keywords',
                                          'publication_date', 'detailed_emails',
                                          'disabled_redirection'])
     assert resp.json['name'] == 'test'
diff --git a/tests/test_backoffice_pages.py b/tests/test_backoffice_pages.py
index 799e91b30..709ec9714 100644
--- a/tests/test_backoffice_pages.py
+++ b/tests/test_backoffice_pages.py
@@ -4288,64 +4288,6 @@ def test_backoffice_logged_errors(pub):
     resp = resp2.click('Failed to evaluate condition')
     assert not 'href="http://example.net/backoffice/management/test/' in resp.body
 
-def test_backoffice_private_status_and_history(pub):
-    create_user(pub)
-    create_environment(pub)
-    formdef = FormDef.get_by_urlname('form-title')
-    formdef.private_status_and_history = True
-    formdef.store()
-    form_class = FormDef.get_by_urlname('form-title').data_class()
-    number31 = [x for x in form_class.select() if x.data['1'] == 'FOO BAR 30'][0]
-    app = login(get_app(pub))
-    resp = app.get('/backoffice/management/form-title/')
-    assert re.findall('<tbody.*\/tbody>', resp.body, re.DOTALL)[0].count('<tr') == 17
-
-    # click on a formdata
-    resp = resp.click(href='%s/' % number31.id)
-    assert (' with the number %s.' % number31.get_display_id()) in resp.body
-    resp.forms[0]['comment'] = 'HELLO WORLD'
-    resp = resp.forms[0].submit('button_accept')
-    resp = resp.follow()
-    assert FormDef.get_by_urlname('form-title').data_class().get(number31.id).status == 'wf-accepted'
-    assert 'HELLO WORLD' in resp.body
-
-    assert 'id="evolution-log"' in resp.body
-
-def test_backoffice_private_status_and_history_with_assigned_function(pub):
-    create_user(pub)
-    create_environment(pub, set_receiver=False)
-
-    formdef = FormDef.get_by_urlname('form-title')
-    formdef.private_status_and_history = True
-    formdef.store()
-
-    form_class = FormDef.get_by_urlname('form-title').data_class()
-    number31 = [x for x in form_class.select() if x.data['1'] == 'FOO BAR 30'][0]
-
-    app = login(get_app(pub))
-    resp = app.get('/backoffice/management/form-title/', status=403)
-
-    # fake function assignment
-    number31.workflow_roles = {'_receiver': '1'}
-    number31.store()
-    resp = app.get('/backoffice/management/form-title/', status=200)
-    assert re.findall('<tbody.*\/tbody>', resp.body, re.DOTALL)[0].count('<tr') == 1
-
-    # click on a formdata
-    resp = resp.click(href='%s/' % number31.id)
-    assert (' with the number %s.' % number31.get_display_id()) in resp.body
-
-    # history is visible
-    assert 'id="evolution-log"' in resp.body
-    resp.forms[0]['comment'] = 'HELLO WORLD'
-    resp = resp.forms[0].submit('button_accept')
-    resp = resp.follow()
-    assert FormDef.get_by_urlname('form-title').data_class().get(number31.id).status == 'wf-accepted'
-
-    # history is still visible
-    assert 'HELLO WORLD' in resp.body
-    assert 'id="evolution-log"' in resp.body
-
 def test_backoffice_formdata_named_wscall(http_requests, pub):
     user = create_user(pub)
     create_environment(pub)
diff --git a/tests/test_formdata.py b/tests/test_formdata.py
index 2da93f175..5cdc2001b 100644
--- a/tests/test_formdata.py
+++ b/tests/test_formdata.py
@@ -476,29 +476,6 @@ def test_backoffice_field_varname(pub):
     substvars = formdata.get_substitution_variables()
     assert substvars.get('form_var_backoffice_blah') == 'test'
 
-def test_private_history(pub, local_user):
-    formdef.data_class().wipe()
-    formdef.private_status_and_history = True
-    formdef.store()
-    formdata = formdef.data_class()()
-    formdata.store()
-
-    assert formdef.is_user_allowed_read_status_and_history(None, formdata=formdata) is False
-
-    assert formdef.is_user_allowed_read_status_and_history(local_user, formdata=formdata) is False
-    local_user.is_admin = True
-    assert formdef.is_user_allowed_read_status_and_history(local_user, formdata=formdata) is True
-    local_user.is_admin = False
-
-    role = Role(name='foobar')
-    role.store()
-
-    formdef.workflow_roles['_receiver'] = role.id
-    assert formdef.is_user_allowed_read_status_and_history(local_user, formdata=formdata) is False
-
-    local_user.roles = [role.id]
-    assert formdef.is_user_allowed_read_status_and_history(local_user, formdata=formdata) is True
-
 def test_workflow_data_file_url(pub):
     upload = Upload('test.txt', 'text/plain', 'ascii')
     upload.receive(['first line', 'second line'])
diff --git a/wcs/admin/forms.py b/wcs/admin/forms.py
index 23f44c8e4..35a07c4eb 100644
--- a/wcs/admin/forms.py
+++ b/wcs/admin/forms.py
@@ -98,7 +98,7 @@ class FormDefUI(object):
 
         for f in ('name', 'confirmation',
                     'only_allow_one', 'category_id', 'disabled',
-                    'enable_tracking_codes', 'workflow_id', 'private_status_and_history',
+                    'enable_tracking_codes', 'workflow_id',
                     'disabled_redirection', 'always_advertise',
                     'publication_date', 'expiration_date'):
             widget = form.get_widget(f)
@@ -142,7 +142,7 @@ class FieldsDirectory(FieldsDirectory):
 
 
 class OptionsDirectory(Directory):
-    _q_exports = ['confirmation', 'private_status', 'only_allow_one',
+    _q_exports = ['confirmation', 'only_allow_one',
             'always_advertise', 'tracking_code', 'online_status', 'captcha',
             'description', 'keywords', 'category', ('360_view', 'p_360_view'),
             'geolocations', 'appearance', 'templates']
@@ -157,14 +157,6 @@ class OptionsDirectory(Directory):
                 value=self.formdef.confirmation)
         return self.handle(form, _('Confirmation Page'))
 
-    def private_status(self):
-        form = Form(enctype='multipart/form-data')
-        form.add(CheckboxWidget, 'private_status_and_history',
-                title=_('Keep workflow status and history private'),
-                hint=_('Restrict the possibility to see status and history to the recipients'),
-                value=self.formdef.private_status_and_history)
-        return self.handle(form, _('History and Status'))
-
     def only_allow_one(self):
         form = Form(enctype='multipart/form-data')
         form.add(CheckboxWidget, 'only_allow_one',
@@ -278,7 +270,7 @@ class OptionsDirectory(Directory):
 
         if form.is_submitted() and not form.has_errors():
             attrs = ['confirmation', 'only_allow_one', 'disabled',
-                    'enable_tracking_codes', 'private_status_and_history',
+                    'enable_tracking_codes',
                     'always_advertise', 'disabled_redirection',
                     'publication_date', 'expiration_date', 'has_captcha',
                     'description', 'keywords', 'category_id',
@@ -502,11 +494,6 @@ class FormDefPage(Directory):
                 self.formdef.confirmation and
                 C_('confirmation page|Enabled') or C_('confirmation page|Disabled'))
 
-        r += add_option_line('options/private_status',
-                _('History and Status'),
-                self.formdef.private_status_and_history and
-                C_('history and status|Private') or C_('history and status|Public'))
-
         r += add_option_line('options/only_allow_one',
                 _('Limit to one form'),
                 self.formdef.only_allow_one and
diff --git a/wcs/formdef.py b/wcs/formdef.py
index 0f3b02d40..8874018a2 100644
--- a/wcs/formdef.py
+++ b/wcs/formdef.py
@@ -97,7 +97,6 @@ class FormDef(StorableObject):
     expiration_date = None
     has_captcha = False
     skip_from_360_view = False
-    private_status_and_history = False
     appearance_keywords = None
     digest_template = None
 
@@ -118,7 +117,7 @@ class FormDef(StorableObject):
             'digest_template']
     BOOLEAN_ATTRIBUTES = ['discussion', 'detailed_emails', 'disabled',
             'only_allow_one', 'enable_tracking_codes', 'confirmation',
-            'always_advertise', 'private_status_and_history',
+            'always_advertise',
             'has_captcha', 'skip_from_360_view']
 
     def __init__(self, *args, **kwargs):
@@ -1314,8 +1313,6 @@ class FormDef(StorableObject):
         form_roles = [x for x in self.workflow_roles.values() if x]
         if formdata and formdata.workflow_roles:
             form_roles.extend([x for x in formdata.workflow_roles.values() if x])
-        if user and self.private_status_and_history and not user_roles.intersection(form_roles):
-            return False
         return self.is_user_allowed_read(user, formdata=formdata)
 
     def is_disabled(self):
diff --git a/wcs/forms/root.py b/wcs/forms/root.py
index f2a285375..c5dab245c 100644
--- a/wcs/forms/root.py
+++ b/wcs/forms/root.py
@@ -1537,7 +1537,6 @@ class RootDirectory(AccessControlled, Directory):
             # XXX: seperate endpoints from non-endpoints
             for status in workflow.possible_status:
                 fms = [x for x in user_forms if \
-                        not x.formdef.private_status_and_history and \
                         x.formdef.workflow.id == workflow.id and \
                         (x.get_visible_status() == status)]
                 if not fms:
-- 
2.20.1

