Projet

Général

Profil

0001-misc-skip-users-with-no-email-in-clean-unused-accoun.patch

Frédéric Péters, 09 août 2022 07:58

Télécharger (2,18 ko)

Voir les différences:

Subject: [PATCH] misc: skip users with no email in clean-unused-accounts
 (#67998)

 .../management/commands/clean-unused-accounts.py     |  5 ++++-
 tests/test_commands.py                               | 12 ++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
src/authentic2/management/commands/clean-unused-accounts.py
67 67
        # exclude user from LDAP directories based on their source name (or realm)
68 68
        realms = [block['realm'] for block in LDAPBackend.get_config() if block.get('realm')]
69 69
        self.user_qs = (
70
            get_user_queryset().exclude(oidc_account__isnull=False).exclude(userexternalid__source__in=realms)
70
            get_user_queryset()
71
            .exclude(oidc_account__isnull=False)
72
            .exclude(userexternalid__source__in=realms)
73
            .exclude(email='')
71 74
        )
72 75

  
73 76
        translation.activate(settings.LANGUAGE_CODE)
tests/test_commands.py
208 208
    assert 'href="http://testserver/login/"' in mail.message().as_string()
209 209

  
210 210

  
211
def test_clean_unused_account_with_no_email(simple_user, mailoutbox, caplog):
212
    simple_user.email = ''
213
    simple_user.ou.clean_unused_accounts_alert = 1
214
    simple_user.ou.clean_unused_accounts_deletion = 2
215
    simple_user.ou.save()
216
    simple_user.last_login = now() - datetime.timedelta(days=1)
217
    simple_user.save()
218
    call_command('clean-unused-accounts')
219
    assert len(mailoutbox) == 0
220
    assert 'clean-unused-accounts failed' not in caplog.text
221

  
222

  
211 223
def test_cleanupauthentic(db):
212 224
    call_command('cleanupauthentic')
213 225

  
214
-