summaryrefslogtreecommitdiff
path: root/app/models/phone.rb
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/models/phone.rb
parentf425280a6312638f364f6ae8d915a30d78a8dce4 (diff)
login/logout methods
Diffstat (limited to 'app/models/phone.rb')
-rw-r--r--app/models/phone.rb27
1 files changed, 8 insertions, 19 deletions
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)