show custom role names in courses drop-down

test plan:
* create a custom course-level role for an account
* enroll a user into an active course with the custom role
* as that user, the "Courses" dropdown menu on the navigation header
 should read "Enrolled as: [Custom Role]" instead of
 the base type for the role

refs #CNVS-5349

Change-Id: Ife07a10852de3d5376a945c9f35d3ef56cb4ca58
Reviewed-on: https://gerrit.instructure.com/44507
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
QA-Review: Jahnavi Yetukuri <jyetukuri@instructure.com>
Product-Review: Cosme Salazar <cosme@instructure.com>
This commit is contained in:
James Williams 2014-11-17 07:52:50 -07:00
parent b9e5e48754
commit 1de91edaa2
6 changed files with 25 additions and 8 deletions

View File

@ -583,10 +583,11 @@ module ApplicationHelper
def map_courses_for_menu(courses)
mapped = courses.map do |course|
term = course.enrollment_term.name if !course.enrollment_term.default_term?
role = Role.get_role_by_id(course.primary_enrollment_role_id) || Enrollment.get_built_in_role_for_type(course.primary_enrollment_type)
subtitle = (course.primary_enrollment_state == 'invited' ?
before_label('#shared.menu_enrollment.labels.invited_as', 'Invited as') :
before_label('#shared.menu_enrollment.labels.enrolled_as', "Enrolled as")
) + " " + Enrollment.readable_type(course.primary_enrollment)
) + " " + role.label
{
:longName => "#{course.name} - #{course.short_name}",
:shortName => course.name,

View File

@ -27,7 +27,7 @@ class Course < ActiveRecord::Base
include TimeZoneHelper
attr_accessor :teacher_names
attr_writer :student_count, :primary_enrollment, :primary_enrollment_rank, :primary_enrollment_state, :invitation
attr_writer :student_count, :primary_enrollment_type, :primary_enrollment_role_id, :primary_enrollment_rank, :primary_enrollment_state, :invitation
attr_accessible :name,
:section,
@ -2768,7 +2768,7 @@ class Course < ActiveRecord::Base
end
end
%w{student_count primary_enrollment primary_enrollment_rank primary_enrollment_state invitation}.each do |method|
%w{student_count primary_enrollment_type primary_enrollment_role_id primary_enrollment_rank primary_enrollment_state invitation}.each do |method|
class_eval <<-RUBY
def #{method}
read_attribute(:#{method}) || @#{method}

View File

@ -1606,7 +1606,7 @@ class User < ActiveRecord::Base
@courses_with_primary_enrollment ||= {}
@courses_with_primary_enrollment.fetch(cache_key) do
res = self.shard.activate do
result = Rails.cache.fetch([self, 'courses_with_primary_enrollment', association, options, ApplicationController.region].cache_key, :expires_in => 15.minutes) do
result = Rails.cache.fetch([self, 'courses_with_primary_enrollment2', association, options, ApplicationController.region].cache_key, :expires_in => 15.minutes) do
# Set the actual association based on if its asking for favorite courses or not.
actual_association = association == :favorite_courses ? :current_and_invited_courses : association
@ -1627,7 +1627,7 @@ class User < ActiveRecord::Base
scope = scope.shard(in_region_associated_shards)
end
courses = scope.select("courses.*, enrollments.id AS primary_enrollment_id, enrollments.type AS primary_enrollment, #{Enrollment.type_rank_sql} AS primary_enrollment_rank, enrollments.workflow_state AS primary_enrollment_state").
courses = scope.select("courses.*, enrollments.id AS primary_enrollment_id, enrollments.type AS primary_enrollment_type, enrollments.role_id AS primary_enrollment_role_id, #{Enrollment.type_rank_sql} AS primary_enrollment_rank, enrollments.workflow_state AS primary_enrollment_state").
order("courses.id, #{Enrollment.type_rank_sql}, #{Enrollment.state_rank_sql}").
distinct_on(:id).to_a
@ -1658,7 +1658,8 @@ class User < ActiveRecord::Base
ActiveRecord::Associations::Preloader.new(pending_enrollments, :course).run
res.concat(pending_enrollments.map do |e|
c = e.course
c.primary_enrollment = e.type
c.primary_enrollment_type = e.type
c.primary_enrollment_role_id = e.role_id
c.primary_enrollment_rank = e.rank_sortable.to_s
c.primary_enrollment_state = e.workflow_state
c.invitation = e.uuid

View File

@ -991,7 +991,7 @@ class MessageableUser
def student_courses
@student_courses_by_shard ||= {}
@student_courses_by_shard[Shard.current] ||= all_courses.
select{ |course| course.primary_enrollment == 'StudentEnrollment' }
select{ |course| course.primary_enrollment_type == 'StudentEnrollment' }
end
def visible_section_ids_in_courses(courses)

View File

@ -46,6 +46,21 @@ describe "navigation" do
expect(list[0].text).not_to match /Term/ # "
end
it "should display custom role names" do
custom_teacher = custom_teacher_role("CustomTeacherRole", :account => Account.default)
course_with_teacher(:course_name => "Course 1", :user => @user, :active_all => true, :role => custom_teacher)
course_with_teacher(:course_name => "Course 2", :user => @user, :active_all => true)
get "/"
page = Nokogiri::HTML(response.body)
list = page.css(".menu-item-drop-column-list li")
# order of tests assumes alphabetical order of list
expect(list[0].text).to match /CustomTeacherRole/
expect(list[1].text).to match /Teacher/
end
it "should not fail on courses where the term no longer exists" do
get "/"
page = Nokogiri::HTML(response.body)

View File

@ -516,7 +516,7 @@ describe User do
# only four, in the right order (type, then name), and with the top type per course
expect(@user.courses_with_primary_enrollment.map{|c| [c.id, c.primary_enrollment]}).to eql [
expect(@user.courses_with_primary_enrollment.map{|c| [c.id, c.primary_enrollment_type]}).to eql [
[@course5.id, 'TeacherEnrollment'],
[@course2.id, 'TeacherEnrollment'],
[@course3.id, 'TeacherEnrollment'],