templates_controller.rb
1.47 KB
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
48
49
50
51
52
class TemplatesController < AdminController
protect 'manage_environment_templates', :environment
def create_person_template
if request.post?
begin
identifier = params[:name].to_slug
password = Digest::MD5.hexdigest(rand.to_s)
template = User.new(:login => identifier, :email => identifier+'@templates.noo', :password => password, :password_confirmation => password, :person_data => {:name => params[:name], :is_template => true})
template.save!
session[:notice] = _('New template created')
redirect_to :action => 'edit_templates'
rescue
@error = _('Name has already been taken')
end
end
end
def create_community_template
if request.post?
begin
create_organization_template(Community)
session[:notice] = _('New template created')
redirect_to :action => 'edit_templates'
rescue
@error = _('Name has already been taken')
end
end
end
def create_enterprise_template
if request.post?
begin
create_organization_template(Enterprise)
session[:notice] = _('New template created')
redirect_to :action => 'edit_templates'
rescue
@error = _('Name has already been taken')
end
end
end
private
def create_organization_template(klass)
identifier = params[:name].to_slug
template = klass.new(:name => params[:name], :identifier => identifier, :is_template => true)
template.save!
end
end