don't infer the current user for nil DiscussionTopic#user in the stream
fixes #8403 test plan: * import an external content package with discussion topics * make sure to find a discussion topic that has no author * on the dashboard of a user that has a stream item about that topic it should not show that the current user is the author Change-Id: I681be31462a82591d60665dce967aa1548ef3a07 Reviewed-on: https://gerrit.instructure.com/10579 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
This commit is contained in:
parent
8beb4e0fd4
commit
b92c17f11d
|
@ -26,7 +26,7 @@ class DiscussionTopic < ActiveRecord::Base
|
|||
|
||||
attr_accessible :title, :message, :user, :delayed_post_at, :assignment,
|
||||
:plaintext_message, :podcast_enabled, :podcast_has_student_posts,
|
||||
:require_initial_post, :threaded, :discussion_type
|
||||
:require_initial_post, :threaded, :discussion_type, :context
|
||||
|
||||
module DiscussionTypes
|
||||
SIDE_COMMENT = 'side_comment'
|
||||
|
|
|
@ -30,7 +30,7 @@ class StreamItem < ActiveRecord::Base
|
|||
def stream_data(viewing_user_id)
|
||||
res = data.is_a?(OpenObject) ? data : OpenObject.new
|
||||
res.assert_hash_data
|
||||
res.user_id ||= viewing_user_id
|
||||
res.user_id ||= viewing_user_id unless res.type == 'DiscussionTopic'
|
||||
post_process(res, viewing_user_id)
|
||||
end
|
||||
|
||||
|
|
|
@ -12,7 +12,9 @@
|
|||
<a href="<%= context_prefix(context_code) %>/discussion_topics/<%= topic ? topic.id : "{{ id }}" %>" class="title"><%= topic.try_rescue(:title) || t('no_title', "No Title") %></a>
|
||||
<div class="sub_title">
|
||||
<span class="context_code group_<%= context_code || 'blank' %>"><%= cached_context_short_name(context_code) %></span>
|
||||
<a title="<%= t 'titles.author_name', "Author's name" %>" href="<%= context_prefix(context_code) %>/users/<%= topic ? topic.user_id : "{{ user_id }}" %>" class="user_name"><%= context_user_name(context_code, topic.try_rescue(:user_id)) %></a>
|
||||
<% if topic && topic.user_id || !topic || topic.new_record? %>
|
||||
<a title="<%= t 'titles.author_name', "Author's name" %>" href="<%= context_prefix(context_code) %>/users/<%= topic ? topic.user_id : "{{ user_id }}" %>" class="user_name"><%= context_user_name(context_code, topic.try_rescue(:user_id)) %></a>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="post_date time_ago_date"><%= datetime_string(post_date) || nbsp %></div>
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
#
|
||||
# Copyright (C) 2011 Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
# Canvas is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
|
||||
|
||||
describe StreamItem do
|
||||
it "should not infer a user_id for DiscussionTopic" do
|
||||
user
|
||||
context = Course.create!
|
||||
dt = DiscussionTopic.create!(:context => context)
|
||||
dt.generate_stream_items([@user])
|
||||
si = @user.stream_item_instances.first.stream_item
|
||||
data = si.stream_data(@user.id)
|
||||
data.type.should == 'DiscussionTopic'
|
||||
data.user_id.should be_nil
|
||||
end
|
||||
end
|
|
@ -20,10 +20,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')
|
||||
|
||||
describe "context/dashboard_topic" do
|
||||
it "should render" do
|
||||
it "should not show the author for nil user_id" do
|
||||
render :partial => "context/dashboard_topic", :locals =>
|
||||
{ :dashboard_topic => OpenObject.new({:root_discussion_entries => nil,
|
||||
:created_at => Time.now.utc})}
|
||||
:created_at => Time.now.utc, :user_id => nil})}
|
||||
response.should_not be_nil
|
||||
response.body.should_not match /Author/
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue