summaryrefslogtreecommitdiff
path: root/app/controllers/gemeinschaft_setups_controller.rb
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-17 12:01:45 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-17 12:01:45 +0100
commitb80bd744ad873f6fc43018bc4bfb90677de167bd (patch)
tree072c4b0e33d442528555b82c415f5e7a1712b2b0 /app/controllers/gemeinschaft_setups_controller.rb
parent3e706c2025ecc5523e81ad649639ef2ff75e7bac (diff)
Start of GS5.
Diffstat (limited to 'app/controllers/gemeinschaft_setups_controller.rb')
-rw-r--r--app/controllers/gemeinschaft_setups_controller.rb61
1 files changed, 61 insertions, 0 deletions
diff --git a/app/controllers/gemeinschaft_setups_controller.rb b/app/controllers/gemeinschaft_setups_controller.rb
new file mode 100644
index 0000000..cafb8a3
--- /dev/null
+++ b/app/controllers/gemeinschaft_setups_controller.rb
@@ -0,0 +1,61 @@
+class GemeinschaftSetupsController < ApplicationController
+ load_and_authorize_resource :gemeinschaft_setup
+
+ skip_before_filter :go_to_setup_if_new_installation
+ # before_filter :redirect_if_not_a_fresh_installation
+
+ def new
+ @user = @gemeinschaft_setup.build_user(
+ :user_name => t('gemeinschaft_setups.initial_setup.admin_name'),
+ :male => true,
+ :email => 'admin@localhost',
+ )
+ @sip_domain = @gemeinschaft_setup.build_sip_domain(
+ :host => guess_local_host(),
+ :realm => guess_local_host(),
+ )
+ @gemeinschaft_setup.country = Country.find_by_name('Germany')
+ @gemeinschaft_setup.language = Language.find_by_name('Deutsch')
+ end
+
+ def create
+ if @gemeinschaft_setup.save
+ super_tenant = Tenant.create(
+ :name => SUPER_TENANT_NAME,
+ :country_id => @gemeinschaft_setup.country.id,
+ :language_id => @gemeinschaft_setup.language_id,
+ :description => t('gemeinschaft_setups.initial_setup.super_tenant_description'),
+ )
+
+ # Admin
+ user = @gemeinschaft_setup.user
+ super_tenant.tenant_memberships.create(:user_id => user.id)
+ user.update_attributes(:current_tenant_id => super_tenant.id)
+
+ # Create the Super-Tenant's group:
+ super_tenant_super_admin_group = super_tenant.user_groups.create(:name => t('gemeinschaft_setups.initial_setup.super_admin_group_name'))
+ super_tenant_super_admin_group.user_group_memberships.create(:user_id => user.id)
+
+ # Auto-Login:
+ session[:user_id] = user.id
+
+ # Redirect to the user
+ redirect_to new_tenant_url, :notice => t('gemeinschaft_setups.initial_setup.successful_setup')
+ else
+ render :new
+ end
+ end
+
+ private
+
+ def redirect_if_not_a_fresh_installation
+ if GemeinschaftSetup.all.count > 0
+ if current_user
+ redirect_to root_url , :alert => t('gemeinschaft_setups.initial_setup.access_denied_only_available_on_a_new_system')
+ else
+ redirect_to log_in_path , :alert => t('gemeinschaft_setups.initial_setup.access_denied_only_available_on_a_new_system')
+ end
+ end
+ end
+
+end