mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
FIX: The "too similar" check happened when trying to make a post a wiki
This commit is contained in:
parent
b56999e984
commit
f15b0d205f
5 changed files with 30 additions and 5 deletions
|
@ -121,7 +121,7 @@ class Post < ActiveRecord::Base
|
|||
|
||||
# The key we use in redis to ensure unique posts
|
||||
def unique_post_key
|
||||
"post-#{user_id}:#{raw_hash}"
|
||||
"unique-post-#{user_id}:#{raw_hash}"
|
||||
end
|
||||
|
||||
def store_unique_post_key
|
||||
|
@ -132,7 +132,7 @@ class Post < ActiveRecord::Base
|
|||
|
||||
def matches_recent_post?
|
||||
post_id = $redis.get(unique_post_key)
|
||||
post_id != nil and post_id != id
|
||||
post_id != nil and post_id.to_i != id
|
||||
end
|
||||
|
||||
def raw_hash
|
||||
|
|
|
@ -70,6 +70,10 @@ class DiscourseRedis
|
|||
}
|
||||
end
|
||||
|
||||
def delete_prefixed(prefix)
|
||||
keys("#{prefix}*").each { |k| $redis.del(k) }
|
||||
end
|
||||
|
||||
def flushdb
|
||||
keys.each{|k| del(k)}
|
||||
end
|
||||
|
|
|
@ -211,6 +211,7 @@ class PostRevisor
|
|||
clear_flags_and_unhide_post
|
||||
|
||||
@post.extract_quoted_post_numbers
|
||||
|
||||
@post_successfully_saved = @post.save(validate: @validate_post)
|
||||
@post.save_reply_relationships
|
||||
end
|
||||
|
|
|
@ -4,7 +4,9 @@ require_dependency 'rate_limiter/on_create_record'
|
|||
# A redis backed rate limiter.
|
||||
class RateLimiter
|
||||
|
||||
KEY_PREFIX = "l-rate-limit:"
|
||||
def self.key_prefix
|
||||
"l-rate-limit:"
|
||||
end
|
||||
|
||||
def self.disable
|
||||
@disabled = true
|
||||
|
@ -20,12 +22,12 @@ class RateLimiter
|
|||
end
|
||||
|
||||
def self.clear_all!
|
||||
$redis.keys("#{KEY_PREFIX}:*").each { |k| $redis.del(k) }
|
||||
$redis.delete_prefixed(RateLimiter.key_prefix)
|
||||
end
|
||||
|
||||
def initialize(user, key, max, secs)
|
||||
@user = user
|
||||
@key = "#{KEY_PREFIX}:#{@user && @user.id}:#{key}"
|
||||
@key = "#{RateLimiter.key_prefix}:#{@user && @user.id}:#{key}"
|
||||
@max = max
|
||||
@secs = secs
|
||||
end
|
||||
|
|
|
@ -39,6 +39,24 @@ describe PostRevisor do
|
|||
end
|
||||
end
|
||||
|
||||
context 'revise wiki' do
|
||||
|
||||
before do
|
||||
# There used to be a bug where wiki changes were considered posting "too similar"
|
||||
# so this is enabled and checked
|
||||
$redis.delete_prefixed('unique-post')
|
||||
SiteSetting.unique_posts_mins = 10
|
||||
end
|
||||
|
||||
it 'allows the user to change it to a wiki' do
|
||||
pc = PostCreator.new(newuser, topic_id: topic.id, raw: 'this is a post that will become a wiki')
|
||||
post = pc.create
|
||||
post.revise(post.user, wiki: true).should == true
|
||||
post.reload
|
||||
post.wiki.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context 'revise' do
|
||||
let(:post) { Fabricate(:post, post_args) }
|
||||
let(:first_version_at) { post.last_version_at }
|
||||
|
|
Loading…
Reference in a new issue