From 966b8733a82f07f825ce07baff0d37e2a5863960 Mon Sep 17 00:00:00 2001 From: Gemeinschaft Service Account Date: Sun, 24 Feb 2013 06:02:29 -0500 Subject: add default groups --- app/models/sip_account.rb | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'app/models/sip_account.rb') diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index 7df8e3b..2b8e95f 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -33,6 +33,9 @@ class SipAccount < ActiveRecord::Base belongs_to :language, :foreign_key => 'language_code', :primary_key => 'code' + has_many :group_memberships, :as => :item, :dependent => :destroy, :uniq => true + has_many :groups, :through => :group_memberships + # Delegations: # delegate :host, :to => :sip_domain, :allow_nil => true @@ -67,6 +70,7 @@ class SipAccount < ActiveRecord::Base validates_uniqueness_of :uuid after_create { self.create_on_other_gs_nodes('sip_accountable', self.sip_accountable.try(:uuid)) } + after_create :create_default_group_memberships after_destroy :destroy_on_other_gs_nodes after_update { self.update_on_other_gs_nodes('sip_accountable', self.sip_accountable.try(:uuid)) } @@ -146,7 +150,7 @@ class SipAccount < ActiveRecord::Base true ); end - + private @@ -220,4 +224,29 @@ class SipAccount < ActiveRecord::Base voicemail_setting.purge = false voicemail_setting.save end + + def create_default_group_memberships + default_groups = Hash.new() + templates = GsParameter.get('SipAccount', 'group', 'default') + if templates.class == Array + templates.each do |group_name| + default_groups[group_name] = true + end + end + + templates = GsParameter.get("SipAccount.#{self.sip_accountable_type}", 'group', 'default') + if templates.class == Array + templates.each do |group_name| + default_groups[group_name] = true + end + end + + default_groups.each do |group_name, value| + group = Group.where(:name => group_name).first + if group + self.group_memberships.create(:group_id => group.id) + end + end + end + end -- cgit v1.2.3 From 5dcdeb1c1f8c53fd80a0443d61a289e583091416 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 25 Feb 2013 02:51:46 -0500 Subject: logout if node ip and homebase ip differ on multi node setups only --- app/models/sip_account.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models/sip_account.rb') diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index 2b8e95f..420e395 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -206,7 +206,7 @@ class SipAccount < ActiveRecord::Base # log out phone if sip_account is not on this node def log_out_phone_if_not_local - if self.gs_node_id && ! GsNode.where(:ip_address => GsParameter.get('HOMEBASE_IP_ADDRESS'), :id => self.gs_node_id).first + if self.gs_node_id && GsNode.count > 1 && ! GsNode.where(:ip_address => GsParameter.get('HOMEBASE_IP_ADDRESS'), :id => self.gs_node_id).first self.phones.each do |phone| phone.user_logout; end -- cgit v1.2.3 From 0442cd19bc9383669b506185356227361a16e442 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 25 Feb 2013 09:29:40 -0500 Subject: call_forwards - polymorphism added --- app/models/sip_account.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'app/models/sip_account.rb') diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index 420e395..a39982b 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -16,7 +16,7 @@ class SipAccount < ActiveRecord::Base has_many :phones, :through => :phone_sip_accounts has_many :phone_numbers, :as => :phone_numberable, :dependent => :destroy - has_many :call_forwards, :through => :phone_numbers + has_many :call_forwards, :as => :call_forwardable, :dependent => :destroy belongs_to :tenant belongs_to :sip_domain @@ -96,8 +96,8 @@ class SipAccount < ActiveRecord::Base if call_forwarding_master.active call_forwarding_master.active = false else - if call_forwarding_service = 'assistant' && call_forwarding_master.call_forwardable_type == 'HuntGroup' && call_forwarding_master.call_forwardable - if call_forwarding_master.call_forwardable.hunt_group_members.where(:active => true).count > 0 + if call_forwarding_service = 'assistant' && call_forwarding_master.destinationable_type == 'HuntGroup' && call_forwarding_master.destinationable + if call_forwarding_master.destinationable.hunt_group_members.where(:active => true).count > 0 call_forwarding_master.active = true else call_forwarding_master.active = false @@ -109,7 +109,7 @@ class SipAccount < ActiveRecord::Base call_forwarding = phone_number.call_forwards.where(:call_forward_case_id => service_id).order(:active).all(:conditions => 'source IS NULL OR source = ""').first if ! call_forwarding call_forwarding = CallForward.new() - call_forwarding.phone_number_id = phone_number.id + call_forwarding.call_forwardable = phone_number end if to_voicemail == nil -- cgit v1.2.3 From fd07b7b85d2d40d7d2999c2899cc890eda2095fd Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 25 Feb 2013 11:41:55 -0500 Subject: more polymorphic objects --- app/models/sip_account.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app/models/sip_account.rb') diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index a39982b..034af7c 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -36,6 +36,8 @@ class SipAccount < ActiveRecord::Base has_many :group_memberships, :as => :item, :dependent => :destroy, :uniq => true has_many :groups, :through => :group_memberships + has_many :ringtones, :as => :ringtoneable, :dependent => :destroy + # Delegations: # delegate :host, :to => :sip_domain, :allow_nil => true -- cgit v1.2.3 From ed0117210837dd1d0d2dbf403799b70225caf0cd Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 27 Feb 2013 06:04:50 -0500 Subject: calls views added --- app/models/sip_account.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app/models/sip_account.rb') diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index 034af7c..2040b41 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -38,6 +38,8 @@ class SipAccount < ActiveRecord::Base has_many :ringtones, :as => :ringtoneable, :dependent => :destroy + has_many :calls, :finder_sql => lambda { |s| "SELECT DISTINCT detailed_calls.* FROM detailed_calls WHERE presence_id LIKE '#{self.auth_name}@%'" } + # Delegations: # delegate :host, :to => :sip_domain, :allow_nil => true -- cgit v1.2.3