0001-data_transfer-export-new-role-attributes-71844.patch
src/authentic2/a2_rbac/models.py | ||
---|---|---|
650 | 650 |
'ou__slug': self.ou.slug if self.ou else None, |
651 | 651 |
} |
652 | 652 | |
653 |
def export_json(self, attributes=False, parents=False, permissions=False):
|
|
653 |
def export_json(self, parents=False, permissions=False): |
|
654 | 654 |
d = { |
655 | 655 |
'uuid': self.uuid, |
656 | 656 |
'slug': self.slug, |
657 | 657 |
'name': self.name, |
658 | 658 |
'description': self.description, |
659 |
'details': self.details, |
|
660 |
'emails': self.emails, |
|
661 |
'emails_to_members': self.emails_to_members, |
|
662 |
'is_superuser': self.is_superuser, |
|
659 | 663 |
'external_id': self.external_id, |
660 | 664 |
'ou': self.ou and self.ou.natural_key_json(), |
661 | 665 |
'service': self.service and self.service.natural_key_json(), |
662 | 666 |
} |
663 | 667 | |
664 |
if attributes: |
|
665 |
for attribute in self.attributes.all(): |
|
666 |
d.setdefault('attributes', []).append(attribute.to_json()) |
|
667 | ||
668 | 668 |
if parents: |
669 | 669 |
for parenting in RoleParenting.objects.filter( |
670 | 670 |
child_id=self.id, direct=True, deleted__isnull=True |
tests/test_a2_rbac.py | ||
---|---|---|
145 | 145 | |
146 | 146 | |
147 | 147 |
def test_basic_role_export_json(db): |
148 |
role = Role.objects.create(name='basic role', slug='basic-role', description='basic role description') |
|
148 |
role = Role.objects.create( |
|
149 |
name='basic role', |
|
150 |
slug='basic-role', |
|
151 |
description='basic role description', |
|
152 |
emails=['test@example.org'], |
|
153 |
) |
|
149 | 154 |
role_dict = role.export_json() |
150 | 155 |
assert role_dict['name'] == role.name |
151 | 156 |
assert role_dict['slug'] == role.slug |
152 | 157 |
assert role_dict['uuid'] == role.uuid |
153 | 158 |
assert role_dict['description'] == role.description |
159 |
assert role_dict['details'] == role.details |
|
160 |
assert role_dict['emails'] == role.emails |
|
161 |
assert role_dict['emails_to_members'] == role.emails_to_members |
|
162 |
assert role_dict['is_superuser'] == role.is_superuser |
|
154 | 163 |
assert role_dict['external_id'] == role.external_id |
155 | 164 |
assert role_dict['ou'] is None |
156 | 165 |
assert role_dict['service'] is None |
tests/test_data_transfer.py | ||
---|---|---|
327 | 327 |
assert "Could not find parent role" in str(excinfo.value) |
328 | 328 | |
329 | 329 | |
330 |
def test_role_deserializer_emails(db): |
|
331 |
role_dict = { |
|
332 |
'name': 'test role', |
|
333 |
'slug': 'test-role-slug', |
|
334 |
'uuid': get_hex_uuid(), |
|
335 |
'ou': None, |
|
336 |
'emails': ['a@example.com'], |
|
337 |
} |
|
338 | ||
339 |
import_context = ImportContext() |
|
340 |
rd = RoleDeserializer(role_dict, import_context) |
|
341 |
rd.deserialize() |
|
342 | ||
343 |
role = Role.objects.get(slug='test-role-slug') |
|
344 |
assert role.emails == ['a@example.com'] |
|
345 | ||
346 | ||
330 | 347 |
def test_role_deserializer_permissions(db): |
331 | 348 |
ou = OU.objects.create(slug='some-ou') |
332 | 349 |
other_role_dict = {'name': 'other role', 'slug': 'other-role-slug', 'uuid': get_hex_uuid(), 'ou': ou} |
333 |
- |