Commit 2fb3086e by wajeeha-khalid

Merge pull request #151 from edx/jia/MA-1742

MA-1742; return read status on GET thread for user_id provided
parents ce416ccc 6372e2fb
...@@ -27,9 +27,12 @@ get "#{APIPREFIX}/threads/:thread_id" do |thread_id| ...@@ -27,9 +27,12 @@ get "#{APIPREFIX}/threads/:thread_id" do |thread_id|
error 404, [t(:requested_object_not_found)].to_json error 404, [t(:requested_object_not_found)].to_json
end end
if params["user_id"] and bool_mark_as_read # user is required to return user-specific fields, such as "read" (even if bool_mark_as_read is False)
if params["user_id"]
user = User.only([:id, :username, :read_states]).find_by(external_id: params["user_id"]) user = User.only([:id, :username, :read_states]).find_by(external_id: params["user_id"])
user.mark_as_read(thread) if user end
if user and bool_mark_as_read
user.mark_as_read(thread)
end end
presenter = ThreadPresenter.factory(thread, user || nil) presenter = ThreadPresenter.factory(thread, user || nil)
......
...@@ -498,6 +498,18 @@ describe "app" do ...@@ -498,6 +498,18 @@ describe "app" do
parse(last_response.body).first.should == I18n.t(:requested_object_not_found) parse(last_response.body).first.should == I18n.t(:requested_object_not_found)
end end
it "marks thread as read and confirms its value on returned response" do
user = create_test_user(123)
thread = CommentThread.first
user.mark_as_read(thread)
get "/api/v1/threads/#{thread.id}", user_id: user.id
last_response.should be_ok
json_response = parse(last_response.body)
changed_thread = CommentThread.find(thread.id)
check_thread_result_json(user, changed_thread, json_response)
json_response["read"].should == true
end
def test_unicode_data(text) def test_unicode_data(text)
thread = make_thread(User.first, text, "unicode_course", "unicode_commentable") thread = make_thread(User.first, text, "unicode_course", "unicode_commentable")
make_comment(User.first, thread, text) make_comment(User.first, thread, text)
......
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