fix #2314 and appeals

This commit is contained in:
Toks
2014-11-30 16:10:17 -05:00
parent 90bca638bf
commit 38f51306a8
4 changed files with 36 additions and 0 deletions

View File

@@ -11,6 +11,11 @@ class PostAppeal < ActiveRecord::Base
attr_accessible :post_id, :post, :reason
module SearchMethods
def reason_matches(query)
query = "*#{query}*" unless query =~ /\*/
where("reason ILIKE ? ESCAPE E'\\\\'", query.to_escaped_for_sql_like)
end
def resolved
joins(:post).where("posts.is_deleted = false and posts.is_flagged = false")
end
@@ -35,6 +40,10 @@ class PostAppeal < ActiveRecord::Base
q = where("true")
return q if params.blank?
if params[:reason_matches].present?
q = q.reason_matches(params[:reason_matches])
end
if params[:creator_id].present?
q = q.for_user(params[:creator_id].to_i)
end

View File

@@ -13,6 +13,11 @@ class PostFlag < ActiveRecord::Base
attr_accessor :is_deletion
module SearchMethods
def reason_matches(query)
query = "*#{query}*" unless query =~ /\*/
where("reason ILIKE ? ESCAPE E'\\\\'", query.to_escaped_for_sql_like)
end
def resolved
where("is_resolved = ?", true)
end
@@ -37,6 +42,10 @@ class PostFlag < ActiveRecord::Base
q = where("true")
return q if params.blank?
if params[:reason_matches].present?
q = q.reason_matches(params[:reason_matches])
end
if params[:creator_id].present? && (CurrentUser.user.is_janitor? || params[:creator_id].to_i == CurrentUser.user.id)
q = q.where("creator_id = ?", params[:creator_id].to_i)
end