Adrià Vilanova MartÃnez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | # Copyright 2016 The Chromium Authors |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 4 | |
| 5 | """Classes to display filter rules in templates.""" |
| 6 | from __future__ import print_function |
| 7 | from __future__ import division |
| 8 | from __future__ import absolute_import |
| 9 | |
| 10 | import logging |
| 11 | |
| 12 | from framework import template_helpers |
| 13 | |
| 14 | |
| 15 | class RuleView(template_helpers.PBProxy): |
| 16 | """Wrapper class that makes it easier to display a Rule via EZT.""" |
| 17 | |
| 18 | def __init__(self, rule_pb, users_by_id): |
| 19 | super(RuleView, self).__init__(rule_pb) |
| 20 | |
| 21 | self.action_type = '' |
| 22 | self.action_value = '' |
| 23 | |
| 24 | if rule_pb is None: |
| 25 | return # Just leave everything as '' |
| 26 | |
| 27 | # self.predicate is automatically available. |
| 28 | |
| 29 | # For the current UI, we assume that each rule has exactly |
| 30 | # one action, so we can determine the text value for it here. |
| 31 | if rule_pb.default_status: |
| 32 | self.action_type = 'default_status' |
| 33 | self.action_value = rule_pb.default_status |
| 34 | elif rule_pb.default_owner_id: |
| 35 | self.action_type = 'default_owner' |
| 36 | self.action_value = users_by_id[rule_pb.default_owner_id].email |
| 37 | elif rule_pb.add_cc_ids: |
| 38 | self.action_type = 'add_ccs' |
| 39 | usernames = [users_by_id[cc_id].email for cc_id in rule_pb.add_cc_ids] |
| 40 | self.action_value = ', '.join(usernames) |
| 41 | elif rule_pb.add_labels: |
| 42 | self.action_type = 'add_labels' |
| 43 | self.action_value = ', '.join(rule_pb.add_labels) |
| 44 | elif rule_pb.add_notify_addrs: |
| 45 | self.action_type = 'also_notify' |
| 46 | self.action_value = ', '.join(rule_pb.add_notify_addrs) |
| 47 | elif rule_pb.warning: |
| 48 | self.action_type = 'warning' |
| 49 | self.action_value = rule_pb.warning |
| 50 | elif rule_pb.error: |
| 51 | self.action_type = 'error' |
| 52 | self.action_value = rule_pb.error |