Projet

Général

Profil

0001-hobo-don-t-require-all-role-attributes-when-deprovis.patch

Frédéric Péters, 29 octobre 2016 22:15

Télécharger (5,23 ko)

Voir les différences:

Subject: [PATCH] hobo: don't require all role attributes when deprovisionning
 (13799)

 tests/test_hobo_notify.py | 32 +++++++++++++++++++++++---------
 wcs/ctl/hobo_notify.py    | 47 +++++++++++++++++++++++++++--------------------
 2 files changed, 50 insertions(+), 29 deletions(-)
tests/test_hobo_notify.py
234 234
    notification = {
235 235
        '@type': u'deprovision',
236 236
        'audience': [u'test'],
237
        'full': True,
237
        'full': False,
238 238
        'objects': {
239 239
            '@type': 'role',
240 240
            'data': [
241 241
                {
242 242
                    '@type': 'role',
243
                    'name': u'Service état civil',
244
                    'slug': u'service-ett-civil',
245
                    'description': u'Rôle du service état civil',
246 243
                    'uuid': u'xyz',
247
                    'emails': [u'etat-civil@example.com'],
248
                    'emails_to_members': True,
249 244
                },
250 245
            ]
251 246
        }
252 247
    }
248
    role = Role.select()[0]
249
    role.remove_self()
250
    assert role.name == 'Service étt civil'
251
    assert role.slug == 'service-ett-civil'
252
    role.id = 'xyz'
253
    role.store()
254

  
255
    role = Role('foo')
256
    role.slug = 'bar'
257
    role.store()
258

  
259
    assert Role.count() == 2
260
    CmdHoboNotify.process_notification(notification)
253 261
    assert Role.count() == 1
254
    assert Role.select()[0].name == 'Service étt civil'
255
    assert Role.select()[0].slug == 'service-ett-civil'
262
    assert Role.select()[0].slug == 'bar'
263

  
264
    r = Role(name='Service étt civil')
265
    r.slug = 'xyz'
266
    r.store()
267
    assert Role.count() == 2
256 268
    CmdHoboNotify.process_notification(notification)
257
    assert Role.count() == 0
269
    assert Role.count() == 1
270
    assert Role.select()[0].slug == 'bar'
271

  
258 272

  
259 273
PROFILE = {
260 274
    'fields': [
wcs/ctl/hobo_notify.py
95 95
    @classmethod
96 96
    def check_valid_role(cls, o):
97 97
        return 'uuid' in o \
98
           or 'name' in o \
99
           or 'emails' in o \
100
           or 'emails_to_members' in o \
101
           or 'slug' in o
98
           and 'name' in o \
99
           and 'emails' in o \
100
           and 'emails_to_members' in o \
101
           and 'slug' in o
102 102

  
103 103
    @classmethod
104 104
    def provision_role(cls, publisher, issuer, action, data, full=False):
105 105
        uuids = set()
106 106
        for o in data:
107
            assert cls.check_valid_role(o)
107
            assert 'uuid' in o
108 108
            uuid = o['uuid'].encode(publisher.site_charset)
109 109
            uuids.add(uuid)
110
            slug = o['slug'].encode(publisher.site_charset)
111
            details = o.get('details', '').encode(publisher.site_charset) or None
112
            name = o['name'].encode(publisher.site_charset)
113
            emails = [email.encode(publisher.site_charset) for email in o['emails']]
114
            emails_to_members = o['emails_to_members']
110
            slug = None
111
            if action == 'provision':
112
                assert cls.check_valid_role(o)
113
                slug = o['slug'].encode(publisher.site_charset)
114
                details = o.get('details', '').encode(publisher.site_charset) or None
115
                name = o['name'].encode(publisher.site_charset)
116
                emails = [email.encode(publisher.site_charset) for email in o['emails']]
117
                emails_to_members = o['emails_to_members']
115 118
            # Find existing role
119
            role = None
116 120
            try:
117 121
                role = Role.get(uuid)
118 122
            except KeyError:
119
                try:
120
                    role = Role.get_on_index(uuid, 'slug')
121
                except KeyError:
123
                for slug_id in (slug, uuid):
124
                    if not slug_id:
125
                        continue
122 126
                    try:
123
                        role = Role.get_on_index(slug, 'slug')
127
                        role = Role.get_on_index(slug_id, 'slug')
128
                        break
124 129
                    except KeyError:
125
                        # New role
126
                        if action != 'provision':
127
                            continue
128
                        role = Role()
129
                        role.id = uuid
130
                        continue
131
                else:
132
                    # New role
133
                    if action != 'provision':
134
                        continue
135
                    role = Role()
136
                    role.id = uuid
130 137
            if action == 'provision':
131 138
                # Provision/rename
132 139
                role.name = name
......
139 146
                # Deprovision
140 147
                role.remove_self()
141 148
        # All roles have been sent
142
        if full:
149
        if full and action == 'provision':
143 150
            for role in Role.select():
144 151
                if role.slug not in uuids:
145 152
                    role.remove_self()
146
-