Skip to content

Commit

Permalink
fixup! Add support of version masking
Browse files Browse the repository at this point in the history
  • Loading branch information
asaunier committed Oct 8, 2022
1 parent d3f389c commit 7cf8ee7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
22 changes: 22 additions & 0 deletions c2corg_api/tests/views/test_document_version_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
5 changes: 5 additions & 0 deletions c2corg_api/views/document_version_mask.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {}


Expand Down Expand Up @@ -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 {}

0 comments on commit 7cf8ee7

Please sign in to comment.