From fc472e40c18e5208693be150dd942d2840b29d9c 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 | 6 ++++-- tests/test_csv_import.py | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/authentic2/csv_import.py b/src/authentic2/csv_import.py index d92eb1ef..5c64460b 100644 --- a/src/authentic2/csv_import.py +++ b/src/authentic2/csv_import.py @@ -589,7 +589,7 @@ class UserCsvImporter(object): if header.name == SOURCE_ID: unique_key = (SOURCE_ID, row[SOURCE_NAME].value, cell.value) elif header.key or header.globally_unique or header.unique: - if not cell.value: + if not cell.value.strip(): # empty values are not checked continue unique_key = (header.name, cell.value) @@ -611,7 +611,7 @@ class UserCsvImporter(object): for cell in row: if (not cell.header.globally_unique and not cell.header.unique) or (user and not cell.header.update): continue - if not cell.value: + if not cell.value.strip(): continue qs = ou_users if cell.header.globally_unique: @@ -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