FIX: Invalid setex expire time in `DiscourseNarrativeBot::Actions#reset_rate_limits`.
This commit is contained in:
parent
12e4dd59b7
commit
9f873fa66c
|
@ -32,22 +32,23 @@ module DiscourseNarrativeBot
|
|||
|
||||
def reset_rate_limits(post)
|
||||
user = post.user
|
||||
data = DiscourseNarrativeBot::Store.get(user.id.to_s)
|
||||
|
||||
duration =
|
||||
if user && user.new_user?
|
||||
SiteSetting.rate_limit_new_user_create_post
|
||||
else
|
||||
SiteSetting.rate_limit_create_post
|
||||
end
|
||||
|
||||
return unless duration > 0
|
||||
|
||||
data = DiscourseNarrativeBot::Store.get(user.id.to_s)
|
||||
return unless data
|
||||
|
||||
key = "#{DiscourseNarrativeBot::PLUGIN_NAME}:reset-rate-limit:#{post.topic_id}:#{data['state']}"
|
||||
|
||||
if !(count = $redis.get(key))
|
||||
count = 0
|
||||
|
||||
duration =
|
||||
if user && user.new_user?
|
||||
SiteSetting.rate_limit_new_user_create_post
|
||||
else
|
||||
SiteSetting.rate_limit_create_post
|
||||
end
|
||||
|
||||
$redis.setex(key, duration, count)
|
||||
end
|
||||
|
||||
|
|
|
@ -211,6 +211,22 @@ describe DiscourseNarrativeBot::NewUserNarrative do
|
|||
expect(narrative.get_data(user)[:state].to_sym).to eq(:tutorial_bookmark)
|
||||
end
|
||||
|
||||
describe 'when rate_limit_new_user_create_post site setting is disabled' do
|
||||
before do
|
||||
SiteSetting.rate_limit_new_user_create_post = 0
|
||||
end
|
||||
|
||||
it 'should create the right reply' do
|
||||
narrative.input(:reply, user, post: post)
|
||||
new_post = Post.last
|
||||
|
||||
expect(new_post.raw).to eq(I18n.t(
|
||||
'discourse_narrative_bot.new_user_narrative.bookmark.not_found',
|
||||
base_uri: ''
|
||||
))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when reply contains the skip trigger' do
|
||||
it 'should create the right reply' do
|
||||
post.update!(raw: "@#{discobot_user.username} #{skip_trigger.upcase}")
|
||||
|
|
Loading…
Reference in New Issue