Skip to content

Commit 5ccb693

Browse files
committed
add destructive set_broadcast_policy! to BroadcastPolicy.
fixes #CNVS-2732 current implementation of set_broadcast_policy shares notifications across parent and child classes; this method provides a way for child classes to choose not to share their notifications with the parent. test plan: * create a user and set her notification policies for announcements and discussions to ASAP; * create a new discussion; * verify that the user receives a single message about the new discussion; * repeat the same process with an announcement. Change-Id: Iaafa97f550f804d8bac4fb95552a6a4eeb2626dd Reviewed-on: https://gerrit.instructure.com/16935 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Mark Ericksen <marke@instructure.com> QA-Review: Marc LeGendre <marc@instructure.com>
1 parent fd305e9 commit 5ccb693

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

app/models/announcement.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ def infer_content
3434
self.title ||= t(:no_title, "No Title")
3535
end
3636
protected :infer_content
37-
38-
set_broadcast_policy do
37+
38+
set_broadcast_policy! do
3939
dispatch :new_announcement
4040
to { active_participants(true) - [user] }
41-
whenever { |record|
41+
whenever { |record|
4242
record.context.available? and
4343
((record.just_created and not record.post_delayed?) || record.changed_state(:active, :post_delayed))
4444
}
4545
end
46-
46+
4747
set_policy do
4848
given { |user| self.user == user }
4949
can :update and can :reply and can :read

vendor/plugins/broadcast_policy/lib/broadcast_policy.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ def set_broadcast_policy(&block)
237237
self.broadcast_policy_list.populate(&block)
238238
end
239239

240+
def set_broadcast_policy!(&block)
241+
self.broadcast_policy_list = PolicyList.new
242+
self.broadcast_policy_list.populate(&block)
243+
end
244+
240245
end # SingletonMethods
241246

242247
module InstanceMethods

vendor/plugins/broadcast_policy/spec_canvas/broadcast_policy_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,25 @@ class AnotherModel
6464
list.find_policy_for(foo).should be_present
6565
list.find_policy_for(bar).should be_present
6666
end
67+
68+
it "should allow overwriting of the current block w/ set_broadcast_policy!" do
69+
foo = Canvas::MessageHelper.create_notification('Foo', 'Foo', 0, '', 'Foo')
70+
bar = Canvas::MessageHelper.create_notification('Bar', 'Bar', 0, '', 'Bar')
71+
72+
class Parent < AnotherModel
73+
has_a_broadcast_policy
74+
75+
set_broadcast_policy { dispatch :foo; to {}; whenever {} }
76+
end
77+
78+
class Child < Parent
79+
has_a_broadcast_policy
80+
81+
set_broadcast_policy! { }
82+
end
83+
84+
Child.broadcast_policy_list.find_policy_for(foo).should_not be_present
85+
end
6786
# it "should require a block" do
6887
# lambda{
6988
# class AnotherModel

0 commit comments

Comments
 (0)