From 5eb569dfae1f882c832a37d9bbc1b25f3451e5b5 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Tue, 23 Feb 2021 16:03:07 +0100 Subject: [PATCH] csv_import: ignore empty role values (#50158) --- src/authentic2/csv_import.py | 2 ++ tests/test_csv_import.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/authentic2/csv_import.py b/src/authentic2/csv_import.py index d92eb1ef..112900b6 100644 --- a/src/authentic2/csv_import.py +++ b/src/authentic2/csv_import.py @@ -744,6 +744,8 @@ class UserCsvImporter(object): return success def add_role(self, cell, user, do_clear=False): + if not cell.value.strip(): + return True try: if cell.header.name == ROLE_NAME: role = Role.objects.get(name=cell.value, ou=self.ou) diff --git a/tests/test_csv_import.py b/tests/test_csv_import.py index a5663555..c28dc505 100644 --- a/tests/test_csv_import.py +++ b/tests/test_csv_import.py @@ -496,6 +496,12 @@ tnoel@entrouvert.com,test_name''' assert importer.has_errors assert importer.errors[0].code == 'invalid-role-column' + # empty role name doesn't raise error + content_name_error = '\n'.join((base_header + '_role_name', base_user + '')) + importer = user_csv_importer_factory(content_name_error) + assert importer.run() + assert not importer.has_errors + def test_csv_registration_options(profile, user_csv_importer_factory): content = '''email key,first_name,last_name,@registration -- 2.20.1