diff --git a/dashboard/app/models/user.rb b/dashboard/app/models/user.rb index aa016b41f6d59..d59c83c71446b 100644 --- a/dashboard/app/models/user.rb +++ b/dashboard/app/models/user.rb @@ -247,6 +247,7 @@ class User < ActiveRecord::Base has_many :user_geos, -> {order 'updated_at desc'} + before_validation :normalize_parent_email validate :validate_parent_email after_create :associate_with_potential_pd_enrollments @@ -2080,6 +2081,10 @@ def get_student_hidden_ids(assign_id, hidden_stages) end end + def normalize_parent_email + self.parent_email = nil if parent_email.blank? + end + # Parent email is not required, but if it is present, it must be a # well-formed email address. def validate_parent_email diff --git a/dashboard/test/controllers/registrations_controller/update_test.rb b/dashboard/test/controllers/registrations_controller/update_test.rb index f5c5d95884c46..3b9200856f4b8 100644 --- a/dashboard/test/controllers/registrations_controller/update_test.rb +++ b/dashboard/test/controllers/registrations_controller/update_test.rb @@ -223,6 +223,22 @@ class UpdateTest < ActionDispatch::IntegrationTest assert_nil student.parent_email end + test "single-auth student can update with a blank parent email without password" do + student = create :student, :unmigrated_clever_sso + assert_nil student.hashed_email + assert_nil student.parent_email + + sign_in student + put '/users', params: { + format: 'json', + user: {parent_email: '', age: '9'} + } + assert_response :no_content + + student.reload + assert_nil student.parent_email + end + # The next several tests explore profile changes for users with or without # passwords. Examples of users without passwords are users that authenticate # via oauth (a third-party account), or students with a picture password.