Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent users changing their email addresses to non-governmental ones #2369

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/batch_invitation_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class BatchInvitationUser < ApplicationRecord
belongs_to :batch_invitation

validates :email, presence: true, format: { with: Devise.email_regexp }
validates :email, reject_non_governmental_email_addresses: true, on: :create
validates :email, reject_non_governmental_email_addresses: true

validates :outcome, inclusion: { in: [nil, "success", "failed", "skipped"] }

Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class User < ApplicationRecord
encrypts :otp_secret_key

validates :name, presence: true
validates :email, reject_non_governmental_email_addresses: true, on: :create
validates :email, reject_non_governmental_email_addresses: true
validates :reason_for_suspension, presence: true, if: proc { |u| u.suspended? }
validate :user_can_be_exempted_from_2sv
validate :organisation_admin_belongs_to_organisation
Expand Down
4 changes: 2 additions & 2 deletions test/models/batch_invitation_user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ class BatchInvitationUserTest < ActiveSupport::TestCase
user.errors[:email]
end

should "still allow user to be updated with a known non-government email address" do
should "not allow user to be updated with a known non-government email address" do
user = create(:batch_invitation_user, email: "alexia.statham@department.gov.uk")

user.email = "alexia.statham@yahoo.co.uk"

assert user.valid?
assert_not user.valid?
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,12 @@ def setup
user.errors[:email]
end

should "still allow user to be updated with a known non-government email address" do
should "not allow user to be updated with a known non-government email address" do
user = create(:batch_invitation_user, email: "alexia.statham@department.gov.uk")

user.email = "alexia.statham@yahoo.co.uk"

assert user.valid?
assert_not user.valid?
end

should "reject emails with invalid domain parts" do
Expand Down