|
1 |
# corbo - Announces Manager
|
|
2 |
# Copyright (C) 2016 Entr'ouvert
|
|
3 |
#
|
|
4 |
# This program is free software: you can redistribute it and/or modify it
|
|
5 |
# under the terms of the GNU Affero General Public License as published
|
|
6 |
# by the Free Software Foundation, either version 3 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU Affero General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU Affero General Public License
|
|
15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16 |
|
|
17 |
from hobo.agent.common.management.commands import hobo_notify
|
|
18 |
|
|
19 |
from corbo.models import Subscription
|
|
20 |
|
|
21 |
class Command(hobo_notify.Command):
|
|
22 |
|
|
23 |
@classmethod
|
|
24 |
def process_notification(cls, tenant, notification):
|
|
25 |
super(CommonCommand, self).process_notification(cls, tenant, notification)
|
|
26 |
object_type = notification['objects']['@type']
|
|
27 |
full = notification['full'] if 'full' in notification else False
|
|
28 |
if object_type != 'user':
|
|
29 |
return
|
|
30 |
data = notification['objects']['data']
|
|
31 |
action = notification['@type']
|
|
32 |
if full:
|
|
33 |
uuids = [obj['uuid'] for obj in data]
|
|
34 |
Subscription.objects.exclude(uuid__in=uuids).delete()
|
|
35 |
|
|
36 |
for obj in data:
|
|
37 |
for subscription in Subscription.objects.filter(uuid=obj['uuid']):
|
|
38 |
if action == 'provision':
|
|
39 |
if subscription.identifier.startswith('mailto:'):
|
|
40 |
if obj.get('email'):
|
|
41 |
subscription.identifier = 'mailto:%s' % obj['email']
|
|
42 |
else:
|
|
43 |
subscription.delete()
|
|
44 |
elif subscription.identifier.startswith('sms:'):
|
|
45 |
if obj.get('mobile'):
|
|
46 |
subscription.identifier = 'sms:%s' % obj['mobile']
|
|
47 |
else:
|
|
48 |
subscription.delete()
|
|
49 |
continue
|
|
50 |
subscription.save()
|
|
51 |
elif action == 'deprovision':
|
|
52 |
subscription.delete()
|