Commit 81dca823 by Ibrahim Awwal

Make handle_threads_query scope all queries by course_id so that everything that uses it is scoped.

parent 236ff613
......@@ -30,7 +30,7 @@ post "#{APIPREFIX}/threads/:thread_id/comments" do |thread_id|
comment = Comment.new(params.slice(*%w[body course_id]))
comment.anonymous = bool_anonymous || false
comment.anonymous_to_peers = bool_anonymous_to_peers || false
comment.author = user
comment.author = user
comment.comment_thread = thread
comment.save
if comment.errors.any?
......
......@@ -3,7 +3,7 @@ get "#{APIPREFIX}/users/:user_id/notifications" do |user_id|
end
get "#{APIPREFIX}/users/:user_id/subscribed_threads" do |user_id|
handle_threads_query(user.subscribed_threads.where(:course_id=>params[:course_id]))
handle_threads_query(user.subscribed_threads)
end
post "#{APIPREFIX}/users/:user_id/subscriptions" do |user_id|
......
......@@ -76,7 +76,7 @@ helpers do
end
def handle_threads_query(comment_threads)
comment_threads = comment_threads.where(:course_id=>params[:course_id])
if CommentService.config[:cache_enabled]
query_params = params.slice(*%w[course_id commentable_id sort_key sort_order page per_page user_id])
memcached_key = "threads_query_#{query_params.hash}"
......@@ -105,6 +105,7 @@ helpers do
sort_key = sort_key_mapper[params["sort_key"]]
sort_order = sort_order_mapper[params["sort_order"]]
sort_keyword_valid = (!params["sort_key"] && !params["sort_order"] || sort_key && sort_order)
if not sort_keyword_valid
{}.to_json
else
......
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