Author: astaric
Date: Mon May 20 09:02:00 2013
New Revision: 1484401

URL: http://svn.apache.org/r1484401
Log:
Do not allow tickets to be marked as duplicates of newer tickets. Towards #528.

Modified:
    bloodhound/trunk/bloodhound_relations/bhrelations/tests/api.py
    bloodhound/trunk/bloodhound_relations/bhrelations/validation.py
    bloodhound/trunk/installer/bloodhound_setup.py

Modified: bloodhound/trunk/bloodhound_relations/bhrelations/tests/api.py
URL: 
http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_relations/bhrelations/tests/api.py?rev=1484401&r1=1484400&r2=1484401&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_relations/bhrelations/tests/api.py (original)
+++ bloodhound/trunk/bloodhound_relations/bhrelations/tests/api.py Mon May 20 
09:02:00 2013
@@ -61,6 +61,10 @@ class BaseApiApiTestCase(MultiproductTes
         env.config.set(config_name, 'parent.exclusive', 'true')
         env.config.set(config_name, 'multiproduct_relation', 'mprel,mpbackrel')
         env.config.set(config_name, 'oneway', 'refersto')
+        env.config.set(config_name, 'duplicate', 'duplicateof,duplicatedby')
+        env.config.set(config_name, 'duplicate.validators', 'ReferencesOlder')
+        env.config.set(config_name, 'duplicateof.label', 'Duplicate of')
+        env.config.set(config_name, 'duplicatedby.label', 'Duplicated by')
 
         self.global_env = env
         self._upgrade_mp(self.global_env)
@@ -530,6 +534,19 @@ class ApiTestCase(BaseApiApiTestCase):
         #assert
         self.assertEqual(1, len(list(warnings)))
 
+    def test_duplicate_can_only_reference_older_ticket(self):
+        t1 = self._insert_and_load_ticket("1")
+        t2 = self._insert_and_load_ticket("2")
+
+        self.assertRaises(
+            ValidationError,
+            self.relations_system.add,
+            t1,
+            t2,
+            "duplicateof",
+        )
+        self.relations_system.add(t2, t1, "duplicateof")
+
 
 class RelationChangingListenerTestCase(BaseApiApiTestCase):
     def test_can_sent_adding_event(self):

Modified: bloodhound/trunk/bloodhound_relations/bhrelations/validation.py
URL: 
http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_relations/bhrelations/validation.py?rev=1484401&r1=1484400&r2=1484401&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_relations/bhrelations/validation.py (original)
+++ bloodhound/trunk/bloodhound_relations/bhrelations/validation.py Mon May 20 
09:02:00 2013
@@ -22,7 +22,7 @@ from trac.core import Component, impleme
 from trac.resource import get_resource_shortname
 
 from bhrelations.api import IRelationValidator, RelationsSystem, \
-    ResourceIdSerializer
+    ResourceIdSerializer, TicketRelationsSpecifics
 
 
 class Validator(Component):
@@ -187,6 +187,21 @@ class OneToManyValidator(Validator):
                 ))
 
 
+class ReferencesOlderValidator(Validator):
+    def validate(self, relation):
+        source, destination = map(ResourceIdSerializer.get_resource_by_id,
+                                  [relation.source, relation.destination])
+        if source.realm == 'ticket' and destination.realm == 'ticket':
+            source, destination = map(
+                TicketRelationsSpecifics(self.env)._create_ticket_by_full_id,
+                [source, destination])
+            if destination['time'] > source['time']:
+                raise ValidationError(
+                    "Relation %s must reference an older resource." %
+                    self.render_relation_type(relation.type)
+                )
+
+
 class ValidationError(TracError):
     def __init__(self, message, title=None, show_traceback=False):
         super(ValidationError, self).__init__(

Modified: bloodhound/trunk/installer/bloodhound_setup.py
URL: 
http://svn.apache.org/viewvc/bloodhound/trunk/installer/bloodhound_setup.py?rev=1484401&r1=1484400&r2=1484401&view=diff
==============================================================================
--- bloodhound/trunk/installer/bloodhound_setup.py (original)
+++ bloodhound/trunk/installer/bloodhound_setup.py Mon May 20 09:02:00 2013
@@ -106,6 +106,10 @@ BASE_CONFIG = {'components': {'bhtheme.*
                     'parent_children.validators':
                         'OneToMany,SingleProduct,NoCycles',
                     'refersto.label': 'Refers to',
+                    'duplicate': 'duplicateof,duplicatedby',
+                    'duplicate.validators': 'ReferencesOlder',
+                    'duplicateof.label': 'Duplicate of',
+                    'duplicatedby.label': 'Duplicated by',
                },
 
                }


Reply via email to