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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
class TenantsController < ApplicationController
authorize_resource :tenant
def index
@tenants = Tenant.scoped
end
def show
@tenant = Tenant.find(params[:id])
@gateways = Gateway.order(:updated_at)
@backup_jobs = BackupJob.order(:finished_at).last(5)
end
def new
@tenant = Tenant.new
@tenant.name = generate_a_new_name(@tenant)
@tenant.sip_domain = SipDomain.last
@tenant.country = GemeinschaftSetup.first.country
@tenant.language = GemeinschaftSetup.first.language
@tenant.internal_extension_ranges = '10-99'
@tenant.from_field_voicemail_email = 'admin@localhost'
@tenant.from_field_pin_change_email = 'admin@localhost'
end
def create
@tenant = Tenant.new(tenant_params)
if @tenant.save
# Become a member of this tenant.
#
@tenant.tenant_memberships.create(:user_id => current_user.id)
# Groups
#
admin_group = @tenant.user_groups.create(:name => t('gemeinschaft_setups.initial_setup.admin_group_name'))
admin_group.users << current_user
user_group = @tenant.user_groups.create(:name => t('gemeinschaft_setups.initial_setup.user_group_name'))
user_group.users << current_user
current_user.update_attributes!(:current_tenant_id => @tenant.id)
# Generate the internal_extensions
#
if !@tenant.internal_extension_ranges.blank?
if @tenant.array_of_internal_extension_numbers.count < 105
# This can be done more or less quick.
@tenant.generate_internal_extensions
else
# Better be on the save side and start a delayed job for this.
@tenant.delay.generate_internal_extensions
end
end
# Generate the external numbers (DIDs)
#
if !@tenant.did_list.blank?
if @tenant.array_of_dids.count < 105
# This can be done more or less quick.
@tenant.generate_dids
else
# Better be on the save side and start a delayed job for this.
@tenant.delay.generate_dids
end
end
if Delayed::Job.count > 0
if SipAccount.any? || Phone.any?
redirect_to @tenant, :notice => t('tenants.controller.successfuly_created_plus_delayed_jobs',
:resource => @tenant,
:amount_of_numbers => @tenant.array_of_internal_extension_numbers.count + @tenant.array_of_dids.count
)
else
redirect_to page_help_path, :notice => t('tenants.controller.successfuly_created_plus_delayed_jobs',
:resource => @tenant,
:amount_of_numbers => @tenant.array_of_internal_extension_numbers.count + @tenant.array_of_dids.count
)
end
else
if SipAccount.any? || Phone.any?
redirect_to @tenant, :notice => t('tenants.controller.successfuly_created',
:resource => @tenant
)
else
redirect_to page_help_path, :notice => t('tenants.controller.successfuly_created',
:resource => @tenant
)
end
end
else
render :new
end
end
def edit
@tenant = Tenant.find(params[:id])
end
def update
@tenant = Tenant.find(params[:id])
if @tenant.update_attributes(tenant_params)
redirect_to @tenant, :notice => t('tenants.controller.successfuly_updated')
else
render :edit
end
end
def destroy
@tenant = Tenant.find(params[:id])
@tenant.destroy
redirect_to tenants_url, :notice => t('tenants.controller.successfuly_destroyed')
end
private
def tenant_params
params.require(:tenant).permit(:name, :description, :sip_domain_id, :country_id, :language_id, :from_field_pin_change_email, :from_field_voicemail_email
)
end
end
|