Merge pull request #3145 from r888888888/flagger_metatag

Add "flagger:" and "appealer:" metatags (fixes #3142)
This commit is contained in:
Albert Yi
2017-06-14 11:02:08 -07:00
committed by GitHub
9 changed files with 114 additions and 16 deletions

View File

@@ -7,8 +7,11 @@ module PostFlagsHelper
html << '<li>'
html << DText.parse_inline(flag.reason).html_safe
if CurrentUser.is_moderator?
html << " - #{link_to_user(flag.creator)} (#{link_to_ip(flag.creator_ip_addr)})"
if CurrentUser.can_view_flagger?(flag.creator_id)
html << " - #{link_to_user(flag.creator)}"
if CurrentUser.is_moderator?
html << " (#{link_to_ip(flag.creator_ip_addr)})"
end
end
html << ' - ' + time_ago_in_words_tagged(flag.created_at)

View File

@@ -116,6 +116,10 @@ class AnonymousUser
false
end
def can_view_flagger?(flagger_id)
false
end
def can_approve_posts?
false
end

View File

@@ -236,6 +236,46 @@ class PostQueryBuilder
has_constraints!
end
if q[:flagger_ids_neg]
q[:flagger_ids_neg].each do |flagger_id|
if CurrentUser.can_view_flagger?(flagger_id)
relation = relation.where("posts.id NOT IN (?)", PostFlag.unscoped.search({:creator_id => flagger_id, :category => "normal"}).reorder("").select(:post_id).distinct)
end
end
end
if q[:flagger_ids]
q[:flagger_ids].each do |flagger_id|
if flagger_id == "any"
relation = relation.where('EXISTS (' + PostFlag.unscoped.search({:category => "normal"}).where('post_id = posts.id').reorder('').select('1').to_sql + ')')
elsif flagger_id == "none"
relation = relation.where('NOT EXISTS (' + PostFlag.unscoped.search({:category => "normal"}).where('post_id = posts.id').reorder('').select('1').to_sql + ')')
elsif CurrentUser.can_view_flagger?(flagger_id)
relation = relation.where("posts.id IN (?)", PostFlag.unscoped.search({:creator_id => flagger_id, :category => "normal"}).reorder("").select(:post_id).distinct)
end
end
has_constraints!
end
if q[:appealer_ids_neg]
q[:appealer_ids_neg].each do |appealer_id|
relation = relation.where("posts.id NOT IN (?)", PostAppeal.unscoped.where(creator_id: appealer_id).select(:post_id).distinct)
end
end
if q[:appealer_ids]
q[:appealer_ids].each do |appealer_id|
if appealer_id == "any"
relation = relation.where('EXISTS (' + PostAppeal.unscoped.where('post_id = posts.id').select('1').to_sql + ')')
elsif appealer_id == "none"
relation = relation.where('NOT EXISTS (' + PostAppeal.unscoped.where('post_id = posts.id').select('1').to_sql + ')')
else
relation = relation.where("posts.id IN (?)", PostAppeal.unscoped.where(creator_id: appealer_id).select(:post_id).distinct)
end
end
has_constraints!
end
if q[:commenter_ids]
q[:commenter_ids].each do |commenter_id|
if commenter_id == "any"

View File

@@ -24,6 +24,16 @@ class PostEvent
type_name.first
end
def is_creator_visible?(user = CurrentUser.user)
case event
when PostAppeal
true
when PostFlag
flag = event
user.can_view_flagger?(flag.creator_id)
end
end
def attributes
{
"creator_id": nil,

View File

@@ -73,12 +73,15 @@ class PostFlag < ActiveRecord::Base
q = q.reason_matches(params[:reason_matches])
end
if params[:creator_id].present? && (CurrentUser.is_moderator? || params[:creator_id].to_i == CurrentUser.user.id)
if params[:creator_id].present? && CurrentUser.can_view_flagger?(params[:creator_id].to_i)
q = q.where("creator_id = ?", params[:creator_id].to_i)
end
if params[:creator_name].present? && (CurrentUser.is_moderator? || params[:creator_name].mb_chars.downcase.strip.tr(" ", "_") == CurrentUser.user.name.downcase)
q = q.where("creator_id = (select _.id from users _ where lower(_.name) = ?)", params[:creator_name].mb_chars.downcase.strip.tr(" ", "_"))
if params[:creator_name].present?
flagger_id = User.name_to_id(params[:creator_name].strip)
if CurrentUser.can_view_flagger?(flagger_id)
q = q.where("creator_id = ?", flagger_id)
end
end
if params[:post_id].present?

View File

@@ -1,7 +1,7 @@
class Tag < ActiveRecord::Base
COSINE_SIMILARITY_RELATED_TAG_THRESHOLD = 1000
METATAGS = "-user|user|-approver|approver|commenter|comm|noter|noteupdater|artcomm|-pool|pool|ordpool|-favgroup|favgroup|-fav|fav|ordfav|sub|md5|-rating|rating|-locked|locked|width|height|mpixels|ratio|score|favcount|filesize|source|-source|id|-id|date|age|order|limit|-status|status|tagcount|gentags|arttags|chartags|copytags|parent|-parent|child|pixiv_id|pixiv|search|upvote|downvote|filetype|-filetype"
SUBQUERY_METATAGS = "commenter|comm|noter|noteupdater|artcomm"
METATAGS = "-user|user|-approver|approver|commenter|comm|noter|noteupdater|artcomm|-pool|pool|ordpool|-favgroup|favgroup|-fav|fav|ordfav|sub|md5|-rating|rating|-locked|locked|width|height|mpixels|ratio|score|favcount|filesize|source|-source|id|-id|date|age|order|limit|-status|status|tagcount|gentags|arttags|chartags|copytags|parent|-parent|child|pixiv_id|pixiv|search|upvote|downvote|filetype|-filetype|flagger|-flagger|appealer|-appealer"
SUBQUERY_METATAGS = "commenter|comm|noter|noteupdater|artcomm|flagger|-flagger|appealer|-appealer"
attr_accessible :category, :as => [:moderator, :gold, :platinum, :member, :anonymous, :default, :builder, :admin]
attr_accessible :is_locked, :as => [:moderator, :admin]
has_one :wiki_page, :foreign_key => "title", :primary_key => "name"
@@ -442,7 +442,7 @@ class Tag < ActiveRecord::Base
when "approver"
if $2 == "none"
q[:approver_id] = "none"
q[:approver_id] = "none"
elsif $2 == "any"
q[:approver_id] = "any"
else
@@ -450,6 +450,40 @@ class Tag < ActiveRecord::Base
q[:approver_id] = user_id unless user_id.blank?
end
when "flagger"
q[:flagger_ids] ||= []
if $2 == "none"
q[:flagger_ids] << "none"
elsif $2 == "any"
q[:flagger_ids] << "any"
else
user_id = User.name_to_id($2)
q[:flagger_ids] << user_id unless user_id.blank?
end
when "-flagger"
q[:flagger_ids_neg] ||= []
user_id = User.name_to_id($2)
q[:flagger_ids_neg] << user_id unless user_id.blank?
when "appealer"
q[:appealer_ids] ||= []
if $2 == "none"
q[:appealer_ids] << "none"
elsif $2 == "any"
q[:appealer_ids] << "any"
else
user_id = User.name_to_id($2)
q[:appealer_ids] << user_id unless user_id.blank?
end
when "-appealer"
q[:appealer_ids_neg] ||= []
user_id = User.name_to_id($2)
q[:appealer_ids_neg] << user_id unless user_id.blank?
when "commenter", "comm"
q[:commenter_ids] ||= []

View File

@@ -545,6 +545,10 @@ class User < ActiveRecord::Base
created_at <= 1.week.ago
end
def can_view_flagger?(flagger_id)
is_moderator? || flagger_id == id
end
def base_upload_limit
if created_at >= 1.month.ago
10

View File

@@ -6,9 +6,7 @@
<thead>
<tr>
<th width="5%">Type</th>
<% if CurrentUser.is_moderator? %>
<th width="10%">Creator</th>
<% end %>
<th width="10%">Creator</th>
<th>Reason</th>
<th width="5%">Resolved?</th>
<th width="15%">Date</th>
@@ -18,11 +16,13 @@
<% @events.each do |event| %>
<tr class="resolved-<%= event.is_resolved %>">
<td><%= event.type_name %></td>
<% if CurrentUser.is_moderator? %>
<td>
<td>
<% if event.is_creator_visible? %>
<%= link_to_user event.creator %>
</td>
<% end %>
<% else %>
<i>hidden</i>
<% end %>
</td>
<td><%= format_text event.reason, :ragel => true %></td>
<td>
<% if event.is_resolved %>

View File

@@ -39,7 +39,7 @@
</td>
<td>
<%= compact_time post_flag.created_at %>
<% if CurrentUser.user.is_moderator? %>
<% if CurrentUser.can_view_flagger?(post_flag.creator_id) %>
<br> by <%= link_to_user post_flag.creator %>
<%= link_to "»", post_flags_path(search: params[:search].merge(creator_name: post_flag.creator.name)) %>
<% end %>