mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 15:14:16 +08:00
FIX: Partial reply key search in email sent logs.
Follow up to c85b9c6ed3a847ce0df7d58340d6680536d92b90
This commit is contained in:
@ -32,7 +32,7 @@ class Admin::EmailController < Admin::AdminController
|
|||||||
|
|
||||||
if params[:reply_key].present?
|
if params[:reply_key].present?
|
||||||
email_logs = email_logs.where(
|
email_logs = email_logs.where(
|
||||||
"CAST (post_reply_keys.reply_key AS VARCHAR) ILIKE ?", "%#{params[:reply_key]}%"
|
"post_reply_keys.reply_key::TEXT ILIKE ?", "%#{params[:reply_key]}%"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -73,10 +73,6 @@ class EmailLog < ActiveRecord::Base
|
|||||||
.first
|
.first
|
||||||
end
|
end
|
||||||
|
|
||||||
def bounce_key
|
|
||||||
super&.delete('-')
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# == Schema Information
|
# == Schema Information
|
||||||
|
@ -8,12 +8,8 @@ class PostReplyKey < ActiveRecord::Base
|
|||||||
validates :user_id, presence: true
|
validates :user_id, presence: true
|
||||||
validates :reply_key, presence: true
|
validates :reply_key, presence: true
|
||||||
|
|
||||||
def reply_key
|
|
||||||
super&.delete('-')
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.generate_reply_key
|
def self.generate_reply_key
|
||||||
SecureRandom.hex(16)
|
SecureRandom.uuid
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -12,6 +12,6 @@ class EmailLogSerializer < ApplicationSerializer
|
|||||||
end
|
end
|
||||||
|
|
||||||
def reply_key
|
def reply_key
|
||||||
@options[:reply_keys][[object.post_id, object.user_id]].delete("-")
|
@options[:reply_keys][[object.post_id, object.user_id]]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -103,8 +103,7 @@ describe EmailLog do
|
|||||||
.pluck("bounce_key::text")
|
.pluck("bounce_key::text")
|
||||||
.first
|
.first
|
||||||
|
|
||||||
expect(raw_key).to_not eq(hex)
|
expect(raw_key).to eq(hex)
|
||||||
expect(raw_key.delete('-')).to eq(hex)
|
|
||||||
expect(EmailLog.find(email_log.id).bounce_key).to eq(hex)
|
expect(EmailLog.find(email_log.id).bounce_key).to eq(hex)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,7 +3,7 @@ require 'rails_helper'
|
|||||||
RSpec.describe PostReplyKey do
|
RSpec.describe PostReplyKey do
|
||||||
describe "#reply_key" do
|
describe "#reply_key" do
|
||||||
it "should format the reply_key correctly" do
|
it "should format the reply_key correctly" do
|
||||||
hex = SecureRandom.hex
|
hex = SecureRandom.uuid
|
||||||
post_reply_key = Fabricate(:post_reply_key,
|
post_reply_key = Fabricate(:post_reply_key,
|
||||||
reply_key: hex
|
reply_key: hex
|
||||||
)
|
)
|
||||||
@ -12,8 +12,7 @@ RSpec.describe PostReplyKey do
|
|||||||
.pluck("reply_key::text")
|
.pluck("reply_key::text")
|
||||||
.first
|
.first
|
||||||
|
|
||||||
expect(raw_key).to_not eq(hex)
|
expect(raw_key).to eq(hex)
|
||||||
expect(raw_key.delete('-')).to eq(hex)
|
|
||||||
expect(PostReplyKey.find(post_reply_key.id).reply_key).to eq(hex)
|
expect(PostReplyKey.find(post_reply_key.id).reply_key).to eq(hex)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -58,6 +58,32 @@ describe Admin::EmailController do
|
|||||||
expect(log["id"]).to eq(email_log.id)
|
expect(log["id"]).to eq(email_log.id)
|
||||||
expect(log["reply_key"]).to eq(post_reply_key.reply_key)
|
expect(log["reply_key"]).to eq(post_reply_key.reply_key)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should be able to filter by reply key' do
|
||||||
|
email_log_2 = Fabricate(:email_log, post: post)
|
||||||
|
|
||||||
|
post_reply_key_2 = Fabricate(:post_reply_key,
|
||||||
|
post: post,
|
||||||
|
user: email_log_2.user,
|
||||||
|
reply_key: "2d447423-c625-4fb9-8717-ff04ac60eee8"
|
||||||
|
)
|
||||||
|
|
||||||
|
[
|
||||||
|
"17-ff04",
|
||||||
|
"2d447423-c625-4fb9-8717-ff04ac60eee8"
|
||||||
|
].each do |reply_key|
|
||||||
|
get "/admin/email/sent.json", params: {
|
||||||
|
reply_key: reply_key
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
|
||||||
|
logs = JSON.parse(response.body)
|
||||||
|
|
||||||
|
expect(logs.size).to eq(1)
|
||||||
|
expect(logs.first["reply_key"]).to eq(post_reply_key_2.reply_key)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#skipped' do
|
describe '#skipped' do
|
||||||
|
Reference in New Issue
Block a user