Commit 994a6328 by Ben McMorran Committed by Saqib

TNL-1943 Add context field to CommentThread

parent 509c96eb
...@@ -25,3 +25,4 @@ Bill DeRusha <bill@edx.org> ...@@ -25,3 +25,4 @@ Bill DeRusha <bill@edx.org>
Brian Beggs <macdiesel@gmail.com> Brian Beggs <macdiesel@gmail.com>
Clinton Blackburn <cblackburn@edx.org> Clinton Blackburn <cblackburn@edx.org>
Eugeny Kolpakov <eugeny.kolpakov@gmail.com> Eugeny Kolpakov <eugeny.kolpakov@gmail.com>
Ben McMorran <ben.mcmorran@gmail.com>
...@@ -10,7 +10,7 @@ helpers do ...@@ -10,7 +10,7 @@ helpers do
raise ArgumentError, t(:user_id_is_required) unless @user || params[:user_id] raise ArgumentError, t(:user_id_is_required) unless @user || params[:user_id]
@user ||= User.find_by(external_id: params[:user_id]) @user ||= User.find_by(external_id: params[:user_id])
end end
def thread def thread
@thread ||= CommentThread.find(params[:thread_id]) @thread ||= CommentThread.find(params[:thread_id])
end end
...@@ -56,7 +56,7 @@ helpers do ...@@ -56,7 +56,7 @@ helpers do
obj.save obj.save
obj.reload.to_hash.to_json obj.reload.to_hash.to_json
end end
def un_flag_as_abuse(obj) def un_flag_as_abuse(obj)
raise ArgumentError, t(:user_id_is_required) unless user raise ArgumentError, t(:user_id_is_required) unless user
if params["all"] if params["all"]
...@@ -66,7 +66,7 @@ helpers do ...@@ -66,7 +66,7 @@ helpers do
else else
obj.abuse_flaggers.delete user.id obj.abuse_flaggers.delete user.id
end end
obj.save obj.save
obj.reload.to_hash.to_json obj.reload.to_hash.to_json
end end
...@@ -78,7 +78,7 @@ helpers do ...@@ -78,7 +78,7 @@ helpers do
end end
obj.reload.to_hash.to_json obj.reload.to_hash.to_json
end end
def pin(obj) def pin(obj)
raise ArgumentError, t(:user_id_is_required) unless user raise ArgumentError, t(:user_id_is_required) unless user
...@@ -86,16 +86,16 @@ helpers do ...@@ -86,16 +86,16 @@ helpers do
obj.save obj.save
obj.reload.to_hash.to_json obj.reload.to_hash.to_json
end end
def unpin(obj) def unpin(obj)
raise ArgumentError, t(:user_id_is_required) unless user raise ArgumentError, t(:user_id_is_required) unless user
obj.pinned = nil obj.pinned = nil
obj.save obj.save
obj.reload.to_hash.to_json obj.reload.to_hash.to_json
end end
def value_to_boolean(value) def value_to_boolean(value)
!!(value.to_s =~ /^true$/i) !!(value.to_s =~ /^true$/i)
end end
...@@ -158,7 +158,7 @@ helpers do ...@@ -158,7 +158,7 @@ helpers do
comment_ids = Comment.where(:course_id => course_id). comment_ids = Comment.where(:course_id => course_id).
where(:abuse_flaggers.ne => [], :abuse_flaggers.exists => true). where(:abuse_flaggers.ne => [], :abuse_flaggers.exists => true).
collect{|c| c.comment_thread_id}.uniq collect{|c| c.comment_thread_id}.uniq
thread_ids = comment_threads.where(:abuse_flaggers.ne => [], :abuse_flaggers.exists => true). thread_ids = comment_threads.where(:abuse_flaggers.ne => [], :abuse_flaggers.exists => true).
collect{|c| c.id} collect{|c| c.id}
...@@ -171,7 +171,7 @@ helpers do ...@@ -171,7 +171,7 @@ helpers do
endorsed_thread_ids = Comment.where(:course_id => course_id). endorsed_thread_ids = Comment.where(:course_id => course_id).
where(:parent_id.exists => false, :endorsed => true). where(:parent_id.exists => false, :endorsed => true).
collect{|c| c.comment_thread_id}.uniq collect{|c| c.comment_thread_id}.uniq
comment_threads = comment_threads.where({"thread_type" => :question}).nin({"_id" => endorsed_thread_ids}) comment_threads = comment_threads.where({"thread_type" => :question}).nin({"_id" => endorsed_thread_ids})
end end
end end
...@@ -217,7 +217,7 @@ helpers do ...@@ -217,7 +217,7 @@ helpers do
# The following trick makes frontend pagers work without recalculating # The following trick makes frontend pagers work without recalculating
# the number of all unread threads per user on every request (since the number # the number of all unread threads per user on every request (since the number
# of threads in a course could be tens or hundreds of thousands). It has the # of threads in a course could be tens or hundreds of thousands). It has the
# effect of showing that there's always just one more page of results, until # effect of showing that there's always just one more page of results, until
# there definitely are no more pages. This is really only acceptable for pagers # there definitely are no more pages. This is really only acceptable for pagers
# that don't actually reveal the total number of pages to the user onscreen. # that don't actually reveal the total number of pages to the user onscreen.
...@@ -228,7 +228,7 @@ helpers do ...@@ -228,7 +228,7 @@ helpers do
page = [1, page].max page = [1, page].max
threads = comment_threads.paginate(:page => page, :per_page => per_page).to_a threads = comment_threads.paginate(:page => page, :per_page => per_page).to_a
end end
if threads.length == 0 if threads.length == 0
collection = [] collection = []
else else
...@@ -328,11 +328,11 @@ helpers do ...@@ -328,11 +328,11 @@ helpers do
current_thread = thread_map[c.comment_thread_id] current_thread = thread_map[c.comment_thread_id]
#do not include threads or comments who have current or historical abuse flags #do not include threads or comments who have current or historical abuse flags
if current_thread.abuse_flaggers.to_a.empty? and if current_thread.abuse_flaggers.to_a.empty? and
current_thread.historical_abuse_flaggers.to_a.empty? and current_thread.historical_abuse_flaggers.to_a.empty? and
c.abuse_flaggers.to_a.empty? and c.abuse_flaggers.to_a.empty? and
c.historical_abuse_flaggers.to_a.empty? c.historical_abuse_flaggers.to_a.empty?
user_ids = subscriptions_map[c.comment_thread_id.to_s] user_ids = subscriptions_map[c.comment_thread_id.to_s]
user_ids.each do |u| user_ids.each do |u|
if not notification_map.keys.include? u if not notification_map.keys.include? u
...@@ -377,12 +377,12 @@ helpers do ...@@ -377,12 +377,12 @@ helpers do
return return
end end
if CommentService.blocked_hashes.include? hash then if CommentService.blocked_hashes.include? hash then
msg = t(:blocked_content_with_body_hash, :hash => hash) msg = t(:blocked_content_with_body_hash, :hash => hash)
logger.warn msg logger.warn msg
error 503, [msg].to_json error 503, [msg].to_json
end end
end end
include ::NewRelic::Agent::MethodTracer include ::NewRelic::Agent::MethodTracer
add_method_tracer :user add_method_tracer :user
add_method_tracer :thread add_method_tracer :thread
......
...@@ -141,7 +141,14 @@ class Comment < Content ...@@ -141,7 +141,14 @@ class Comment < Content
end end
def context def context
self.comment_thread_id ? self.comment_thread.context : nil if self.comment_thread_id
t = CommentThread.find self.comment_thread_id
if t
t.context
end
end
rescue Mongoid::Errors::DocumentNotFound
nil
end end
def course_context? def course_context?
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment