Revert "FIX: Partial reply key search in email sent logs."

Revert “FIX: Partial reply key search in email sent logs.”

This reverts commit e9b2018bc8bc1254075bec597ce30a84f38b456e.

diff --git a/app/controllers/admin/email_controller.rb b/app/controllers/admin/email_controller.rb
index b1f28d4..8325070 100644
--- a/app/controllers/admin/email_controller.rb
+++ b/app/controllers/admin/email_controller.rb
@@ -30,10 +30,16 @@ class Admin::EmailController < Admin::AdminController
 
     email_logs = filter_logs(email_logs, params)
 
-    if params[:reply_key].present?
-      email_logs = email_logs.where(
-        "post_reply_keys.reply_key::TEXT ILIKE ?", "%#{params[:reply_key]}%"
-      )
+    if (reply_key = params[:reply_key]).present?
+      email_logs =
+        if reply_key.length == 32
+          email_logs.where("post_reply_keys.reply_key = ?", reply_key)
+        else
+          email_logs.where(
+            "replace(post_reply_keys.reply_key::VARCHAR, '-', '') ILIKE ?",
+            "%#{reply_key}%"
+          )
+        end
     end
 
     email_logs = email_logs.to_a
diff --git a/app/models/email_log.rb b/app/models/email_log.rb
index 0aeae60..769436e 100644
--- a/app/models/email_log.rb
+++ b/app/models/email_log.rb
@@ -73,6 +73,10 @@ class EmailLog < ActiveRecord::Base
       .first
   end
 
+  def bounce_key
+    super&.delete('-')
+  end
+
 end
 
 # == Schema Information
diff --git a/app/models/post_reply_key.rb b/app/models/post_reply_key.rb
index 2c85058..3f1479f 100644
--- a/app/models/post_reply_key.rb
+++ b/app/models/post_reply_key.rb
@@ -8,8 +8,12 @@ class PostReplyKey < ActiveRecord::Base
   validates :user_id, presence: true
   validates :reply_key, presence: true
 
+  def reply_key
+    super&.delete('-')
+  end
+
   def self.generate_reply_key
-    SecureRandom.uuid
+    SecureRandom.hex(16)
   end
 end
 
diff --git a/app/serializers/email_log_serializer.rb b/app/serializers/email_log_serializer.rb
index e4d120a..75c7010 100644
--- a/app/serializers/email_log_serializer.rb
+++ b/app/serializers/email_log_serializer.rb
@@ -12,6 +12,6 @@ class EmailLogSerializer < ApplicationSerializer
   end
 
   def reply_key
-    @options[:reply_keys][[object.post_id, object.user_id]]
+    @options[:reply_keys][[object.post_id, object.user_id]].delete("-")
   end
 end
diff --git a/spec/models/email_log_spec.rb b/spec/models/email_log_spec.rb
index 6124d32..f0f60da 100644
--- a/spec/models/email_log_spec.rb
+++ b/spec/models/email_log_spec.rb
@@ -103,7 +103,8 @@ describe EmailLog do
         .pluck("bounce_key::text")
         .first
 
-      expect(raw_key).to eq(hex)
+      expect(raw_key).to_not eq(hex)
+      expect(raw_key.delete('-')).to eq(hex)
       expect(EmailLog.find(email_log.id).bounce_key).to eq(hex)
     end
   end
diff --git a/spec/models/post_reply_key_spec.rb b/spec/models/post_reply_key_spec.rb
index 45f6d5e..631e6cd 100644
--- a/spec/models/post_reply_key_spec.rb
+++ b/spec/models/post_reply_key_spec.rb
@@ -3,7 +3,7 @@ require 'rails_helper'
 RSpec.describe PostReplyKey do
   describe "#reply_key" do
     it "should format the reply_key correctly" do
-      hex = SecureRandom.uuid
+      hex = SecureRandom.hex
       post_reply_key = Fabricate(:post_reply_key,
         reply_key: hex
       )
@@ -12,7 +12,8 @@ RSpec.describe PostReplyKey do
         .pluck("reply_key::text")
         .first
 
-      expect(raw_key).to eq(hex)
+      expect(raw_key).to_not eq(hex)
+      expect(raw_key.delete('-')).to eq(hex)
       expect(PostReplyKey.find(post_reply_key.id).reply_key).to eq(hex)
     end
   end
diff --git a/spec/requests/admin/email_controller_spec.rb b/spec/requests/admin/email_controller_spec.rb
index 8bee246..97cdef0 100644
--- a/spec/requests/admin/email_controller_spec.rb
+++ b/spec/requests/admin/email_controller_spec.rb
@@ -69,8 +69,8 @@ describe Admin::EmailController do
       )
 
       [
-        "17-ff04",
-        "2d447423-c625-4fb9-8717-ff04ac60eee8"
+        "17ff04",
+        "2d447423c6254fb98717ff04ac60eee8"
       ].each do |reply_key|
         get "/admin/email/sent.json", params: {
           reply_key: reply_key

GitHub sha: d1069415