Projet

Général

Profil

0001-provisionning-agent-12910.patch

Serghei Mihai, 01 juin 2017 11:00

Télécharger (4,07 ko)

Voir les différences:

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
corbo/hobo_agent/management/commands/hobo_notify.py
1
# corbo - Announces Manager
2
# Copyright (C) 2017 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(Command, self).process_notification(cls, tenant, notification)
26
        object_type = notification['objects']['@type']
27
        if object_type != 'user':
28
            return
29
        users = notification['objects']['data']
30
        action = notification['@type']
31
        if notification.get('full'):
32
            uuids = [user['uuid'] for user in users]
33
            Subscription.objects.filter(uuid__isnull=False).exclude(uuid__in=uuids).delete()
34

  
35
        for user in users:
36
            for subscription in Subscription.objects.filter(uuid=user['uuid']):
37
                if action == 'provision':
38
                    if subscription.identifier.startswith('mailto:'):
39
                        if user.get('email'):
40
                            subscription.identifier = 'mailto:%s' % user['email']
41
                        else:
42
                            subscription.delete()
43
                            continue
44
                    elif subscription.identifier.startswith('sms:'):
45
                        if user.get('mobile'):
46
                            subscription.identifier = 'sms:%s' % user['mobile']
47
                        else:
48
                            subscription.delete()
49
                            continue
50
                    subscription.save()
51
                elif action == 'deprovision':
52
                    subscription.delete()
debian/debian_config.py
12 12
#
13 13
execfile('/usr/lib/hobo/debian_config_common.py')
14 14

  
15
INSTALLED_APPS = ('corbo.hobo_agent', ) + INSTALLED_APPS
16

  
15 17
#
16 18
# local settings
17 19
#
18
-