announcements rss feed shows correct list of visible announcements
fixes CNVS-19529 test plan: - in a course, create the following types of announcements: * a normal announcement that is visible * an announcement that is post_delayed for the future * an announcement that is closed for comments (create announcement, go to show page and close for comments in the cog menu) * an announcement that is deleted (create and the delete) - view the announcement rss feed as a teacher and a student - the teacher should see everything but the deleted discussion - the student should just see the normal one and the closed for comments one Change-Id: I46dd583c01cbd7817f3d599cb3816bf386cf3266 Reviewed-on: https://gerrit.instructure.com/51095 Tested-by: Jenkins Reviewed-by: Mike Nomitch <mnomitch@instructure.com> Reviewed-by: John Corrigan <jcorrigan@instructure.com> QA-Review: Adam Stone <astone@instructure.com> Product-Review: Simon Williams <simon@instructure.com>
This commit is contained in:
parent
8376f3d365
commit
dde9ee86ca
|
@ -49,7 +49,8 @@ class AnnouncementsController < ApplicationController
|
|||
|
||||
def public_feed
|
||||
return unless get_feed_context
|
||||
announcements = @context.announcements.active.order('posted_at DESC').limit(15).reject{|a| a.locked_for?(@current_user, :check_policies => true) }
|
||||
announcements = @context.announcements.active.order('posted_at DESC').limit(15).
|
||||
select{|a| a.visible_for?(@current_user) }
|
||||
|
||||
respond_to do |format|
|
||||
format.atom {
|
||||
|
|
|
@ -722,7 +722,8 @@ class DiscussionTopicsController < ApplicationController
|
|||
f.id = polymorphic_url([@context, :discussion_topics])
|
||||
end
|
||||
@entries = []
|
||||
@entries.concat @context.discussion_topics.reject{|a| a.locked_for?(@current_user, :check_policies => true) }
|
||||
@entries.concat @context.discussion_topics.
|
||||
select{|dt| dt.visible_for?(@current_user) }
|
||||
@entries.concat @context.discussion_entries.active
|
||||
@entries = @entries.sort_by{|e| e.updated_at}
|
||||
@entries.each do |entry|
|
||||
|
|
|
@ -968,10 +968,9 @@ class DiscussionTopic < ActiveRecord::Base
|
|||
# Public: Determine if the given user can view this discussion topic.
|
||||
#
|
||||
# user - The user attempting to view the topic (default: nil).
|
||||
# options - Options passed to the locked_for? call (default: {}).
|
||||
#
|
||||
# Returns a boolean.
|
||||
def visible_for?(user = nil, options = {})
|
||||
def visible_for?(user = nil)
|
||||
# user is the topic's author
|
||||
return true if user == self.user
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ module Api::V1::DiscussionTopics
|
|||
# Returns an array of hashes.
|
||||
def discussion_topics_api_json(topics, context, user, session, opts={})
|
||||
topics.inject([]) do |result, topic|
|
||||
if topic.visible_for?(user, check_policies: true)
|
||||
if topic.visible_for?(user)
|
||||
result << discussion_topic_api_json(topic, context, user, session, opts)
|
||||
end
|
||||
|
||||
|
|
|
@ -23,11 +23,11 @@ describe AnnouncementsController do
|
|||
course_with_student(:active_all => true)
|
||||
end
|
||||
|
||||
def course_announcement
|
||||
@announcement = @course.announcements.create!(
|
||||
def course_announcement(opts = {})
|
||||
@announcement = @course.announcements.create!({
|
||||
:title => "some announcement",
|
||||
:message => "some message"
|
||||
)
|
||||
}.merge(opts))
|
||||
end
|
||||
|
||||
describe "GET 'index'" do
|
||||
|
@ -73,13 +73,40 @@ describe AnnouncementsController do
|
|||
end
|
||||
|
||||
it "shows the 15 most recent announcements" do
|
||||
announcements = []
|
||||
16.times { announcements << course_announcement.id }
|
||||
announcements.shift # Drop first announcement so we have the 15 most recent
|
||||
announcement_ids = []
|
||||
16.times { announcement_ids << course_announcement.id }
|
||||
announcement_ids.shift # Drop first announcement so we have the 15 most recent
|
||||
|
||||
get 'public_feed', :format => 'atom', :feed_code => @enrollment.feed_code
|
||||
|
||||
feed_entries = Atom::Feed.load_feed(response.body).entries
|
||||
feed_entries.map!{ |e| e.id.gsub(/.*topic_/, "").to_i }
|
||||
expect(feed_entries).to match_array(announcements)
|
||||
feed_entry_ids = feed_entries.map{ |e| e.id.gsub(/.*topic_/, "").to_i }
|
||||
expect(feed_entry_ids).to match_array(announcement_ids)
|
||||
end
|
||||
|
||||
it "only shows announcements that are visible to the caller" do
|
||||
normal_ann = @a # from the announcement_model in the before block
|
||||
closed_for_comments_ann = course_announcement(locked: true)
|
||||
post_delayed_ann = @course.announcements.build({
|
||||
title: 'hi',
|
||||
message: 'blah',
|
||||
delayed_post_at: 1.day.from_now
|
||||
})
|
||||
post_delayed_ann.workflow_state = 'post_delayed'
|
||||
post_delayed_ann.save!
|
||||
deleted_ann = course_announcement
|
||||
deleted_ann.destroy
|
||||
|
||||
expect(closed_for_comments_ann).to be_locked
|
||||
expect(post_delayed_ann).to be_post_delayed
|
||||
expect(deleted_ann).to be_deleted
|
||||
visible_announcements = [normal_ann, closed_for_comments_ann]
|
||||
|
||||
get 'public_feed', :format => 'atom', :feed_code => @enrollment.feed_code
|
||||
|
||||
feed_entries = Atom::Feed.load_feed(response.body).entries
|
||||
feed_entry_ids = feed_entries.map{ |e| e.id.gsub(/.*topic_/, "").to_i }
|
||||
expect(feed_entry_ids).to match_array(visible_announcements.map(&:id))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue