diff options
author | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2012-12-28 20:27:04 +0100 |
---|---|---|
committer | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2012-12-28 20:27:04 +0100 |
commit | f3c3e77eaa2b82567f02601b6f66177208674181 (patch) | |
tree | 1946390f7f697e80fcdab4164ad620d507b6a1fe /app/models | |
parent | 3e76142566ad8f55a64a88fe5c19e7d0ec7c11c0 (diff) | |
parent | 8d20201910b1915cffa495e6474d50f9c8e8331d (diff) |
Merge branch 'develop'5.0.1
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/phone.rb | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/app/models/phone.rb b/app/models/phone.rb index 89371eb..1f3c497 100644 --- a/app/models/phone.rb +++ b/app/models/phone.rb @@ -4,7 +4,7 @@ class Phone < ActiveRecord::Base attr_accessible :mac_address, :ip_address, :http_user, :http_password, :phone_model_id, :hot_deskable, :nightly_reboot, - :provisioning_key, :provisioning_key_active + :provisioning_key, :provisioning_key_active, :fallback_sip_account_id, :tenant # Associations # @@ -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 @@ -29,6 +32,8 @@ class Phone < ActiveRecord::Base validates_presence_of :phone_model validates_presence_of :phoneable + + validates_uniqueness_of :fallback_sip_account_id, :allow_nil => true before_save :save_last_ip_address before_save :destroy_phones_sip_accounts_if_phoneable_changed @@ -138,6 +143,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 +170,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) |