Remove all content_for :auto_discovery’s

In order to get ready for streaming. Rather than having to have every
route that wants to be able to stream worry about adding a
provide_blank(:auto_discovery) so that it doesn’t block and wait there,
we can just handle these all in a way that if you want to have something
there in the <head> you can do it in your controller,
but if you do nothing streaming will just work like you’d expect it to

Test plan:
* all of the <link rel=“alternate” …> tags these made should all be
  There on all pages as before
* so for example:
* go to the dashboard page
* view-source
* you should see something like this in the <head>
  <link rel="alternate" type="application/atom+xml"
    title="User Atom Feed (All Courses)"
    href="/feeds/users/user_xyz123.atom"
   />

Change-Id: I97879d6142141dd7d9ba438a110f012313f6a699
Reviewed-on: https://gerrit.instructure.com/202408
Tested-by: Jenkins
Reviewed-by: Steven Burnett <sburnett@instructure.com>
QA-Review: Ryan Shaw <ryan@instructure.com>
Product-Review: Ryan Shaw <ryan@instructure.com>
This commit is contained in:
Ryan Shaw 2019-07-23 15:42:35 -06:00
parent 737375f3c0
commit c432869039
20 changed files with 78 additions and 131 deletions

View File

@ -52,6 +52,24 @@ class AnnouncementsController < ApplicationController
css_bundle :announcements_index
set_tutorial_js_env
feed_key = nil
if @context_enrollment
feed_key = @context_enrollment.feed_code
elsif can_do(@context, @current_user, :manage)
feed_key = @context.feed_code
elsif @context.available? && @context.respond_to?(:is_public) && @context.is_public
feed_key = @context.asset_string
end
if feed_key
if @context.is_a?(Course)
content_for_head helpers.auto_discovery_link_tag(:atom, feeds_announcements_format_path(feed_key, :atom), {:title => t(:feed_title_course, "Course Announcements Atom Feed")})
content_for_head helpers.auto_discovery_link_tag(:rss, feeds_announcements_format_path(feed_key, :rss), {:title => t(:podcast_title_course, "Course Announcements Podcast Feed")})
elsif @context.is_a?(Group)
content_for_head helpers.auto_discovery_link_tag(:atom, feeds_announcements_format_path(feed_key, :atom), {:title => t(:feed_title_group, "Group Announcements Atom Feed")})
content_for_head helpers.auto_discovery_link_tag(:rss, feeds_announcements_format_path(feed_key, :rss), {:title => t(:podcast_title_group, "Group Announcements Podcast Feed")})
end
end
end
end
end

View File

@ -104,6 +104,7 @@ class CalendarsController < ApplicationController
info
end
StringifyIds.recursively_stringify_ids(@contexts_json)
content_for_head helpers.auto_discovery_link_tag(:atom, @feed_url + '.atom', {:title => t(:feed_title, "Course Calendar Atom Feed")})
js_env(@hash) if @hash
end
end

View File

@ -498,6 +498,10 @@ class CoursesController < ApplicationController
end
@visible_groups = @current_user.visible_groups
if @current_user
content_for_head helpers.auto_discovery_link_tag(:atom, feeds_user_format_path(@current_user.feed_code, :atom), {:title => t('titles.rss.course_announcements', "Course Announcements Atom Feed")})
end
@past_enrollments.sort_by! {|e| Canvas::ICU.collation_key(e.long_name(@current_user))}
[@current_enrollments, @future_enrollments].each {|list| list.sort_by! {|e| [e.active? ? 1 : 0, Canvas::ICU.collation_key(e.long_name(@current_user))]}}
}
@ -1877,6 +1881,12 @@ class CoursesController < ApplicationController
unless @context.grants_right?(@current_user, session, :manage_content)
@course_home_sub_navigation_tools.reject! {|tool| tool.course_home_sub_navigation(:visibility) == 'admins'}
end
if @context_enrollment
content_for_head helpers.auto_discovery_link_tag(:atom, feeds_course_format_path(@context_enrollment.feed_code, :atom), {:title => t("Course Atom Feed")})
elsif @context.available?
content_for_head helpers.auto_discovery_link_tag(:atom, feeds_course_format_path(@context.feed_code, :atom), {:title => t("Course Atom Feed")})
end
elsif @context.indexed && @context.available?
render :description
else

View File

@ -420,6 +420,17 @@ class DiscussionTopicsController < ApplicationController
if user_can_edit_course_settings?
js_env(SETTINGS_URL: named_context_url(@context, :api_v1_context_settings_url))
end
add_body_class 'hide-content-while-scripts-not-loaded'
@page_title = join_title(t('#titles.discussions', "Discussions"), @context.name)
feed_code = @context_enrollment.try(:feed_code) || (@context.available? && @context.feed_code)
content_for_head helpers.auto_discovery_link_tag(:atom, feeds_forum_format_path(@context.feed_code, :atom), {:title => t(:course_discussions_atom_feed_title, "Course Discussions Atom Feed")})
js_bundle :discussion_topics_index_v2
css_bundle :discussions_index
render html: '', layout: true
end
format.json do
if @context.grants_right?(@current_user, session, :moderate_forum)
@ -769,6 +780,19 @@ class DiscussionTopicsController < ApplicationController
conditional_release_js_env(@topic.assignment, includes: [:rule])
js_bundle :discussion
css_bundle :tinymce, :discussions, :learning_outcomes
if @context_enrollment
content_for_head helpers.auto_discovery_link_tag(:atom, feeds_topic_format_path(@topic.id, @context_enrollment.feed_code, :atom), {:title => t(:discussion_atom_feed_title, "Discussion Atom Feed")})
if @topic.podcast_enabled
content_for_head helpers.auto_discovery_link_tag(:rss, feeds_topic_format_path(@topic.id, @context_enrollment.feed_code, :rss), {:title => t(:discussion_podcast_feed_title, "Discussion Podcast Feed")})
end
elsif @context.available?
content_for_head helpers.auto_discovery_link_tag(:atom, feeds_topic_format_path(@topic.id, @context.feed_code, :atom), {:title => t(:discussion_atom_feed_title, "Discussion Atom Feed")})
if @topic.podcast_enabled
content_for_head helpers.auto_discovery_link_tag(:rss, feeds_topic_format_path(@topic.id, @context.feed_code, :rss), {:title => t(:discussion_podcast_feed_title, "Discussion Podcast Feed")})
end
end
end
end
end

View File

@ -98,6 +98,12 @@ class EportfoliosController < ApplicationController
# otherwise, if I can otherwise view the user, link directly to them
@owner_url ||= user_url(@portfolio.user) if @portfolio.user.grants_right?(@current_user, :view_statistics)
end
if can_do(@portfolio, @current_user, :update)
content_for_head helpers.auto_discovery_link_tag(:atom, feeds_eportfolio_path(@portfolio.id, :atom, :verifier => @portfolio.uuid), {:title => t('titles.feed', "Eportfolio Atom Feed") })
elsif @portfolio.public
content_for_head helpers.auto_discovery_link_tag(:atom, feeds_eportfolio_path(@portfolio.id, :atom), {:title => t('titles.feed', "Eportfolio Atom Feed") })
end
end
end

View File

@ -393,6 +393,13 @@ class GroupsController < ApplicationController
set_badge_counts_for(@group, @current_user)
@home_page = @group.wiki.front_page
end
if @context_membership
content_for_head helpers.auto_discovery_link_tag(:atom, feeds_group_format_url(@context_membership.feed_code, :atom), {:title => t('group_atom_feed', "Group Atom Feed")})
elsif @context.available?
content_for_head helpers.auto_discovery_link_tag(:atom, feeds_group_format_url(@context.feed_code, :atom), {:title => t('group_atom_feed', "Group Atom Feed")})
end
end
format.json do
if authorized_action(@group, @current_user, :read)

View File

@ -571,6 +571,11 @@ class UsersController < ApplicationController
@announcements = AccountNotification.for_user_and_account(@current_user, @domain_root_account)
@pending_invitations = @current_user.cached_invitations(:include_enrollment_uuid => session[:enrollment_uuid], :preload_course => true)
if @current_user
content_for_head helpers.auto_discovery_link_tag(:atom, feeds_user_format_path(@current_user.feed_code, :atom), {:title => t('user_atom_feed', "User Atom Feed (All Courses)")})
end
end
def dashboard_stream_items

View File

@ -860,6 +860,10 @@ module ApplicationHelper
end
end
def content_for_head(string)
(@content_for_head ||= []) << string
end
def include_custom_meta_tags
add_csp_for_root
js_env(csp: csp_iframe_attribute) if csp_enforced?

View File

@ -21,23 +21,3 @@
provide :page_title, join_title(t('#titles.announcements', "Announcements"), @context.name)
feed_code = @context_enrollment.try(:feed_code) || (@context.available? && @context.feed_code)
%>
<% content_for :auto_discovery do %>
<% feed_key = nil
if @context_enrollment
feed_key = @context_enrollment.feed_code
elsif can_do(@context, @current_user, :manage)
feed_key = @context.feed_code
elsif @context.available? && @context.respond_to?(:is_public) && @context.is_public
feed_key = @context.asset_string
end
if feed_key
if @context.is_a?(Course) %>
<%= auto_discovery_link_tag(:atom, feeds_announcements_format_path(feed_key, :atom), {:title => t(:feed_title_course, "Course Announcements Atom Feed")}) %>
<%= auto_discovery_link_tag(:rss, feeds_announcements_format_path(feed_key, :rss), {:title => t(:podcast_title_course, "Course Announcements Podcast Feed")}) %>
<% elsif @context.is_a?(Group) %>
<%= auto_discovery_link_tag(:atom, feeds_announcements_format_path(feed_key, :atom), {:title => t(:feed_title_group, "Group Announcements Atom Feed")}) %>
<%= auto_discovery_link_tag(:rss, feeds_announcements_format_path(feed_key, :rss), {:title => t(:podcast_title_group, "Group Announcements Podcast Feed")}) %>
<% end
end %>
<% end %>

View File

@ -23,7 +23,6 @@
</style>
<% provide :page_title, @assignment.title %>
<% provide_blank :auto_discovery %>
<% provide :right_side, render(:partial => "assignment_sidebar") %>
<% if @locked && !@locked[:can_view] %>

View File

@ -42,10 +42,6 @@
%>
<h1 class="screenreader-only"><%= t(:page_title_header, "Calendar") %></h1>
<% content_for :auto_discovery do %>
<%= auto_discovery_link_tag(:atom, @feed_url + '.atom', {:title => t(:feed_title, "Course Calendar Atom Feed")}) %>
<% end %>
<% provide :right_side do %>
<a href="#" class="screenreader-only skip-to-calendar"><%= t(:skip_to_calendar, "Skip to calendar") %></a>

View File

@ -18,11 +18,6 @@
<% content_for :page_title, t('titles.courses', 'Courses') %>
<% content_for :auto_discovery do %>
<% if @current_user %>
<%= auto_discovery_link_tag(:atom, feeds_user_format_path(@current_user.feed_code, :atom), {:title => t('titles.rss.course_announcements', "Course Announcements Atom Feed")}) %>
<% end %>
<% end %>
<% css_bundle :context_list, :course_list %>
<% js_bundle :course_list %>

View File

@ -20,13 +20,6 @@
<% css_bundle :course_show %>
<% @active_tab ||= "home" %>
<h1 class='screenreader-only'><%= @context.name %></h1>
<% content_for :auto_discovery do %>
<% if @context_enrollment %>
<%= auto_discovery_link_tag(:atom, feeds_course_format_path(@context_enrollment.feed_code, :atom), {:title => t("Course Atom Feed")}) %>
<% elsif @context.available? %>
<%= auto_discovery_link_tag(:atom, feeds_course_format_path(@context.feed_code, :atom), {:title => t("Course Atom Feed")}) %>
<% end %>
<% end %>
<% provide :right_side do %>
<div id="course_show_secondary">

View File

@ -1,27 +0,0 @@
<%
# Copyright (C) 2011 - present 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/>.
add_body_class 'hide-content-while-scripts-not-loaded'
provide :page_title, join_title(t('#titles.discussions', "Discussions"), @context.name)
feed_code = @context_enrollment.try(:feed_code) || (@context.available? && @context.feed_code)
content_for :auto_discovery, auto_discovery_link_tag(:atom, feeds_forum_format_path(@context.feed_code, :atom), {:title => t(:course_discussions_atom_feed_title, "Course Discussions Atom Feed")})
js_bundle :discussion_topics_index_v2
css_bundle :discussions_index
%>

View File

@ -21,20 +21,6 @@
@discussion_presenter = DiscussionTopicPresenter.new(@topic, @current_user)
%>
<% content_for :auto_discovery do %>
<% if @context_enrollment %>
<%= auto_discovery_link_tag(:atom, feeds_topic_format_path(@topic.id, @context_enrollment.feed_code, :atom), {:title => t(:discussion_atom_feed_title, "Discussion Atom Feed")}) %>
<% if @topic.podcast_enabled %>
<%= auto_discovery_link_tag(:rss, feeds_topic_format_path(@topic.id, @context_enrollment.feed_code, :rss), {:title => t(:discussion_podcast_feed_title, "Discussion Podcast Feed")}) %>
<% end %>
<% elsif @context.available? %>
<%= auto_discovery_link_tag(:atom, feeds_topic_format_path(@topic.id, @context.feed_code, :atom), {:title => t(:discussion_atom_feed_title, "Discussion Atom Feed")}) %>
<% if @topic.podcast_enabled %>
<%= auto_discovery_link_tag(:rss, feeds_topic_format_path(@topic.id, @context.feed_code, :rss), {:title => t(:discussion_podcast_feed_title, "Discussion Podcast Feed")}) %>
<% end %>
<% end %>
<% end %>
<% if (@headers || !@locked) && ((show_crs_graphs = can_do(@context, @current_user, :view_all_grades) && ConditionalRelease::Service.triggers_mastery_paths?(@topic.assignment, @current_user, session)) || !@context.try(:feature_enabled?, :rce_enhancements)) %>
<% provide :right_side do %>
<div id="sidebar_content" class="rs-margin-bottom">

View File

@ -24,14 +24,6 @@
js_env({ SECTION_COUNT_IDX: @page.content_sections.count })
%>
<% content_for :auto_discovery do %>
<% if can_do(@portfolio, @current_user, :update) %>
<%= auto_discovery_link_tag(:atom, feeds_eportfolio_path(@portfolio.id, :atom, :verifier => @portfolio.uuid), {:title => t('titles.feed', "Eportfolio Atom Feed") }) %>
<% elsif @portfolio.public %>
<%= auto_discovery_link_tag(:atom, feeds_eportfolio_path(@portfolio.id, :atom), {:title => t('titles.feed', "Eportfolio Atom Feed") }) %>
<% end %>
<% end %>
<% provide :left_side do %>
<div class="eportfolio-name">
<h3><%= @portfolio.name %></h3>

View File

@ -20,13 +20,6 @@
<% css_bundle :dashboard %>
<% js_bundle :dashboard %>
<% @active_tab = "home" %>
<% content_for :auto_discovery do %>
<% if @context_membership %>
<%= auto_discovery_link_tag(:atom, feeds_group_format_url(@context_membership.feed_code, :atom), {:title => t('group_atom_feed', "Group Atom Feed")}) %>
<% elsif @context.available? %>
<%= auto_discovery_link_tag(:atom, feeds_group_format_url(@context.feed_code, :atom), {:title => t('group_atom_feed', "Group Atom Feed")}) %>
<% end %>
<% end %>
<% provide :right_side do %>

View File

@ -31,7 +31,6 @@
<script>window.fetchIgnoredByNewRelic = window.fetch</script><%= browser_performance_monitor_embed %>
<%= favicon_link_tag(favicon) %>
<%= favicon_link_tag(brand_variable('ic-brand-apple-touch-icon'), rel: 'apple-touch-icon', type: nil) %>
<%= yield :auto_discovery %>
<%= stylesheet_link_tag(active_brand_config_url('css'), media: "all") %>
<%= yield :head %>
<%=
@ -91,4 +90,7 @@
<% @xhrs_to_prefetch_from_controller&.each do |args| %>
<%= prefetch_xhr(*args) %>
<% end %>
<% @content_for_head&.each do |string| %>
<%= string %>
<% end %>
</head>

View File

@ -34,12 +34,6 @@
<%= prefetch_xhr('/api/v1/users/self/missing_submissions?include[]=planner_overrides&filter[]=submittable') %>
<% end %>
<% content_for :auto_discovery do %>
<% if @current_user %>
<%= auto_discovery_link_tag(:atom, feeds_user_format_path(@current_user.feed_code, :atom), {:title => t('user_atom_feed', "User Atom Feed (All Courses)")}) %>
<% end %>
<% end %>
<% provide :right_side do %>
<% unless show_planner? %>
<div class="placeholder"></div>

View File

@ -1,31 +0,0 @@
#
# Copyright (C) 2011 - present 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')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')
describe "/discussion_topics/index" do
it "should render" do
course_with_teacher
view_context(@course, @user)
assign(:body_classes, [])
assign(:discussion_topics_urls_to_prefetch, [])
render "discussion_topics/index"
expect(response).not_to be_nil
end
end