Commit 965efede by Toby Lawrence Committed by Robert Raposa

Add the ability to request a thread without its responses.

For cases where we don't need or want the responses on a thread at all,
like getting some metadata about a thread, we should be able to request
it without the responses.  This exists in the ThreadPresenter but didn't
exist as an option that could be passed in the API call itself.

We've added this as an option now -- with_responses -- that defaults to
true, which preserves the existing behavior but does in fact allow
toggling.

This gives us a backwards-compatible upgrade path to allow changes to be
made the LMS so that requests which don't need the responses, or do need
the responses, can be explicit about what they want.
parent f051f495
......@@ -49,7 +49,7 @@ get "#{APIPREFIX}/threads/:thread_id" do |thread_id|
else
resp_limit = nil
end
presenter.to_hash(true, resp_skip, resp_limit, bool_recursive).to_json
presenter.to_hash(bool_with_responses, resp_skip, resp_limit, bool_recursive).to_json
end
put "#{APIPREFIX}/threads/:thread_id" do |thread_id|
......
require 'new_relic/agent/method_tracer'
helpers do
def commentable
@commentable ||= Commentable.find(params[:commentable_id])
end
......@@ -79,7 +78,6 @@ helpers do
obj.reload.to_hash.to_json
end
def pin(obj)
raise ArgumentError, t(:user_id_is_required) unless user
obj.pinned = true
......@@ -94,8 +92,6 @@ helpers do
obj.reload.to_hash.to_json
end
def value_to_boolean(value)
!!(value.to_s =~ /^true$/i)
end
......@@ -104,6 +100,10 @@ helpers do
value_to_boolean params["recursive"]
end
def bool_with_responses
value_to_boolean params["with_responses"] || "true"
end
def bool_mark_as_read
value_to_boolean params["mark_as_read"]
end
......@@ -142,7 +142,6 @@ helpers do
per_page,
context=:course
)
context_threads = comment_threads.where({:context => context})
if not group_ids.empty?
......@@ -365,7 +364,6 @@ helpers do
end
notification_map.to_json
end
def filter_blocked_content body
......@@ -390,5 +388,4 @@ helpers do
add_method_tracer :flag_as_abuse
add_method_tracer :un_flag_as_abuse
add_method_tracer :handle_threads_query
end
......@@ -23,7 +23,7 @@ class ThreadPresenter
@is_endorsed = is_endorsed
end
def to_hash with_responses=false, resp_skip=0, resp_limit=nil, recursive=true
def to_hash(with_responses=false, resp_skip=0, resp_limit=nil, recursive=true)
raise ArgumentError unless resp_skip >= 0
raise ArgumentError unless resp_limit.nil? or resp_limit >= 1
h = @thread.to_hash
......
......@@ -513,6 +513,18 @@ describe "app" do
check_thread_result_json(nil, thread, parsed)
end
context 'when requesting the thread for informational purposes' do
subject do
get "/api/v1/threads/#{thread.id}", with_responses: false # we're asking for no responses here.
end
it 'should have no children' do
expect(subject).to be_ok
parsed = parse(subject.body)
expect(parsed).not_to include('children')
end
end
context 'when marking as read' do
subject do
get "/api/v1/threads/#{thread.id}", {:user_id => thread.author.id, :mark_as_read => true}
......
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