only send conference invitations to active members fixes #5290

test plan:
 * create and publish a course
 * invite and accept a student
 * change the course dates to the future, and restrict access to
   them
 * create a web conference
 * the student should not get a notification

Change-Id: I06b0226c01fd38f99afed0ce767e9e7207864fbe
Reviewed-on: https://gerrit.instructure.com/10288
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
This commit is contained in:
Cody Cutrer 2012-04-24 15:31:03 -06:00
parent 834f53d889
commit 43f33049e3
3 changed files with 29 additions and 2 deletions

View File

@ -119,6 +119,7 @@ class GroupMembership < ActiveRecord::Base
state :rejected
state :deleted
end
alias_method :active?, :accepted?
def self.serialization_excludes; [:uuid]; end

View File

@ -19,7 +19,7 @@
class WebConference < ActiveRecord::Base
include SendToStream
include TextHelper
attr_accessible :title, :duration, :description, :conference_type, :user, :user_settings
attr_accessible :title, :duration, :description, :conference_type, :user, :user_settings, :context
attr_readonly :context_id, :context_type
belongs_to :context, :polymorphic => true
has_many :web_conference_participants
@ -150,7 +150,7 @@ class WebConference < ActiveRecord::Base
set_broadcast_policy do |p|
p.dispatch :web_conference_invitation
p.to { @new_participants }
p.to { @new_participants.select { |p| context.membership_for_user(p).active? } }
p.whenever { |record|
@new_participants && !@new_participants.empty?
}

View File

@ -268,4 +268,30 @@ describe WebConference do
conference.should_not be_restartable
end
end
context "notifications" do
before do
Notification.create!(:name => 'Web Conference Invitation')
end
it "should send notifications" do
course_with_student(:active_all => 1)
conference = DimDimConference.create!(:title => "my conference", :user => @user, :context => @course)
conference.add_attendee(@student)
conference.save!
conference.messages_sent['Web Conference Invitation'].should_not be_empty
end
it "should not send notifications to inactive users" do
course_with_student(:active_all => 1)
@course.restrict_enrollments_to_course_dates = true
@course.start_at = 2.days.from_now
@course.conclude_at = 4.days.from_now
@course.save!
conference = DimDimConference.create!(:title => "my conference", :user => @user, :context => @course)
conference.add_attendee(@student)
conference.save!
conference.messages_sent['Web Conference Invitation'].should be_blank
end
end
end