diff --git a/app/controllers/contact_requests_controller.rb b/app/controllers/contact_requests_controller.rb index 59c7d624..c7854599 100644 --- a/app/controllers/contact_requests_controller.rb +++ b/app/controllers/contact_requests_controller.rb @@ -39,7 +39,7 @@ def redirect_to_main end def show - if @contact_request.confirm_email + if @contact_request.confirmable? redirect_to edit_contact_request_url else redirect_to root_url, alert: t('contact_requests.already_used') @@ -51,12 +51,14 @@ def edit; end def update email_body = params[:email_body] recipients = params[:recipients] + @contact_request.confirm_email if @contact_request.send_contact_email(body: email_body, recipients: recipients) logger.warn( "Email sent to #{@contact_request.whois_record.name} contacts " \ "from #{@contact_request.email} (IP: #{request.ip})" ) + render :request_completed else redirect_to(:root, alert: t('contact_requests.something_went_wrong')) diff --git a/app/models/contact_request.rb b/app/models/contact_request.rb index 7548671f..ddfc7885 100644 --- a/app/models/contact_request.rb +++ b/app/models/contact_request.rb @@ -64,6 +64,9 @@ def completed_or_expired? status == STATUS_SENT || !still_valid? || !whois_record_exists? end + def confirmable? + status == STATUS_NEW && still_valid? && whois_record_exists? + end private def extract_emails_for_recipients(recipients) @@ -83,10 +86,6 @@ def sendable? status == STATUS_CONFIRMED && still_valid? && whois_record_exists? end - def confirmable? - status == STATUS_NEW && still_valid? && whois_record_exists? - end - def still_valid? valid_to >= Time.zone.now end diff --git a/test/integration/contact_requests_test.rb b/test/integration/contact_requests_test.rb index 53353f91..e5c63374 100644 --- a/test/integration/contact_requests_test.rb +++ b/test/integration/contact_requests_test.rb @@ -25,11 +25,11 @@ def test_request_replay_fails end end - def test_opening_link_twice_redirects_you_to_root_with_notice_that_this_link_has_been_used + def test_opening_link_twice_does_not_invalidate_link_if_not_used visit(contact_request_path(@valid_contact_request.secret)) visit(contact_request_path(@valid_contact_request.secret)) - assert(page.has_css?('div#flash-alert', text: 'This one-time link has been already used.')) + assert_text('Message is limited to 2000 characters') end def test_request_fails_when_whois_record_was_deleted