Fix GitLab issue #243, "System allows a user to skip entering values for a required metadata field while uploading a new document".

This commit is contained in:
Roberto Rosario
2016-01-12 02:40:47 -04:00
parent 6c0ce71086
commit 79c5a103a2
4 changed files with 109 additions and 1 deletions

View File

@@ -1,3 +1,7 @@
2.0.1 (2016-01-xx)
==================
- Fix GitLab issue #243, "System allows a user to skip entering values for a required metadata field while uploading a new document"
2.0 (2015-12-04)
================

77
docs/releases/2.0.1.rst Normal file
View File

@@ -0,0 +1,77 @@
===============================
Mayan EDMS v2.0.1 release notes
===============================
Released: January 2016
Welcome to Mayan EDMS v2.0.1
What's new in Mayan EDMS v2.0.1
===============================
Required metadata was not enforce correctly
-------------------------------------------
Fixed a situation where documents having required metadata could still be
uploaded without entering a value for the required metadata.
Other changes
-------------
* None
Removals
--------
* None
Upgrading from a previous version
---------------------------------
Using PIP
~~~~~~~~~
Type in the console::
$ pip install -U mayan-edms
the requirements will also be updated automatically.
Using Git
~~~~~~~~~
If you installed Mayan EDMS by cloning the Git repository issue the commands::
$ git reset --hard HEAD
$ git pull
otherwise download the compressed archived and uncompress it overriding the
existing installation.
Next upgrade/add the new requirements::
$ pip install --upgrade -r requirements.txt
Common steps
~~~~~~~~~~~~
Migrate existing database schema with::
$ mayan-edms.py performupgrade
Add new static media::
$ mayan-edms.py collectstatic --noinput
The upgrade procedure is now complete.
Backward incompatible changes
=============================
* None
Bugs fixed or issues closed
===========================
* `GitLab issue #243 <https://gitlab.com/mayan-edms/mayan-edms/issues/243>`_ System allows a user to skip entering values for a required metadata field while uploading a new document
.. _PyPI: https://pypi.python.org/pypi/mayan-edms/

View File

@@ -110,7 +110,9 @@ class MetadataType(models.Model):
return MetadataType.comma_splitter(template.render(context=context))
def get_required_for(self, document_type):
return self in document_type.metadata.filter(required=True)
return document_type.metadata.filter(
required=True, metadata_type=self
).exists()
def validate_value(self, document_type, value):
# Check default

View File

@@ -126,3 +126,28 @@ class MetadataTestCase(TestCase):
self.assertEqual(
self.document.metadata_value_of.test, TEST_PARSED_VALID_DATE
)
def test_required_metadata(self):
self.document_type.metadata.all().delete()
self.assertFalse(
self.metadata_type.get_required_for(self.document_type)
)
self.document_type.metadata.create(
metadata_type=self.metadata_type, required=False
)
self.assertFalse(
self.metadata_type.get_required_for(self.document_type)
)
self.document_type.metadata.all().delete()
self.document_type.metadata.create(
metadata_type=self.metadata_type, required=True
)
self.assertTrue(
self.metadata_type.get_required_for(self.document_type)
)