Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit allowable child types based on parent. #12

Open
ChrisNelsonPE opened this issue Nov 2, 2010 · 0 comments
Open

Limit allowable child types based on parent. #12

ChrisNelsonPE opened this issue Nov 2, 2010 · 0 comments

Comments

@ChrisNelsonPE
Copy link

This feature is ported from ChildTickets plugin.


diff --git a/tracsubtickets/api.py b/tracsubtickets/api.py
index 71f2d67..9ad2674 100644
--- a/tracsubtickets/api.py
+++ b/tracsubtickets/api.py
@@ -181,6 +181,19 @@ class SubTicketsSystem(Component):
                         errors += _check_parents(x, all_parents)
                 return errors
 
+            def _check_types(ticket, parent):
+                if not self.config.getbool('subtickets', 
+                                           '%s.allow_child_tickets' % 
+                                           parent['type']):
+                    yield None, "The parent ticket (#%s) has type '%s' which does not allow child tickets." % (parent.id, parent['type'])
+
+                # It is possible that the parent restricts the
+                # type of children it allows.
+                allowedtypes = self.config.getlist('subtickets', 
+                                                   '%s.restrict_child_types' % parent['type'])
+                if allowedtypes and ticket['type'] not in allowedtypes:
+                    yield None, "The parent ticket (#%s) has type '%s' which does not allow child type '%s'. Must be one of: %s." % (parent.id,parent['type'],ticket['type'],','.join(allowedtypes))
+
             for x in ids:
                 # check parent ticket state
                 parent = Ticket(self.env, x)
@@ -192,9 +205,14 @@ class SubTicketsSystem(Component):
                     for error in _check_parents(int(x), all_parents):
                         yield error
 
+                    # Check type
+                    for error in _check_types(ticket, parent):
+                        yield error
+
             ticket['parents'] = ', '.join(sorted(ids, key=lambda x: int(x)))
 
         except Exception, e:
             self.log.error(e)
             yield 'parents', 'Not a valid list of ticket IDs'
 
+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant