diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a2f526f8f46..ec7604554e9 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -253,6 +253,7 @@ class UsersController < ApplicationController # 'context_type': 'course', // course|group # 'course_id': 1, # 'group_id': null, + # 'html_url': "http://..." // URL to the Canvas web UI for this stream item # } # # In addition, each item type has its own set of attributes available. diff --git a/lib/api/v1/stream_item.rb b/lib/api/v1/stream_item.rb index e3b74d0eac3..73bc26b7300 100644 --- a/lib/api/v1/stream_item.rb +++ b/lib/api/v1/stream_item.rb @@ -31,14 +31,17 @@ module Api::V1::StreamItem hash['message'] = data.body hash['type'] = data.type hash.merge!(context_data(data)) + context_type, context_id = stream_item.context_code.try(:split, '_', 2) case data.type when 'DiscussionTopic', 'Announcement' hash['message'] = data.message if data.type == 'DiscussionTopic' hash['discussion_topic_id'] = data.id + hash['html_url'] = send("#{context_type}_discussion_topic_url", context_id.to_i, data.id.to_i) else hash['announcement_id'] = data.id + hash['html_url'] = send("#{context_type}_announcement_url", context_id.to_i, data.id.to_i) end hash['total_root_discussion_entries'] = data.total_root_discussion_entries hash['require_initial_post'] = data.require_initial_post @@ -59,17 +62,19 @@ module Api::V1::StreamItem hash['conversation_id'] = data.id hash['private'] = data.private hash['participant_count'] = data.participant_count + hash['html_url'] = conversation_url(data.id.to_i) when 'Message' hash['message_id'] = data.id # this type encompasses a huge number of different types of messages, # anything that gets send to communication channels hash['title'] = data.subject hash['notification_category'] = data.notification_category - hash['url'] = data.url + hash['html_url'] = hash['url'] = data.url when 'Submission' hash['title'] = data.assignment.try(:title) hash['grade'] = data.grade hash['score'] = data.score + hash['html_url'] = course_assignment_submission_url(context_id, data.assignment.id, data.user_id) hash['submission_comments'] = data.submission_comments.map do |comment| { 'body' => comment.formatted_body, @@ -86,10 +91,12 @@ module Api::V1::StreamItem hash['web_conference_id'] = data.id hash['type'] = 'WebConference' hash['message'] = data.description + hash['html_url'] = send("#{context_type}_conference_url", context_id.to_i, data.id.to_i) if context_type when /Collaboration/ hash['collaboration_id'] = data.id # TODO: this type isn't even shown on the web activity stream yet hash['type'] = 'Collaboration' + hash['html_url'] = send("#{context_type}_collaboration_url", context_id.to_i, data.id.to_i) if context_type else raise("Unexpected stream item type: #{data.type}") end diff --git a/spec/apis/v1/stream_items_api_spec.rb b/spec/apis/v1/stream_items_api_spec.rb index 26451e4e140..d7ba97d8f9b 100644 --- a/spec/apis/v1/stream_items_api_spec.rb +++ b/spec/apis/v1/stream_items_api_spec.rb @@ -64,6 +64,7 @@ describe UsersController, :type => :integration do 'updated_at' => StreamItem.last.updated_at.as_json, 'require_initial_post' => true, 'user_has_posted' => true, + 'html_url' => "http://www.example.com/courses/#{@context.id}/discussion_topics/#{@topic.id}", 'total_root_discussion_entries' => 1, 'root_discussion_entries' => [ @@ -127,6 +128,7 @@ describe UsersController, :type => :integration do 'updated_at' => StreamItem.last.updated_at.as_json, 'require_initial_post' => nil, 'user_has_posted' => nil, + 'html_url' => "http://www.example.com/courses/#{@context.id}/announcements/#{@a.id}", 'total_root_discussion_entries' => 1, 'root_discussion_entries' => [ @@ -156,6 +158,7 @@ describe UsersController, :type => :integration do 'message' => nil, 'private' => false, + 'html_url' => "http://www.example.com/conversations/#{@conversation.id}", 'participant_count' => 2 } @@ -176,6 +179,7 @@ describe UsersController, :type => :integration do 'notification_category' => 'TestImmediately', 'url' => nil, + 'html_url' => nil, }] end @@ -199,6 +203,7 @@ describe UsersController, :type => :integration do 'updated_at' => StreamItem.last.updated_at.as_json, 'grade' => '12', 'score' => 12, + 'html_url' => "http://www.example.com/courses/#{@course.id}/assignments/#{@assignment.id}/submissions/#{@user.id}", 'assignment' => { 'title' => 'assignment 1', @@ -242,6 +247,7 @@ describe UsersController, :type => :integration do 'updated_at' => StreamItem.last.updated_at.as_json, 'grade' => nil, 'score' => nil, + 'html_url' => "http://www.example.com/courses/#{@course.id}/assignments/#{@assignment.id}/submissions/#{@user.id}", 'assignment' => { 'title' => 'assignment 1', @@ -283,6 +289,7 @@ describe UsersController, :type => :integration do 'updated_at' => StreamItem.last.updated_at.as_json, 'grade' => '12', 'score' => 12, + 'html_url' => "http://www.example.com/courses/#{@course.id}/assignments/#{@assignment.id}/submissions/#{@user.id}", 'assignment' => { 'title' => 'assignment 1', @@ -317,6 +324,9 @@ describe UsersController, :type => :integration do 'title' => "hey", 'message' => nil, 'type' => 'Collaboration', + 'context_type' => 'Course', + 'course_id' => @course.id, + 'html_url' => "http://www.example.com/courses/#{@course.id}/collaborations/#{@collaboration.id}", 'created_at' => StreamItem.last.created_at.as_json, 'updated_at' => StreamItem.last.updated_at.as_json, }] @@ -326,7 +336,7 @@ describe UsersController, :type => :integration do WebConference.stubs(:plugins).returns( [OpenObject.new(:id => "big_blue_button", :settings => {:domain => "bbb.instructure.com", :secret_dec => "secret"}, :valid_settings? => true, :enabled? => true),] ) - @conference = BigBlueButtonConference.create!(:title => 'myconf', :user => @user, :description => 'mydesc', :conference_type => 'big_blue_button') + @conference = BigBlueButtonConference.create!(:title => 'myconf', :user => @user, :description => 'mydesc', :conference_type => 'big_blue_button', :context => @course) json = api_call(:get, "/api/v1/users/activity_stream.json", { :controller => "users", :action => "activity_stream", :format => 'json' }) json.should == [{ @@ -335,6 +345,9 @@ describe UsersController, :type => :integration do 'title' => "myconf", 'type' => 'WebConference', 'message' => 'mydesc', + 'context_type' => 'Course', + 'course_id' => @course.id, + 'html_url' => "http://www.example.com/courses/#{@course.id}/conferences/#{@conference.id}", 'created_at' => StreamItem.last.created_at.as_json, 'updated_at' => StreamItem.last.updated_at.as_json, }] diff --git a/spec/factories/collaboration_factory.rb b/spec/factories/collaboration_factory.rb index 43c7bd0dede..fd923cd0802 100644 --- a/spec/factories/collaboration_factory.rb +++ b/spec/factories/collaboration_factory.rb @@ -29,6 +29,7 @@ def valid_collaboration_attributes :collaboration_type => "value for collaboration_type", :document_id => "document:dc3pjs4r_3hhc6fvcc", :user_id => User.create!.id, + :context => @course || course_model, :url => "value for url", :data => %{