Skip to content

Commit 33401e1

Browse files
committed
Only validate emails on create
Previously we had allowed '+' style addressing but it was removed due to fraud concerns. However the validation for this now causes a petition save to fail if the original email address is now valid and the creator_signature association is loaded. We can fix this by moving the email validations to on creation only since the email address shouldn't be updated other than when it is anonymised after the 12 month window.
1 parent 5e2ed64 commit 33401e1

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

app/models/staged/validations/email.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Email
44
extend ActiveSupport::Concern
55

66
included do
7-
validates :email, presence: true, email: { allow_blank: true }
7+
validates :email, presence: true, email: { allow_blank: true }, on: :create
88
end
99
end
1010
end

app/models/staged/validations/multiple_signers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module MultipleSigners
44
extend ActiveSupport::Concern
55

66
included do
7-
validate do |signature|
7+
validate on: :create do |signature|
88
matcher = ::Signature.where(:email => signature.email, :petition_id => signature.petition_id)
99
matcher = matcher.where("signatures.id != ?", signature.id) unless signature.new_record?
1010
existing_email_address_count = matcher.count

spec/models/petition_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,6 +1897,31 @@
18971897
end
18981898
end
18991899
end
1900+
1901+
context "when the creator's signature is now invalid" do
1902+
let(:creator) { petition.creator_signature }
1903+
1904+
before do
1905+
creator.update_column(:email, "jo+123@public.com")
1906+
creator.reload
1907+
end
1908+
1909+
it "sets the state to STOPPED" do
1910+
expect {
1911+
petition.stop!(dissolution_at)
1912+
}.to change {
1913+
petition.state
1914+
}.from(Petition::PENDING_STATE).to(Petition::STOPPED_STATE)
1915+
end
1916+
1917+
it "sets the stopped date to the dissolution time" do
1918+
expect {
1919+
petition.stop!(dissolution_at)
1920+
}.to change {
1921+
petition.stopped_at
1922+
}.from(nil).to(dissolution_at)
1923+
end
1924+
end
19001925
end
19011926

19021927
describe '#flag' do

0 commit comments

Comments
 (0)