Change the way new document version are blocked, moving the logic to the documents app from the checkouts app signal handler. Disable the upload new document version button and have the new version upload view redirect to the document version list with a message. GitLab issue #231.

This commit is contained in:
Roberto Rosario
2015-10-23 06:06:59 -04:00
parent 414c55f824
commit da4c41c5b2
16 changed files with 395 additions and 141 deletions
+54 -1
View File
@@ -6,8 +6,9 @@ import time
from django.core.files import File
from django.test import TestCase, override_settings
from ..exceptions import NewDocumentVersionNotAllowed
from ..literals import STUB_EXPIRATION_INTERVAL
from ..models import DeletedDocument, Document, DocumentType
from ..models import DeletedDocument, Document, DocumentType, NewVersionBlock
from .literals import (
TEST_DOCUMENT_TYPE, TEST_DOCUMENT_PATH, TEST_MULTI_PAGE_TIFF_PATH,
@@ -257,3 +258,55 @@ class DocumentManagerTestCase(TestCase):
Document.objects.delete_stubs()
self.assertEqual(Document.objects.count(), 0)
@override_settings(OCR_AUTO_OCR=False)
class NewVersionBlockTestCase(TestCase):
def setUp(self):
self.document_type = DocumentType.objects.create(
label=TEST_DOCUMENT_TYPE
)
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
self.document = self.document_type.new_document(
file_object=File(file_object)
)
def tearDown(self):
self.document.delete()
self.document_type.delete()
def test_blocking(self):
NewVersionBlock.objects.block(document=self.document)
self.assertEqual(NewVersionBlock.objects.count(), 1)
self.assertEqual(
NewVersionBlock.objects.first().document, self.document
)
def test_unblocking(self):
NewVersionBlock.objects.create(document=self.document)
NewVersionBlock.objects.unblock(document=self.document)
self.assertEqual(NewVersionBlock.objects.count(), 0)
def test_is_blocked(self):
NewVersionBlock.objects.create(document=self.document)
self.assertTrue(
NewVersionBlock.objects.is_blocked(document=self.document)
)
NewVersionBlock.objects.all().delete()
self.assertFalse(
NewVersionBlock.objects.is_blocked(document=self.document)
)
def test_blocking_new_versions(self):
NewVersionBlock.objects.block(document=self.document)
with self.assertRaises(NewDocumentVersionNotAllowed):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
self.document.new_version(file_object=File(file_object))
+32 -1
View File
@@ -16,7 +16,9 @@ from user_management.tests.literals import (
)
from ..literals import DEFAULT_DELETE_PERIOD, DEFAULT_DELETE_TIME_UNIT
from ..models import DeletedDocument, Document, DocumentType, HASH_FUNCTION
from ..models import (
DeletedDocument, Document, DocumentType, NewVersionBlock, HASH_FUNCTION
)
from ..permissions import (
permission_document_download, permission_document_properties_edit,
permission_document_restore, permission_document_tools,
@@ -575,3 +577,32 @@ class DocumentTypeViewsTestCase(GenericDocumentViewTestCase):
DocumentType.objects.get(pk=self.document_type.pk).label,
TEST_DOCUMENT_TYPE_EDITED_LABEL
)
class NewDocumentVersionBlockViewTestCase(GenericDocumentViewTestCase):
def test_document_new_version_after_checkout(self):
"""
Gitlab issue #231
User shown option to upload new version of a document even though it
is blocked by checkout - v2.0.0b2
Expected results:
- Link to upload version view should not resolve
- Upload version view should reject request
"""
self.login(
username=TEST_ADMIN_USERNAME, password=TEST_ADMIN_PASSWORD
)
NewVersionBlock.objects.block(self.document)
response = self.post(
'sources:upload_version', args=(self.document.pk,),
follow=True
)
self.assertContains(
response, text='blocked from uploading',
status_code=200
)