forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathannouncements_controller.rb
More file actions
97 lines (87 loc) · 3.86 KB
/
Copy pathannouncements_controller.rb
File metadata and controls
97 lines (87 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#
# 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 'atom'
class AnnouncementsController < ApplicationController
include Api::V1::DiscussionTopics
before_action :require_context, :except => :public_feed
before_action { |c| c.active_tab = "announcements" }
def index
return unless authorized_action(@context, @current_user, :read)
return if @context.class.const_defined?('TAB_ANNOUNCEMENTS') && !tab_enabled?(@context.class::TAB_ANNOUNCEMENTS)
log_asset_access([ "announcements", @context ], "announcements", "other")
respond_to do |format|
format.html do
add_crumb(t(:announcements_crumb, "Announcements"))
can_create = @context.announcements.temp_record.grants_right?(@current_user, session, :create)
js_env :permissions => {
:create => can_create,
manage_content: @context.grants_right?(@current_user, session, :manage_content),
:moderate => can_create
}
js_env :is_showing_announcements => true
js_env :atom_feed_url => feeds_announcements_format_path((@context_enrollment || @context).feed_code, :atom)
if @context.is_a?(Course) && @context.grants_right?(@current_user, session, :read) && !@js_env[:COURSE_ID].present?
js_env :COURSE_ID => @context.id.to_s
end
set_tutorial_js_env
end
end
end
def show
redirect_to named_context_url(@context, :context_discussion_topic_url, params[:id])
end
def public_feed
return unless get_feed_context
announcements = @context.announcements.active.order('posted_at DESC').limit(15).
select{|a| a.visible_for?(@current_user) }
respond_to do |format|
format.atom {
feed = Atom::Feed.new do |f|
f.title = t(:feed_name, "%{course} Announcements Feed", :course => @context.name)
f.links << Atom::Link.new(:href => polymorphic_url([@context, :announcements]), :rel => 'self')
f.updated = Time.now
f.id = polymorphic_url([@context, :announcements])
end
announcements.each do |e|
feed.entries << e.to_atom
end
render :plain => feed.to_xml
}
format.rss {
@announcements = announcements
require 'rss/2.0'
rss = RSS::Rss.new("2.0")
channel = RSS::Rss::Channel.new
channel.title = t(:podcast_feed_name, "%{course} Announcements Podcast Feed", :course => @context.name)
if @context.is_a?(Course)
channel.description = t(:podcast_feed_description_course, "Any media files linked from or embedded within announcements in the course \"%{course}\" will appear in this feed.", :course => @context.name)
elsif @context.is_a?(Group)
channel.description = t(:podcast_feed_description_group, "Any media files linked from or embedded within announcements in the group \"%{group}\" will appear in this feed.", :group => @context.name)
end
channel.link = polymorphic_url([@context, :announcements])
channel.pubDate = Time.now.strftime("%a, %d %b %Y %H:%M:%S %z")
elements = Announcement.podcast_elements(announcements, @context)
elements.each do |item|
channel.items << item
end
rss.channel = channel
render :plain => rss.to_s
}
end
end
end