forked from fedora-infra/fedmsg_meta_fedora_infrastructure
/
fmn.py
83 lines (71 loc) · 3.12 KB
/
fmn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# This file is part of fedmsg.
# Copyright (C) 2014 Red Hat, Inc.
#
# fedmsg is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# fedmsg is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with fedmsg; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Authors: Ralph Bean <rbean@redhat.com>
import six
from fedmsg_meta_fedora_infrastructure.fasshim import avatar_url
from fedmsg_meta_fedora_infrastructure import BaseProcessor
class FMNProcessor(BaseProcessor):
__name__ = "FMN"
__description__ = "the Fedora Notifications System"
__link__ = "https://apps.fedoraproject.org/notifications/"
__icon__ = "https://apps.fedoraproject.org/img/icons/fedmsg.png"
__docs__ = "https://github.com/fedora-infra/fmn"
__obj__ = "Notification Preference Updates"
def subtitle(self, msg, **config):
kwargs = dict(
user=self.username(msg),
ctx=msg['msg']['context'],
obj=msg['topic'].split('.')[-2],
changed=msg['msg']['changed'],
)
if 'fmn.confirmation.update' in msg['topic']:
tmpl = self._("the {changed} of one of {user}'s "
"pending confirmations changed")
elif 'fmn.rule.update' in msg['topic']:
tmpl = self._("{user} updated the {changed} on a fmn {ctx} rule")
elif 'fmn.filter.update' in msg['topic']:
tmpl = self._("{user} updated the {changed} on a fmn {ctx} filter")
elif 'fmn.preference.update' in msg['topic']:
if 'enabled' == kwargs['changed']:
tmpl = self._("{user} toggled their flow of {ctx} messages")
else:
swaps = {
'batch_values': self._('digest options'),
'details': self._('delivery details'),
}
changed = kwargs['changed']
kwargs['changed'] = swaps.get(changed, changed)
tmpl = self._("{user} updated their {ctx} {changed}")
else:
tmpl = ''
return tmpl.format(**kwargs)
def link(self, msg, **config):
return self.__link__
def secondary_icon(self, msg, **config):
return avatar_url(self.username(msg))
def usernames(self, msg, **config):
return set([self.username(msg)])
def username(self, msg):
return msg['msg']['openid'].split('.')[0]
def objects(self, msg, **config):
user = self.username(msg)
ctx = msg['msg']['context']
obj = msg['topic'].split('.')[-2]
changed = msg['msg']['changed']
tokens = [user, ctx, obj, changed]
return set(['/'.join(map(six.text_type, tokens))])