diff --git a/CHANGELOG.md b/CHANGELOG.md index 59ef866..ef3df05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Change Log * Dropped support for Python 3.7. * Set same redirect URL for password resets as for setting an initial password. * Added some exception handling and error messages for cases where emails fail to send. +* Update the date_invited field when resending invitations. 4.1.0 ----- diff --git a/invite/views.py b/invite/views.py index 56b1fd7..205a271 100644 --- a/invite/views.py +++ b/invite/views.py @@ -235,6 +235,8 @@ def resend(request, code): return HttpResponseServerError( 'We\'re having trouble resending the invitation email, please try again later.' ) + i.date_invited = date.today() + i.save() resent_user = '%s %s' % (i.first_name, i.last_name) invites = Invitation.objects.all().order_by('-date_invited') diff --git a/tests/test_all.py b/tests/test_all.py index b092c6f..629a711 100644 --- a/tests/test_all.py +++ b/tests/test_all.py @@ -480,6 +480,9 @@ def test_forgotten_password(self): def test_resend(self): """Resend the invitation email to alpha invitee.""" + # Date should get reset to today, so make sure original date is in the past. + self.alpha_invite.date_invited = self.old_date + self.alpha_invite.save() self.client.login(username='superuser', password='superuser') code = str(self.alpha_invite.activation_code) response = self.client.post( @@ -491,6 +494,9 @@ def test_resend(self): 'Resent invitation email for {}'.format(self.alpha_invite.username), response.content.decode() ) + self.alpha_invite.refresh_from_db() + self.assertNotEqual(self.alpha_invite.date_invited, self.old_date) + self.assertEqual(self.alpha_invite.date_invited, datetime.date.today()) self.assertEqual(len(mail.outbox), 1) def test_resend_wrong_code(self): @@ -508,6 +514,8 @@ def test_resend_wrong_code(self): @mock.patch('invite.models.send_mail', side_effect=smtplib.SMTPException) def test_resend_email_not_sent(self, mock_send_mail): + # Date shouldn't get changed if email fails to send. + original_invite_date = self.alpha_invite.date_invited self.client.login(username='superuser', password='superuser') code = str(self.alpha_invite.activation_code) response = self.client.post( @@ -519,6 +527,8 @@ def test_resend_email_not_sent(self, mock_send_mail): "We're having trouble resending the invitation email", response.content.decode() ) + self.alpha_invite.refresh_from_db() + self.assertEqual(self.alpha_invite.date_invited, original_invite_date) self.assertEqual(len(mail.outbox), 0) @mock.patch('invite.views.app_settings')