use message participants in interaction report

shouldn't count conversations in interaction report
if message wasn't received by a student

test plan:
* have two students and a teacher in a course
* as a student send a message to the other student
 and the teacher
* respond as a teacher just to the original sender
* the student interaction report shouldn't count
 the conversation for the student who didn't
 receive the message

closes #ADMIN-1165

Change-Id: I7e67befd867f9be6952865573086551887c1beda
Reviewed-on: https://gerrit.instructure.com/158329
Tested-by: Jenkins
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
QA-Review: Luke Kingsley <lkingsley@instructure.com>
Product-Review: James Williams  <jamesw@instructure.com>
This commit is contained in:
James Williams 2018-07-23 10:50:31 -06:00
parent ccd3669ac7
commit a89cc72a0d
2 changed files with 18 additions and 3 deletions

View File

@ -2299,10 +2299,10 @@ class UsersController < ApplicationController
student[:last_interaction] = [student[:last_interaction], date].compact.max
end
scope = ConversationMessage.
joins("INNER JOIN #{ConversationParticipant.quoted_table_name} ON conversation_participants.conversation_id=conversation_messages.conversation_id").
where('conversation_messages.author_id = ? AND conversation_participants.user_id IN (?) AND NOT conversation_messages.generated', teacher, ids)
joins(:conversation_message_participants).
where('conversation_messages.author_id = ? AND conversation_message_participants.user_id IN (?) AND NOT conversation_messages.generated', teacher, ids)
# fake_arel can't pass an array in the group by through the scope
last_message_dates = scope.group(['conversation_participants.user_id', 'conversation_messages.author_id']).maximum(:created_at)
last_message_dates = scope.group(['conversation_message_participants.user_id', 'conversation_messages.author_id']).maximum(:created_at)
last_message_dates.each do |key, date|
next unless (student = data[key.first.to_i])
student[:last_interaction] = [student[:last_interaction], date].compact.max
@ -2465,6 +2465,7 @@ class UsersController < ApplicationController
@pseudonym.save!
@user = @pseudonym.user
@user.workflow_state = 'registered'
@user.update_account_associations
end
end

View File

@ -47,6 +47,20 @@ describe UsersController do
expect(Nokogiri::HTML(response.body).at_css('table.report tbody tr:first td:nth(2)').text).to match(/less than 1 day/)
end
it "should use conversation message participants when calculating interaction" do
other_student = user_factory(:active_all => true)
@e1.course.enroll_student(other_student, :enrollment_state => 'active')
@conversation = Conversation.initiate([@e1.user, other_student, @teacher], false)
@conversation.add_message(@teacher, "hello", :only_users => [@e1.user]) # only send to one user
get user_student_teacher_activity_url(@teacher, @e1.user)
expect(Nokogiri::HTML(response.body).at_css('table.report tbody tr:first td:nth(2)').text).to match(/less than 1 day/)
get user_student_teacher_activity_url(@teacher, other_student)
expect(Nokogiri::HTML(response.body).at_css('table.report tbody tr:first td:nth(2)').text).to match(/never/)
end
it "should only include students the teacher can view" do
get user_course_teacher_activity_url(@teacher, @course)
expect(response).to be_success