diff --git a/c2corg_api/tests/views/test_document_version_mask.py b/c2corg_api/tests/views/test_document_version_mask.py index 1c75c638e..87b5a2de6 100644 --- a/c2corg_api/tests/views/test_document_version_mask.py +++ b/c2corg_api/tests/views/test_document_version_mask.py @@ -195,6 +195,28 @@ def test_masked_version(self): self.assertIsNotNone(body['document']) self.assertEqual(body['document']['activities'], ['skitouring']) + def test_updated_cache(self): + request_body = self._get_first_version_params() + document_id, lang, version_id = request_body.values() + + body = self.app.get( + '/document/{}/history/{}'.format(document_id, 'en'), status=200) + self.assertFalse(body.json['versions'][0]['masked']) + body = self._get_version( + 'routes', document_id, lang, version_id, 'contributor') + self.assertFalse(body['version']['masked']) + + headers = self.add_authorization_header(username='moderator') + self.app_post_json( + self._prefix, request_body, status=200, headers=headers) + + body = self.app.get( + '/document/{}/history/{}'.format(document_id, 'en'), status=200) + self.assertTrue(body.json['versions'][0]['masked']) + body = self._get_version( + 'routes', document_id, lang, version_id, 'contributor') + self.assertTrue(body['version']['masked']) + class TestVersionUnmaskRest(BaseMaskTest): diff --git a/c2corg_api/views/document_version_mask.py b/c2corg_api/views/document_version_mask.py index f35922104..101dc7e9c 100644 --- a/c2corg_api/views/document_version_mask.py +++ b/c2corg_api/views/document_version_mask.py @@ -1,6 +1,7 @@ import logging from c2corg_api import DBSession +from c2corg_api.models.cache_version import update_cache_version_direct from c2corg_api.models.common.attributes import default_langs from c2corg_api.models.document_history import DocumentVersion from c2corg_api.views import cors_policy, restricted_json_view @@ -93,6 +94,8 @@ def post(self): version = _get_version(self.request) version.masked = True + update_cache_version_direct(self.request.validated['document_id']) + return {} @@ -123,4 +126,6 @@ def post(self): version = _get_version(self.request) version.masked = False + update_cache_version_direct(self.request.validated['document_id']) + return {}