community.rb
939 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
44
45
46
47
require_dependency 'community'
class Community
SEARCHABLE_SOFTWARE_FIELDS = {
:name => 1,
:identifier => 2,
:nickname => 3
}
attr_accessible :visible
has_one :software_info, :dependent=>:destroy
has_one :institution, :dependent=>:destroy
def self.create_after_moderation(requestor, attributes = {})
community = Community.new(attributes)
if community.environment.enabled?('admin_must_approve_new_communities') &&
!community.environment.admins.include?(requestor)
cc = CreateCommunity.create(attributes.merge(:requestor => requestor))
else
community = Community.create(attributes)
community.add_admin(requestor)
end
community
end
def software?
return !software_info.nil?
end
def institution?
return !institution.nil?
end
def deactivate
self.visible = false
self.save!
end
def activate
self.visible = true
self.save!
end
end