Skip to content
Snippets Groups Projects
Commit d1b0e309 authored by Daniel Schultz's avatar Daniel Schultz :tm:
Browse files

Fix change email error

Users without a `slack` field could not change their email address due
to the fact that doing so would attempt to set the slack column to null
(and nulls are not allowed).

This updates the save of the change email field to only modify the slack
value if it exists.

Issue #2784 Changing email on non-staff accounts creates non-null
            constraint violation
parent f4b3cec8
No related branches found
No related tags found
No related merge requests found
......@@ -105,7 +105,8 @@ class EmailChangePasswordForm(forms.Form):
def save(self, updated_email, name, slack, commit=True):
self.user.full_name = name
self.user.slack = slack
if slack is not None:
self.user.slack = slack
if commit:
self.user.save()
return self.user
......
from django.forms.models import model_to_dict
from django.test import TestCase
from ..forms import ProfileForm
from ..forms import EmailChangePasswordForm, ProfileForm
from .factories import StaffFactory, UserFactory
......@@ -89,3 +89,18 @@ class TestStaffProfileForm(BaseTestProfileForm):
self.staff.refresh_from_db()
self.assertEqual(self.staff.slack, slack_name)
class TestEmailChangePasswordForm(TestCase):
def setUp(self):
self.user = UserFactory()
def test_doesnt_error_on_null_slack_field(self):
form = EmailChangePasswordForm(self.user)
form.save('', '', None)
def test_can_update_slack(self):
slack_name = 'foobar'
form = EmailChangePasswordForm(self.user)
form.save('', '', slack_name)
self.assertEqual(self.user.slack, slack_name)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment