Documents: Add default filtering of stubs
Add filter(is_stub) to the default Document model manager. Now only the Passthrough manager can access document stubs. Remove the explicit filtering of stubs from code that obtains the queryset from the default document manager. Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -55,7 +55,7 @@ class DashboardWidgetDocumentsTotal(DashboardWidgetNumeric):
|
||||
)
|
||||
self.count = AccessControlList.objects.filter_by_access(
|
||||
permission=permission_document_view, user=request.user,
|
||||
queryset=Document.objects.filter(is_stub=False)
|
||||
queryset=Document.objects.all()
|
||||
).count()
|
||||
return super(DashboardWidgetDocumentsTotal, self).render(request)
|
||||
|
||||
|
||||
@@ -17,17 +17,13 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DocumentManager(models.Manager):
|
||||
def delete_stubs(self):
|
||||
for stale_stub_document in self.filter(is_stub=True, date_added__lt=now() - timedelta(seconds=STUB_EXPIRATION_INTERVAL)):
|
||||
stale_stub_document.delete(trash=False)
|
||||
|
||||
def get_by_natural_key(self, uuid):
|
||||
return self.model.passthrough.get(uuid=force_text(uuid))
|
||||
|
||||
def get_queryset(self):
|
||||
return TrashCanQuerySet(
|
||||
self.model, using=self._db
|
||||
).filter(in_trash=False)
|
||||
).filter(in_trash=False).filter(is_stub=False)
|
||||
|
||||
def invalidate_cache(self):
|
||||
for document in self.model.objects.all():
|
||||
@@ -222,7 +218,9 @@ class FavoriteDocumentManager(models.Manager):
|
||||
|
||||
|
||||
class PassthroughManager(models.Manager):
|
||||
pass
|
||||
def delete_stubs(self):
|
||||
for stale_stub_document in self.filter(is_stub=True, date_added__lt=now() - timedelta(seconds=STUB_EXPIRATION_INTERVAL)):
|
||||
stale_stub_document.delete(to_trash=False)
|
||||
|
||||
|
||||
class RecentDocumentManager(models.Manager):
|
||||
|
||||
@@ -75,7 +75,7 @@ def task_delete_stubs():
|
||||
)
|
||||
|
||||
logger.info('Executing')
|
||||
Document.objects.delete_stubs()
|
||||
Document.passthrough.delete_stubs()
|
||||
logger.info('Finshed')
|
||||
|
||||
|
||||
|
||||
@@ -242,34 +242,34 @@ class DocumentVersionTestCase(GenericDocumentTestCase):
|
||||
|
||||
|
||||
@override_settings(OCR_AUTO_OCR=False)
|
||||
class DocumentManagerTestCase(BaseTestCase):
|
||||
class DocumentPassthroughManagerTestCase(BaseTestCase):
|
||||
def setUp(self):
|
||||
super(DocumentManagerTestCase, self).setUp()
|
||||
super(DocumentPassthroughManagerTestCase, self).setUp()
|
||||
self.document_type = DocumentType.objects.create(
|
||||
label=TEST_DOCUMENT_TYPE_LABEL
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
self.document_type.delete()
|
||||
super(DocumentManagerTestCase, self).tearDown()
|
||||
super(DocumentPassthroughManagerTestCase, self).tearDown()
|
||||
|
||||
def test_document_stubs_deletion(self):
|
||||
document_stub = Document.objects.create(
|
||||
document_type=self.document_type
|
||||
)
|
||||
|
||||
Document.objects.delete_stubs()
|
||||
Document.passthrough.delete_stubs()
|
||||
|
||||
self.assertEqual(Document.objects.count(), 1)
|
||||
self.assertEqual(Document.passthrough.count(), 1)
|
||||
|
||||
document_stub.date_added = document_stub.date_added - timedelta(
|
||||
seconds=STUB_EXPIRATION_INTERVAL + 1
|
||||
)
|
||||
document_stub.save()
|
||||
|
||||
Document.objects.delete_stubs()
|
||||
Document.passthrough.delete_stubs()
|
||||
|
||||
self.assertEqual(Document.objects.count(), 0)
|
||||
self.assertEqual(Document.passthrough.count(), 0)
|
||||
|
||||
|
||||
class DuplicatedDocumentsTestCase(GenericDocumentTestCase):
|
||||
|
||||
@@ -80,9 +80,7 @@ class IndexFilesystem(Operations):
|
||||
if access_only:
|
||||
return True
|
||||
else:
|
||||
return Document.objects.get(
|
||||
is_stub=False, pk=document_pk
|
||||
)
|
||||
return Document.objects.get(pk=document_pk)
|
||||
|
||||
for count, part in enumerate(parts[1:]):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user