5
3
mirror of https://github.com/tildeverse/lobsters synced 2024-06-17 22:27:08 +00:00

quietly accept dupe comments

Fix #967
This commit is contained in:
Peter Bhat Harkins 2022-01-18 21:52:59 -06:00
parent 6301dea8a6
commit 7d52e54221
3 changed files with 24 additions and 10 deletions

View File

@ -154,7 +154,7 @@ RSpec/BeforeAfterAll:
Enabled: false
RSpec/DescribeClass:
Enabled: false
Rspec/LetSetup:
RSpec/LetSetup:
Enabled: false
Capybara/FeatureMethods:
Enabled: false

View File

@ -34,7 +34,16 @@ class CommentsController < ApplicationController
end
end
# prevent double-clicks of the post button
# sometimes on slow connections people resubmit; silently accept it
if (already = Comment.find_by(user: comment.user,
story: comment.story,
parent_comment_id: comment.parent_comment_id,
comment: comment.comment))
self.render_created_comment(already)
return
end
# rate-limit users to one reply per 5m per parent comment
if params[:preview].blank? &&
(pc = Comment.where(:story_id => story.id,
:user_id => @user.id,
@ -50,13 +59,7 @@ class CommentsController < ApplicationController
if comment.valid? && params[:preview].blank? && ActiveRecord::Base.transaction { comment.save }
comment.current_vote = { :vote => 1 }
if request.xhr?
render :partial => "comments/postedreply", :layout => false,
:content_type => "text/html", :locals => { :comment => comment }
else
redirect_to comment.path
end
self.render_created_comment(comment)
else
comment.score = 1
comment.current_vote = { :vote => 1 }
@ -65,6 +68,15 @@ class CommentsController < ApplicationController
end
end
def render_created_comment(comment)
if request.xhr?
render :partial => "comments/postedreply", :layout => false,
:content_type => "text/html", :locals => { :comment => comment }
else
redirect_to comment.path
end
end
def show
if !((comment = find_comment) && comment.is_editable_by_user?(@user))
return render :plain => "can't find comment", :status => 400

View File

@ -880,7 +880,9 @@ class Story < ApplicationRecord
if (match = u.match(/\A([^\?]+)\?(.+)\z/))
params = match[2].split(/[&\?]/)
# utm_ is google and many others; sk is medium
params.reject! {|p| p.match(/^utm_(source|medium|campaign|term|content|referrer)=|^sk=|^gclid=|^fbclid=/) }
params.reject! {|p|
p.match(/^utm_(source|medium|campaign|term|content|referrer)=|^sk=|^gclid=|^fbclid=/x)
}
u = match[1] << (params.any?? "?" << params.join("&") : "")
end