diff --git a/src/authentic2/manager/user_views.py b/src/authentic2/manager/user_views.py index 6c50643d0..c94b46d05 100644 --- a/src/authentic2/manager/user_views.py +++ b/src/authentic2/manager/user_views.py @@ -355,7 +355,9 @@ class UsersExportView(ExportMixin, UsersView): at_mapping = {a.id: a for a in Attribute.objects.all()} avs = AttributeValue.objects.filter( - content_type=ContentType.objects.get_for_model(get_user_model())).values() + content_type=ContentType.objects.get_for_model(get_user_model()))\ + .filter(attribute__disabled=False).values() + user_attrs = collections.defaultdict(dict) for av in avs: user_attrs[av['object_id']][at_mapping[av['attribute_id']].name] = av['content'] diff --git a/tests/test_user_manager.py b/tests/test_user_manager.py index a23fc1b87..c5298751b 100644 --- a/tests/test_user_manager.py +++ b/tests/test_user_manager.py @@ -131,3 +131,27 @@ def test_export_csv(settings, app, superuser, django_assert_num_queries): assert len(table) == (user_count + 1) assert len(table[0]) == (15 + AT_COUNT) + +@skipif_sqlite +def test_export_csv_disabled_attribute(settings, app, superuser): + attr = Attribute.objects.create(name='attr', label='Attr', kind='string') + attr_d = Attribute.objects.create(name='attrd', label='Attrd', kind='string') + + user = User.objects.create(username='user-foo') + AttributeValue.objects.create(owner=user, attribute=attr, content='attr-value') + AttributeValue.objects.create(owner=user, attribute=attr_d, content='attrd-value') + + attr_d.disabled = True + attr_d.save() + + response = login(app, superuser, reverse('a2-manager-users')) + settings.A2_CACHE_ENABLED = True + response = response.click('CSV') + + user_count = User.objects.count() + table = list(csv.reader(response.content.splitlines())) + assert len(table) == (user_count + 1) + num_col = 15 + 1 # 1 is the number active attributes, + # disabled attribute should not show up + for line in table: + assert len(line) == num_col