communities_block.rb
981 Bytes
1
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
36
37
38
39
40
41
42
43
class CommunitiesBlock < ProfileListBlock
def self.description
__('A block that displays your communities')
end
def default_title
__('Communities')
end
def help
__('The communities in which the user is a member')
end
def footer
owner = self.owner
case owner
when Profile
lambda do
link_to __('All communities'), :profile => owner.identifier, :controller => 'profile', :action => 'communities'
end
when Environment
lambda do
link_to __('All communities'), :controller => 'search', :action => 'assets', :asset => 'communities'
end
else
''
end
end
def profile_finder
@profile_finder ||= CommunitiesBlock::Finder.new(self)
end
class Finder < ProfileListBlock::Finder
def ids
# FIXME when owner is an environment (i.e. listing communities globally
# this can become SLOW)
block.owner.communities.select(&:public_profile).map(&:id)
end
end
end