From 79c5a103a2824581de8424d53a4b9ed0f37a4120 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Tue, 12 Jan 2016 02:40:47 -0400 Subject: [PATCH] Fix GitLab issue #243, "System allows a user to skip entering values for a required metadata field while uploading a new document". --- HISTORY.rst | 4 ++ docs/releases/2.0.1.rst | 77 ++++++++++++++++++++++++ mayan/apps/metadata/models.py | 4 +- mayan/apps/metadata/tests/test_models.py | 25 ++++++++ 4 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 docs/releases/2.0.1.rst diff --git a/HISTORY.rst b/HISTORY.rst index a4995da416..0197542fa7 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -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) ================ diff --git a/docs/releases/2.0.1.rst b/docs/releases/2.0.1.rst new file mode 100644 index 0000000000..399fa649fe --- /dev/null +++ b/docs/releases/2.0.1.rst @@ -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 `_ 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/ diff --git a/mayan/apps/metadata/models.py b/mayan/apps/metadata/models.py index d9b7d249bf..8b4784b27a 100644 --- a/mayan/apps/metadata/models.py +++ b/mayan/apps/metadata/models.py @@ -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 diff --git a/mayan/apps/metadata/tests/test_models.py b/mayan/apps/metadata/tests/test_models.py index facdacfc11..4826a7c64a 100644 --- a/mayan/apps/metadata/tests/test_models.py +++ b/mayan/apps/metadata/tests/test_models.py @@ -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) + )