3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/grouped_post.rb', line 3
def self.included(base)
base.class_eval {
named_scope :visible_to, lambda { |reader|
if reader.nil? || reader.groups.empty?
conditions = "pp.group_id IS NULL"
else
ids = reader.group_ids
conditions = reader.nil? ? "pp.group_id IS NULL" : ["pp.group_id IS NULL OR pp.group_id IN(#{ids.map{"?"}.join(',')})", *ids]
end
{
:joins => "LEFT OUTER JOIN topics on posts.topic_id = topics.id LEFT OUTER JOIN forums on topics.forum_id = forums.id LEFT OUTER JOIN permissions as pp on pp.permitted_id = forums.id AND pp.permitted_type = 'Forum'",
:group => column_names.map { |n| self.table_name + '.' + n }.join(','),
:conditions => conditions,
:readonly => false
}
} do
def count
length
end
end
}
end
|