2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/joinable/feedable_extensions.rb', line 2
def self.add
Feed.class_eval do
scope :not_from_unjoined, lambda {|joinable_type, user|
where("feeds.scoping_object_type IS NULL OR
feeds.scoping_object_type != '#{joinable_type}' OR
(feeds.feedable_type = 'User' AND feeds.feedable_id = #{user.id}) OR
EXISTS (SELECT * FROM memberships WHERE memberships.joinable_type = '#{joinable_type}' AND memberships.joinable_id = feeds.scoping_object_id AND memberships.user_id = ?)", user.id)
}
scope :not_unscoped, lambda {|action| where('NOT (feeds.scoping_object_type IS NULL AND feeds.action = ?)', action) }
acts_as_joinable_component :parent => 'permission_inheritance_target', :polymorphic => true, :view_permission => lambda {|feed| :find if feed.feedable.acts_like?(:joinable) }
def permission_inheritance_target_type
if feedable.acts_like?(:permissable)
feedable_type
else
scoping_object_type
end
end
def permission_inheritance_target_id
if feedable.acts_like?(:permissable)
feedable_id
else
scoping_object_id
end
end
end
end
|