summaryrefslogtreecommitdiff
path: root/app/controllers/tenants_controller.rb
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-17 12:05:14 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-17 12:05:14 +0100
commiteaad37485fe59d0306c37cc038dda6d210052910 (patch)
tree072c4b0e33d442528555b82c415f5e7a1712b2b0 /app/controllers/tenants_controller.rb
parent3e706c2025ecc5523e81ad649639ef2ff75e7bac (diff)
parentb80bd744ad873f6fc43018bc4bfb90677de167bd (diff)
Merge branch 'develop'
Diffstat (limited to 'app/controllers/tenants_controller.rb')
-rw-r--r--app/controllers/tenants_controller.rb91
1 files changed, 91 insertions, 0 deletions
diff --git a/app/controllers/tenants_controller.rb b/app/controllers/tenants_controller.rb
new file mode 100644
index 0000000..724d179
--- /dev/null
+++ b/app/controllers/tenants_controller.rb
@@ -0,0 +1,91 @@
+class TenantsController < ApplicationController
+ load_and_authorize_resource :tenant
+
+ def index
+ end
+
+ def show
+ end
+
+ def 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
+ 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
+ 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 @tenant, :notice => t('tenants.controller.successfuly_created',
+ :resource => @tenant
+ )
+ end
+ else
+ render :new
+ end
+ end
+
+ def edit
+ end
+
+ def update
+ if @tenant.update_attributes(params[:tenant])
+ redirect_to @tenant, :notice => t('tenants.controller.successfuly_updated')
+ else
+ render :edit
+ end
+ end
+
+ def destroy
+ @tenant.destroy
+ redirect_to tenants_url, :notice => t('tenants.controller.successfuly_destroyed')
+ end
+
+end