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