From 834f8d39c81a64a957645d70b07410aa81e3d367 Mon Sep 17 00:00:00 2001 From: Serghei Mihai Date: Fri, 21 Apr 2017 11:43:59 +0200 Subject: [PATCH] provisionning agent (#12910) --- corbo/hobo_agent/__init__.py | 0 corbo/hobo_agent/management/__init__.py | 0 corbo/hobo_agent/management/commands/__init__.py | 0 .../hobo_agent/management/commands/hobo_notify.py | 52 ++++++++++++++++++++++ debian/debian_config.py | 2 + 5 files changed, 54 insertions(+) create mode 100644 corbo/hobo_agent/__init__.py create mode 100644 corbo/hobo_agent/management/__init__.py create mode 100644 corbo/hobo_agent/management/commands/__init__.py create mode 100644 corbo/hobo_agent/management/commands/hobo_notify.py diff --git a/corbo/hobo_agent/__init__.py b/corbo/hobo_agent/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/corbo/hobo_agent/management/__init__.py b/corbo/hobo_agent/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/corbo/hobo_agent/management/commands/__init__.py b/corbo/hobo_agent/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/corbo/hobo_agent/management/commands/hobo_notify.py b/corbo/hobo_agent/management/commands/hobo_notify.py new file mode 100644 index 0000000..d7a7e17 --- /dev/null +++ b/corbo/hobo_agent/management/commands/hobo_notify.py @@ -0,0 +1,52 @@ +# corbo - Announces Manager +# Copyright (C) 2017 Entr'ouvert +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from hobo.agent.common.management.commands import hobo_notify + +from corbo.models import Subscription + +class Command(hobo_notify.Command): + + @classmethod + def process_notification(cls, tenant, notification): + super(Command, self).process_notification(cls, tenant, notification) + object_type = notification['objects']['@type'] + if object_type != 'user': + return + users = notification['objects']['data'] + action = notification['@type'] + if notification.get('full'): + uuids = [user['uuid'] for user in users] + Subscription.objects.filter(uuid__isnull=False).exclude(uuid__in=uuids).delete() + + for user in users: + for subscription in Subscription.objects.filter(uuid=user['uuid']): + if action == 'provision': + if subscription.identifier.startswith('mailto:'): + if user.get('email'): + subscription.identifier = 'mailto:%s' % user['email'] + else: + subscription.delete() + continue + elif subscription.identifier.startswith('sms:'): + if user.get('mobile'): + subscription.identifier = 'sms:%s' % user['mobile'] + else: + subscription.delete() + continue + subscription.save() + elif action == 'deprovision': + subscription.delete() diff --git a/debian/debian_config.py b/debian/debian_config.py index 743e9ca..fe2d43d 100644 --- a/debian/debian_config.py +++ b/debian/debian_config.py @@ -12,6 +12,8 @@ INSTALLED_APPS += ('mellon',) # execfile('/usr/lib/hobo/debian_config_common.py') +INSTALLED_APPS = ('corbo.hobo_agent', ) + INSTALLED_APPS + # # local settings # -- 2.11.0