send announcement notifications to observers; fixes #7424

test-plan:
- in an available course with an active observer, with a communication channel
- have an admin create an announcment
- the observer should receive a notification about it

Change-Id: I94cd7eadead3bd079d820c0ea4595f203c4458bc
Reviewed-on: https://gerrit.instructure.com/9303
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Simon Williams 2012-03-08 10:14:57 -07:00
parent 8f58ea76a4
commit cfbe0c19ec
5 changed files with 27 additions and 8 deletions

View File

@ -37,7 +37,7 @@ class Announcement < DiscussionTopic
set_broadcast_policy do
dispatch :new_announcement
to { participants - [user] }
to { active_participants(true) - [user] }
whenever { |record|
record.context.available? and
((record.just_created and not record.post_delayed?) || record.changed_state(:active, :post_delayed))

View File

@ -85,6 +85,7 @@ class Course < ActiveRecord::Base
has_many :designers, :through => :designer_enrollments, :source => :user
has_many :designer_enrollments, :class_name => 'DesignerEnrollment', :conditions => ['enrollments.workflow_state != ?', 'deleted'], :include => :user
has_many :observers, :through => :observer_enrollments, :source => :user
has_many :participating_observers, :through => :observer_enrollments, :source => :user, :conditions => ['enrollments.workflow_state = ?', 'active']
has_many :observer_enrollments, :class_name => 'ObserverEnrollment', :conditions => ['enrollments.workflow_state != ?', 'deleted'], :include => :user
has_many :instructors, :through => :enrollments, :source => :user, :conditions => "enrollments.type = 'TaEnrollment' or enrollments.type = 'TeacherEnrollment'"
has_many :instructor_enrollments, :class_name => 'Enrollment', :conditions => "(enrollments.type = 'TaEnrollment' or enrollments.type = 'TeacherEnrollment')"
@ -1292,8 +1293,8 @@ class Course < ActiveRecord::Base
GradingStandard.score_to_grade(scheme, score)
end
def participants
(participating_admins + participating_students).uniq
def participants(include_observers=false)
(participating_admins + participating_students + (include_observers ? participating_observers : [])).uniq
end
def enroll_user(user, type='StudentEnrollment', opts={})

View File

@ -519,15 +519,15 @@ class DiscussionTopic < ActiveRecord::Base
def delay_posting=(val); end
def set_assignment=(val); end
def participants
([self.user] + context.participants).compact.uniq
def participants(include_observers=false)
([self.user] + context.participants(include_observers)).compact.uniq
end
def active_participants
def active_participants(include_observers=false)
if !self.context.available? && self.context.respond_to?(:participating_admins)
self.context.participating_admins
else
self.participants
self.participants(include_observers)
end
end

View File

@ -100,7 +100,8 @@ class Group < ActiveRecord::Base
allow_join_request?(user) || allow_self_signup?(user)
end
def participants
def participants(include_observers=false)
# argument needed because #participants is polymorphic for contexts
participating_users.uniq
end

View File

@ -50,5 +50,22 @@ describe Announcement do
dom.css('object')[0]['data'].should eql("http://www.youtuube.com/test")
dom.css('object')[0]['othertag'].should eql(nil)
end
it "should broadcast to students and observers" do
course_with_student(:active_all => true)
course_with_observer(:course => @course, :active_all => true)
notification_name = "New Announcement"
n = Notification.create(:name => notification_name, :category => "TestImmediately")
NotificationPolicy.create(:notification => n, :communication_channel => @student.communication_channel, :frequency => "immediately")
NotificationPolicy.create(:notification => n, :communication_channel => @observer.communication_channel, :frequency => "immediately")
@context = @course
announcement_model
to_users = @a.messages_sent[notification_name].map(&:user)
to_users.should include(@student)
to_users.should include(@observer)
end
end
end