Skip to content

Commit

Permalink
show_sections_in_course_tray setting
Browse files Browse the repository at this point in the history
closes EGG-9
flag=none

test plan:
- Create a course with sections
- Enroll yourself in every section with any role
(e.g. teacher, student etc)
- Click the courses icon in the left navbar, then in
the courses pop out menu click All Courses link and
mark the course as favorite
- Go to Root Account settings
- "Show sections in course tray" is enabled by default
- Click the courses icon in the left navbar
- Sections show up
- Disable "Show sections in course tray"
- Click the courses icon in the left navbar
- Sections do not show up

Change-Id: I3720ab36c19f6d5a590a631c17b58fd5a948f522
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/354841
Tested-by: Service Cloud Jenkins <[email protected]>
Reviewed-by: Martin Yosifov <[email protected]>
QA-Review: Martin Yosifov <[email protected]>
Product-Review: Sam Garza <[email protected]>
  • Loading branch information
Wilmer Corrales committed Aug 13, 2024
1 parent 360db7c commit f608fbf
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/controllers/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2064,7 +2064,8 @@ def ensure_sis_max_name_length_value!(account_settings)
:enable_name_pronunciation,
:enable_limited_access_for_students,
:enable_as_k5_account,
:use_classic_font_in_k5].freeze
:use_classic_font_in_k5,
:show_sections_in_course_tray].freeze

def permitted_account_attributes
[:name,
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ def js_env(hash = {}, overwrite = false)
open_registration: @domain_root_account&.open_registration?,
collapse_global_nav: @current_user&.collapse_global_nav?,
release_notes_badge_disabled: @current_user&.release_notes_badge_disabled?,
can_add_pronouns: @domain_root_account&.can_add_pronouns?
can_add_pronouns: @domain_root_account&.can_add_pronouns?,
show_sections_in_course_tray: @domain_root_account&.show_sections_in_course_tray?
},
RAILS_ENVIRONMENT: Canvas.environment,
}
Expand Down
1 change: 1 addition & 0 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ def allow_student_anonymous_discussion_topics
add_setting :disable_login_search_indexing, boolean: true, root_only: true, default: false
add_setting :allow_additional_email_at_registration, boolean: true, root_only: true, default: false
add_setting :limit_personal_access_tokens, boolean: true, root_only: true, default: false
add_setting :show_sections_in_course_tray, boolean: true, root_only: true, default: true

# Allow enabling metrics like Heap for sandboxes and other accounts without Salesforce data
add_setting :enable_usage_metrics, boolean: true, root_only: true, default: false
Expand Down
9 changes: 9 additions & 0 deletions app/views/accounts/settings.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,15 @@
</tr>
<% end %>
<% if !@account.site_admin? && @account.primary_settings_root_account? %>
<tr>
<td colspan="2">
<%= settings.check_box :show_sections_in_course_tray, checked: @account.show_sections_in_course_tray? %>
<%= settings.label :show_sections_in_course_tray, t("Show Sections in Course Tray.") %>
</td>
</tr>
<% end %>
<% if !@account.site_admin? && @account.primary_settings_root_account? && @account.feature_enabled?(:admin_manage_access_tokens)%>
<tr>
<td colspan="2">
Expand Down
31 changes: 31 additions & 0 deletions spec/controllers/accounts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,37 @@ def account_with_admin(opts = {})
expect(@account.settings[:sis_assignment_name_length_input][:value]).to eq "255"
end

it "updates 'show_sections_in_course_tray'" do
account_with_admin_logged_in
post(
:update,
params: {
id: @account.id,
account: {
settings: {
show_sections_in_course_tray: false
}
}
}
)
@account.reload
expect(@account.settings[:show_sections_in_course_tray]).to be false

post(
:update,
params: {
id: @account.id,
account: {
settings: {
show_sections_in_course_tray: true
}
}
}
)
@account.reload
expect(@account.settings[:show_sections_in_course_tray]).to be true
end

it "allows admins to set the sis_source_id on sub accounts" do
account_with_admin_logged_in
@account = @account.sub_accounts.create!
Expand Down
5 changes: 3 additions & 2 deletions spec/controllers/application_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -339,17 +339,18 @@
end

it "gets appropriate settings from the root account" do
root_account = double(global_id: 1, id: 1, feature_enabled?: false, open_registration?: true, can_add_pronouns?: true, settings: {}, cache_key: "key", uuid: "bleh", salesforce_id: "blah")
root_account = double(global_id: 1, id: 1, feature_enabled?: false, open_registration?: true, can_add_pronouns?: true, show_sections_in_course_tray?: true, settings: {}, cache_key: "key", uuid: "bleh", salesforce_id: "blah")
allow(root_account).to receive(:kill_joy?).and_return(false)
allow(HostUrl).to receive_messages(file_host: "files.example.com")
controller.instance_variable_set(:@domain_root_account, root_account)
expect(controller.js_env[:SETTINGS][:open_registration]).to be_truthy
expect(controller.js_env[:SETTINGS][:can_add_pronouns]).to be_truthy
expect(controller.js_env[:SETTINGS][:show_sections_in_course_tray]).to be_truthy
expect(controller.js_env[:KILL_JOY]).to be_falsey
end

it "disables fun when set" do
root_account = double(global_id: 1, id: 1, feature_enabled?: false, open_registration?: true, can_add_pronouns?: true, settings: {}, cache_key: "key", uuid: "blah", salesforce_id: "bleh")
root_account = double(global_id: 1, id: 1, feature_enabled?: false, open_registration?: true, can_add_pronouns?: true, show_sections_in_course_tray?: true, settings: {}, cache_key: "key", uuid: "blah", salesforce_id: "bleh")
allow(root_account).to receive(:kill_joy?).and_return(true)
allow(HostUrl).to receive_messages(file_host: "files.example.com")
controller.instance_variable_set(:@domain_root_account, root_account)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ const UNPUBLISHED = 'unpublished'

export const CourseListItemContent = ({course}: {course: Course}) => {
const sectionNames = (course.sections || []).map(section => section.name)
const sectionDetails = sectionNames.length > 0 ? sectionNames.sort().join(', ') : null
const showSections = ENV.SETTINGS?.show_sections_in_course_tray
const sectionDetails =
showSections && sectionNames.length > 0 ? sectionNames.sort().join(', ') : null
const courseDetails =
ENV.FEATURES?.courses_popout_sisid && course.sis_course_id
? course.enrollment_term_id > 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ describe('CoursesTray', () => {
window.ENV.K5_USER = false
window.ENV.FEATURES.courses_popout_sisid = true
window.ENV.current_user_roles = []
window.ENV.SETTINGS = {show_sections_in_course_tray: true}
})

afterEach(() => {
Expand Down Expand Up @@ -184,6 +185,12 @@ describe('CoursesTray', () => {
expect(getByText('Section3, Section4, Section5')).toBeInTheDocument()
})

it('does not render sections if setting show_sections_in_course_tray is disabled', () => {
window.ENV.SETTINGS.show_sections_in_course_tray = false
const {queryByText} = render(<CoursesTray />)
expect(queryByText('Section3, Section4, Section5')).not.toBeInTheDocument()
})

it('renders the correct URL for each course', () => {
const {getByText} = render(<CoursesTray />)
expect(getByText('Course1').getAttribute('href')).toBe('/courses/1')
Expand Down

0 comments on commit f608fbf

Please sign in to comment.