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