summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/config_siemens_controller.rb18
-rw-r--r--app/controllers/config_snom_controller.rb19
-rw-r--r--app/controllers/phones_controller.rb13
3 files changed, 34 insertions, 16 deletions
diff --git a/app/controllers/config_siemens_controller.rb b/app/controllers/config_siemens_controller.rb
index f398b1a..c09dfcf 100644
--- a/app/controllers/config_siemens_controller.rb
+++ b/app/controllers/config_siemens_controller.rb
@@ -80,6 +80,7 @@ class ConfigSiemensController < ApplicationController
@phone.mac_address = mac_address
@phone.hot_deskable = true
@phone.phone_model = PhoneModel.where('name LIKE ?', "#{phone_type}").first
+ @phone.tenant = tenant
if ! @phone.save
render(
:status => 500,
@@ -128,16 +129,13 @@ class ConfigSiemensController < ApplicationController
return
end
- phone_sip_account = PhoneSipAccount.new()
- phone_sip_account.phone_id = @phone.id
- phone_sip_account.sip_account_id = @sip_account.id
-
- if ! phone_sip_account.save
+ @phone.fallback_sip_account = @sip_account
+ if ! @phone.save
render(
:status => 500,
:layout => false,
:content_type => 'text/plain',
- :text => "<!-- #{phone_sip_account.errors.messages.inspect} -->",
+ :text => "<!-- #{@phone.errors.messages.inspect} -->",
)
return
end
@@ -152,13 +150,17 @@ class ConfigSiemensController < ApplicationController
@sip_account = @phone.sip_accounts.where(:sip_accountable_type => @phone.phoneable_type,
:sip_accountable_id => @phone.phoneable_id).first
+ if !@sip_account
+ @sip_account = @phone.fallback_sip_account
+ end
+
+ tenant = @phone.tenant
+
if @phone.phoneable
if @phone.phoneable_type == 'Tenant'
- tenant = @phone.phoneable
language = tenant.language.code
elsif @phone.phoneable_type == 'User'
language = @phone.phoneable.language.code
- tenant = @phone.phoneable.current_tenant
end
end
diff --git a/app/controllers/config_snom_controller.rb b/app/controllers/config_snom_controller.rb
index 74a117d..4d12082 100644
--- a/app/controllers/config_snom_controller.rb
+++ b/app/controllers/config_snom_controller.rb
@@ -49,6 +49,7 @@ class ConfigSnomController < ApplicationController
@phone = tenant.phones.build
@phone.mac_address = @mac_address
@phone.hot_deskable = true
+ @phone.tenant = tenant
mac_address_to_model = {
'00041325' => 'Snom 300',
@@ -130,20 +131,16 @@ class ConfigSnomController < ApplicationController
return
end
- phone_sip_account = PhoneSipAccount.new()
- phone_sip_account.phone_id = @phone.id
- phone_sip_account.sip_account_id = @sip_account.id
-
- if ! phone_sip_account.save
+ @phone.fallback_sip_account = @sip_account
+ if ! @phone.save
render(
:status => 500,
:layout => false,
:content_type => 'text/plain',
- :text => "<!-- #{phone_sip_account.errors.messages.inspect} -->",
+ :text => "<!-- #{@phone.errors.messages.inspect} -->",
)
return
end
-
end
elsif ! params[:phone].blank? then
@phone = Phone.where({ :id => params[:phone].to_i }).first
@@ -238,9 +235,15 @@ class ConfigSnomController < ApplicationController
@softkeys = Array.new()
@sip_accounts = Array.new()
+ phone_sip_accounts = Array.new()
if send_sensitve
- @phone.sip_accounts.each do |sip_account|
+ if @phone.sip_accounts && @phone.sip_accounts.count > 0
+ phone_sip_accounts = @phone.sip_accounts
+ elsif @phone.fallback_sip_account
+ phone_sip_accounts.push( @phone.fallback_sip_account )
+ end
+ phone_sip_accounts.each do |sip_account|
if (sip_account.sip_accountable_type == @phone.phoneable_type) and (sip_account.sip_accountable_id == @phone.phoneable_id)
snom_sip_account = {
:id => sip_account.id,
diff --git a/app/controllers/phones_controller.rb b/app/controllers/phones_controller.rb
index d46bf86..f1dcd3e 100644
--- a/app/controllers/phones_controller.rb
+++ b/app/controllers/phones_controller.rb
@@ -13,6 +13,8 @@ class PhonesController < ApplicationController
end
def new
+ set_fallback_sip_accounts
+
@phone = @phoneable.phones.build()
# Use the last phone.phone_model as the default.
@@ -22,15 +24,21 @@ class PhonesController < ApplicationController
def create
@phone = @phoneable.phones.build(params[:phone])
+ if !@tenant
+ @tenant = @user.current_tenant
+ end
+ @phone.tenant = @tenant
if @phone.save
m = method( :"#{@phoneable.class.name.underscore}_phone_path" )
redirect_to m.( @phoneable, @phone ), :notice => t('phones.controller.successfuly_created')
else
+ set_fallback_sip_accounts
render :new
end
end
def edit
+ set_fallback_sip_accounts
end
def update
@@ -68,5 +76,10 @@ class PhonesController < ApplicationController
add_breadcrumb @phone, method( :"#{@phone.phoneable.class.name.underscore}_phone_path" ).(@phone.phoneable, @phone)
end
end
+
+ def set_fallback_sip_accounts
+ used_sip_account_ids = Phone.where(:fallback_sip_account_id => SipAccount.pluck(:id)).pluck(:fallback_sip_account_id)
+ @fallback_sip_accounts = SipAccount.where(:sip_accountable_type => 'Tenant').where(:hotdeskable => true) - SipAccount.where(:id => used_sip_account_ids)
+ end
end