allow more forum posts to be voted on (fixes #3677)
This commit is contained in:
@@ -6,6 +6,8 @@ class ForumPost < ApplicationRecord
|
|||||||
belongs_to_updater
|
belongs_to_updater
|
||||||
belongs_to :topic, :class_name => "ForumTopic"
|
belongs_to :topic, :class_name => "ForumTopic"
|
||||||
has_many :votes, class_name: "ForumPostVote"
|
has_many :votes, class_name: "ForumPostVote"
|
||||||
|
has_one :tag_relationship
|
||||||
|
has_one :bulk_update_request
|
||||||
before_validation :initialize_is_deleted, :on => :create
|
before_validation :initialize_is_deleted, :on => :create
|
||||||
after_create :update_topic_updated_at_on_create
|
after_create :update_topic_updated_at_on_create
|
||||||
after_update :update_topic_updated_at_on_update_for_original_posts
|
after_update :update_topic_updated_at_on_update_for_original_posts
|
||||||
@@ -129,6 +131,11 @@ class ForumPost < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def votable?
|
||||||
|
# shortcut to eliminate posts that are probably not tag change requests
|
||||||
|
body.match(/->/) && (bulk_update_request.present? || tag_relationship.present?) && created_at >= TagRelationship::EXPIRY.days.ago
|
||||||
|
end
|
||||||
|
|
||||||
def voted?(user, score)
|
def voted?(user, score)
|
||||||
votes.where(creator_id: user.id, score: score).exists?
|
votes.where(creator_id: user.id, score: score).exists?
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
<% else %>
|
<% else %>
|
||||||
<li><%= link_to "Permalink", forum_post_path(forum_post) %></li>
|
<li><%= link_to "Permalink", forum_post_path(forum_post) %></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if forum_post.is_original_post?(original_forum_post_id) %>
|
<% if forum_post.votable? %>
|
||||||
<ul class="votes" id="forum-post-votes-for-<%= forum_post.id %>">
|
<ul class="votes" id="forum-post-votes-for-<%= forum_post.id %>">
|
||||||
<%= render "forum_post_votes/list", votes: forum_post.votes, forum_post: forum_post %>
|
<%= render "forum_post_votes/list", votes: forum_post.votes, forum_post: forum_post %>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -14,6 +14,17 @@ class ForumPostTest < ActiveSupport::TestCase
|
|||||||
CurrentUser.ip_addr = nil
|
CurrentUser.ip_addr = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "#votable?" do
|
||||||
|
setup do
|
||||||
|
@post = FactoryBot.build(:forum_post, :topic_id => @topic.id, :body => "[[aaa]] -> [[bbb]]")
|
||||||
|
@tag_alias = FactoryBot.create(:tag_alias, forum_post: @post)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be true for a post associated with a tag alias" do
|
||||||
|
assert(@post.votable?)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "that mentions a user" do
|
context "that mentions a user" do
|
||||||
context "in a quote block" do
|
context "in a quote block" do
|
||||||
setup do
|
setup do
|
||||||
|
|||||||
Reference in New Issue
Block a user