Beispiel #1
0
    def GatherPageData(self, mr):
        """Build up a dictionary of data values to use when rendering the page.

    Args:
      mr: commonly used info parsed from the request.

    Returns:
      Dict of values used by EZT for rendering the page.
    """
        page_data = super(AdminRules, self).GatherPageData(mr)
        rules = self.services.features.GetFilterRules(mr.cnxn, mr.project_id)
        users_by_id = framework_views.MakeAllUserViews(
            mr.cnxn, self.services.user,
            [rule.default_owner_id for rule in rules],
            *[rule.add_cc_ids for rule in rules])
        framework_views.RevealAllEmailsToMembers(mr.auth, mr.project,
                                                 users_by_id)
        rule_views = [
            filterrules_views.RuleView(rule, users_by_id) for rule in rules
        ]

        for idx, rule_view in enumerate(rule_views):
            rule_view.idx = idx + 1  # EZT has no loop index, so we set idx.

        page_data.update({
            'rules':
            rule_views,
            'new_rule_indexes':
            (list(range(len(rules) + 1, filterrules_helpers.MAX_RULES + 1))),
            'max_rules':
            filterrules_helpers.MAX_RULES,
        })
        return page_data
 def testDefaultOwner(self):
     self.rule.default_owner_id = 111
     view = filterrules_views.RuleView(
         self.rule,
         {111: testing_helpers.Blank(email='*****@*****.**')})
     self.assertEquals('label:a label:b', view.predicate)
     self.assertEquals('default_owner', view.action_type)
     self.assertEquals('*****@*****.**', view.action_value)
 def testAddCCs(self):
     self.rule.add_cc_ids.extend([111, 222])
     view = filterrules_views.RuleView(
         self.rule, {
             111: testing_helpers.Blank(email='*****@*****.**'),
             222: testing_helpers.Blank(email='*****@*****.**')
         })
     self.assertEquals('label:a label:b', view.predicate)
     self.assertEquals('add_ccs', view.action_type)
     self.assertEquals('[email protected], [email protected]',
                       view.action_value)
Beispiel #4
0
 def testAlsoNotify(self):
     self.rule.add_notify_addrs.extend(['*****@*****.**', '*****@*****.**'])
     view = filterrules_views.RuleView(self.rule, {})
     self.assertEquals('label:a label:b', view.predicate)
     self.assertEquals('also_notify', view.action_type)
     self.assertEquals('[email protected], [email protected]', view.action_value)
Beispiel #5
0
 def testAddLabels(self):
     self.rule.add_labels.extend(['Hot', 'Cool'])
     view = filterrules_views.RuleView(self.rule, {})
     self.assertEquals('label:a label:b', view.predicate)
     self.assertEquals('add_labels', view.action_type)
     self.assertEquals('Hot, Cool', view.action_value)
Beispiel #6
0
 def testDefaultStatus(self):
     self.rule.default_status = 'Unknown'
     view = filterrules_views.RuleView(self.rule, {})
     self.assertEquals('label:a label:b', view.predicate)
     self.assertEquals('default_status', view.action_type)
     self.assertEquals('Unknown', view.action_value)
Beispiel #7
0
 def testEmpty(self):
     view = filterrules_views.RuleView(self.rule, {})
     self.rule.predicate = ''
     self.assertEquals('', view.predicate)
     self.assertEquals('', view.action_type)
     self.assertEquals('', view.action_value)
Beispiel #8
0
 def testNone(self):
     view = filterrules_views.RuleView(None, {})
     self.assertEquals('', view.action_type)
     self.assertEquals('', view.action_value)