include admin_context on calls to address book user counts
fixes USERS-539 flag = none test plan: - As an admin not enrolled in the course - Navigate to the People page - Have two different course sections with enrollments - Click the hamburger menu for a user and select the 'edit sections' option - Search for the section for which the user is not enrolled - Verify it returns the proper Section enrollment count that is non zero Change-Id: Ib4e910878651fb80a450258237e43c56138dd528 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/239597 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Cody Cutrer <cody@instructure.com> Reviewed-by: Simon Williams <simon@instructure.com> QA-Review: Simon Williams <simon@instructure.com> Product-Review: August Thornton <august@instructure.com>
This commit is contained in:
parent
c46a1119c4
commit
3f6686e042
|
@ -2449,8 +2449,8 @@ class User < ActiveRecord::Base
|
|||
messageable_user_calculator.messageable_users_in_context(asset_string)
|
||||
end
|
||||
|
||||
def count_messageable_users_in_context(asset_string)
|
||||
messageable_user_calculator.count_messageable_users_in_context(asset_string)
|
||||
def count_messageable_users_in_context(asset_string, options={})
|
||||
messageable_user_calculator.count_messageable_users_in_context(asset_string, options)
|
||||
end
|
||||
|
||||
def messageable_users_in_course(course_or_id)
|
||||
|
|
|
@ -64,7 +64,11 @@ module AddressBook
|
|||
def count_in_contexts(contexts)
|
||||
counts = {}
|
||||
contexts.each do |context|
|
||||
counts[context] = @sender.count_messageable_users_in_context(context)
|
||||
counts[context] =
|
||||
@sender.count_messageable_users_in_context(
|
||||
context,
|
||||
admin_context: admin_context?(context)
|
||||
)
|
||||
end
|
||||
counts
|
||||
end
|
||||
|
|
|
@ -126,6 +126,27 @@ describe SearchController do
|
|||
expect(response.body).to include('other section')
|
||||
end
|
||||
|
||||
it "should return sub-contexts with user counts" do
|
||||
account_admin_user
|
||||
user_session(@user)
|
||||
course_factory(active_all: true)
|
||||
@section = @course.course_sections.create!(:name => 'Section1')
|
||||
@section2 = @course.course_sections.create!(:name => 'Section2')
|
||||
@student1 = user_with_pseudonym(:active_all => true, :name => 'Student1', :username => 'student1@instructure.com')
|
||||
@section.enroll_user(@student1, 'StudentEnrollment', 'active')
|
||||
@student2 = user_with_pseudonym(:active_all => true, :name => 'Student2', :username => 'student2@instructure.com')
|
||||
@section2.enroll_user(@student2, 'StudentEnrollment', 'active')
|
||||
|
||||
get 'recipients', params: {
|
||||
type: 'section', exclude: ["section_#{@section2.id}"],
|
||||
synthetic_contexts: true, context: "course_#{@course.id}_sections",
|
||||
search_all_contexts: true
|
||||
}
|
||||
expect(response.body).to include('Section1')
|
||||
expect(response.body).to include('"user_count":1')
|
||||
expect(response.body).not_to include('Section2')
|
||||
end
|
||||
|
||||
it "should return sub-users" do
|
||||
account_admin_user
|
||||
user_session(@user)
|
||||
|
|
|
@ -306,6 +306,16 @@ describe AddressBook::MessageableUser do
|
|||
course.asset_string => 3
|
||||
})
|
||||
end
|
||||
|
||||
it "returns count in an unassociated :context when an admin" do
|
||||
sender = account_admin_user(active_all: true)
|
||||
enrollment = student_in_course(active_all: true)
|
||||
course = enrollment.course
|
||||
address_book = AddressBook::MessageableUser.new(sender)
|
||||
expect(address_book.count_in_contexts([course.asset_string])).to eql({
|
||||
course.asset_string => 2
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
describe "search_users" do
|
||||
|
|
Loading…
Reference in New Issue