From 55a0d5ce38f99226174f358279c02178eacd75d7 Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 23 Dec 2012 16:04:05 +0100 Subject: login/logout methods --- app/controllers/config_siemens_controller.rb | 18 ++++++++++-------- app/controllers/config_snom_controller.rb | 19 +++++++++++-------- app/controllers/phones_controller.rb | 5 ++++- 3 files changed, 25 insertions(+), 17 deletions(-) (limited to 'app/controllers') 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 => "", + :text => "", ) 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 => "", + :text => "", ) 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..0b765e8 100644 --- a/app/controllers/phones_controller.rb +++ b/app/controllers/phones_controller.rb @@ -14,7 +14,6 @@ class PhonesController < ApplicationController def new @phone = @phoneable.phones.build() - # Use the last phone.phone_model as the default. # @phone.phone_model_id = Phone.last.try(:phone_model).try(:id) @@ -22,6 +21,10 @@ 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') -- cgit v1.2.3