summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorspag <spag@golwen.net>2012-12-23 16:04:05 +0100
committerspag <spag@golwen.net>2012-12-23 16:04:05 +0100
commit55a0d5ce38f99226174f358279c02178eacd75d7 (patch)
tree8ad5fe87d51760bf8fa76bd60337c25ff16726f5 /app
parentf425280a6312638f364f6ae8d915a30d78a8dce4 (diff)
login/logout methods
Diffstat (limited to 'app')
-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.rb5
-rw-r--r--app/models/phone.rb27
4 files changed, 33 insertions, 36 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..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')
diff --git a/app/models/phone.rb b/app/models/phone.rb
index 89371eb..bd6e3f6 100644
--- a/app/models/phone.rb
+++ b/app/models/phone.rb
@@ -14,6 +14,9 @@ class Phone < ActiveRecord::Base
has_many :phone_sip_accounts, :dependent => :destroy, :uniq => true, :order => :position
has_many :sip_accounts, :through => :phone_sip_accounts
+ belongs_to :tenant
+ belongs_to :fallback_sip_account, :class_name => "SipAccount"
+
# Validations
#
before_validation :sanitize_mac_address
@@ -138,6 +141,8 @@ class Phone < ActiveRecord::Base
end
end
+ PhoneSipAccount.where(:phone_id => self.id).destroy_all
+
self.phoneable = user
sip_accounts.each do |sip_account|
if ! self.sip_accounts.where(:id => sip_account.id).first
@@ -163,37 +168,21 @@ class Phone < ActiveRecord::Base
# OPTIMIZE i18n translations
def user_logout
- if ! self.hot_deskable or self.phoneable_type == 'Tenant'
+ if ! self.hot_deskable
errors.add(:hot_deskable, "Phone not hot-deskable")
return false
end
sip_account = self.sip_accounts.where(:sip_accountable_type => self.phoneable_type).first
- tenant_sip_account = self.sip_accounts.where(:sip_accountable_type => 'Tenant').first
- if tenant_sip_account
- tenant = tenant_sip_account.sip_accountable
- end
-
- sip_account_ids = Array.new()
- self.sip_accounts.where(:sip_accountable_type => 'User', :hotdeskable => true).each do |sip_account|
- sip_account_ids.push(sip_account.id)
- end
-
- if tenant
- self.phoneable = tenant
- @not_destroy_phones_sip_accounts = true
+ if self.tenant
+ self.phoneable = self.tenant
if ! self.save
errors.add(:phoneable, "Could not change owner")
return false
end
end
- if ! PhoneSipAccount.destroy_all(:sip_account_id => sip_account_ids)
- errors.add(:sip_accounts, "Could not delete sip_accounts")
- return false
- end
-
sleep(0.5)
if ! self.resync(true, sip_account)