Skip to content
Browse files

Fix: apps receive notifications for private posts

closes #60
  • Loading branch information...
1 parent 2f40767 commit 67bf82f07760f2cea221c8cdec9ef64c788cebbc Jesse Stuart committed Dec 27, 2012
View
52 lib/tentd/model/notification_subscription.rb
@@ -41,7 +41,34 @@ def self.notify_all(type, post_id)
:view => subscription.type_view
)
end
- elsif !post.original
+ else
+ if post.original
+ # Notify follower subscriptions
+ NotificationSubscription.join(
+ :followers,
+ :notification_subscriptions__follower_id => :followers__id
+ ).join(
+ Permission,
+ :permissions__follower_access_id => :followers__id
+ ).join(
+ :posts,
+ :permissions__post_id => :posts__id
+ ).where(
+ :notification_subscriptions__type_base => [TentType.new(type).base, 'all'],
+ :permissions__post_id => post.id,
+ :followers__deleted_at => nil,
+ :posts__deleted_at => nil
+ ).select(
+ :notification_subscriptions__id,
+ :notification_subscriptions__app_authorization_id,
+ :notification_subscriptions__follower_id
+ ).all.each do |subscription|
+ next unless post.can_notify?(subscription.subject)
+ Notifications.notify(:subscription_id => subscription.id, :post_id => post_id, :view => subscription.type_view)
+ end
+ end
+
+ # Notify app authorization subscriptions
q = NotificationSubscription.select(
:id, :app_authorization_id
).where(
@@ -57,29 +84,6 @@ def self.notify_all(type, post_id)
:view => subscription.type_view
)
end
- else
- NotificationSubscription.join(
- :followers,
- :notification_subscriptions__follower_id => :followers__id
- ).join(
- Permission,
- :permissions__follower_access_id => :followers__id
- ).join(
- :posts,
- :permissions__post_id => :posts__id
- ).where(
- :notification_subscriptions__type_base => [TentType.new(type).base, 'all'],
- :permissions__post_id => post.id,
- :followers__deleted_at => nil,
- :posts__deleted_at => nil
- ).select(
- :notification_subscriptions__id,
- :notification_subscriptions__app_authorization_id,
- :notification_subscriptions__follower_id
- ).all.each do |subscription|
- next unless post.can_notify?(subscription.subject)
- Notifications.notify(:subscription_id => subscription.id, :post_id => post_id, :view => subscription.type_view)
- end
end
end
View
32 spec/integration/model/notification_subscription_spec.rb
@@ -96,9 +96,9 @@
expect(subscription.notify_about(post.id)).to be_true
end
- context 'when post not original' do
+ notify_app_examples = proc do
context 'when permissible via post type' do
- let(:post) { Fabricate(:post, :public => false, :original => false) }
+ let(:post) { Fabricate(:post, :public => post_public?, :original => post_original?) }
let!(:subscription) {
Fabricate(:notification_subscription,
:type_base => post.type_base,
@@ -131,6 +131,34 @@
end
end
end
+
+ context 'when post is original' do
+ let(:post_original?) { true }
+
+ context 'when post is public' do
+ let(:post_public?) { true }
+ context &notify_app_examples
+ end
+
+ context 'when post is private' do
+ let(:post_public?) { false }
+ context &notify_app_examples
+ end
+ end
+
+ context 'when post not original' do
+ let(:post_original?) { false }
+
+ context 'when post is public' do
+ let(:post_public?) { true }
+ context &notify_app_examples
+ end
+
+ context 'when post is private' do
+ let(:post_public?) { false }
+ context &notify_app_examples
+ end
+ end
end
context ".notify_entity(entity, post_id)" do

0 comments on commit 67bf82f

Please sign in to comment.
Something went wrong with that request. Please try again.