From db9dbf03d88cfbd68ce99a242730b9e870339539 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Thu, 7 Mar 2013 13:15:35 +0100 Subject: Added Switchboard scaffold. --- app/models/call_route.rb | 2 +- app/models/switchboard.rb | 14 ++++++++++++++ app/models/user.rb | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 app/models/switchboard.rb (limited to 'app/models') diff --git a/app/models/call_route.rb b/app/models/call_route.rb index 8bc811a..6c54549 100644 --- a/app/models/call_route.rb +++ b/app/models/call_route.rb @@ -7,7 +7,7 @@ class CallRoute < ActiveRecord::Base has_many :route_elements, :dependent => :destroy, :order => :position validates :name, - :presence => true + :presence => true validates :routing_table, :presence => true, diff --git a/app/models/switchboard.rb b/app/models/switchboard.rb new file mode 100644 index 0000000..cb0c70f --- /dev/null +++ b/app/models/switchboard.rb @@ -0,0 +1,14 @@ +class Switchboard < ActiveRecord::Base + # https://github.com/rails/strong_parameters + include ActiveModel::ForbiddenAttributesProtection + + validates :name, + :presence => true, + :uniqueness => {:scope => :user_id} + + belongs_to :user, :touch => true + + def to_s + self.name.to_s + end +end diff --git a/app/models/user.rb b/app/models/user.rb index 913d75f..6091e32 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -94,6 +94,8 @@ class User < ActiveRecord::Base has_many :group_memberships, :as => :item, :dependent => :destroy, :uniq => true has_many :groups, :through => :group_memberships + has_many :switchboards, :dependent => :destroy + # Avatar like photo mount_uploader :image, ImageUploader -- cgit v1.2.3 From 3cf3b921ee398472f2663cc1210932429f7710d9 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 7 Mar 2013 07:18:46 -0500 Subject: target_group_ids_by_permission method added --- app/models/sip_account.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'app/models') diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index 81b9c1c..3340a76 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -155,12 +155,16 @@ class SipAccount < ActiveRecord::Base ); end - - def target_sip_accounts_by_permission(permission) + def target_group_ids_by_permission(permission) target_groups = Group.union(self.groups.collect{|g| g.permission_targets(permission)}) target_groups = target_groups + Group.union(self.sip_accountable.groups.collect{|g| g.permission_targets(permission)}) + + return target_groups + end + + def target_sip_accounts_by_permission(permission) sip_accounts = [] - GroupMembership.where(:group_id => target_groups).each do |group_membership| + GroupMembership.where(:group_id => target_group_ids_by_permission(permission)).each do |group_membership| if group_membership.item.class == User || group_membership.item.class == Tenant sip_accounts = sip_accounts + group_membership.item.sip_accounts elsif group_membership.item.class == SipAccount -- cgit v1.2.3 From 678baf479066ad6b517b3a97925a7e37bf5327e4 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 7 Mar 2013 07:38:44 -0500 Subject: softkey form fixed --- app/models/softkey.rb | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'app/models') diff --git a/app/models/softkey.rb b/app/models/softkey.rb index 6063017..7f77a25 100644 --- a/app/models/softkey.rb +++ b/app/models/softkey.rb @@ -1,17 +1,17 @@ class Softkey < ActiveRecord::Base - attr_accessible :softkey_function_id, :number, :label, :uuid, :softkeyable_type, :softkeyable_id + attr_accessible :softkey_function_id, :number, :label, :uuid, :softkeyable_type, :softkeyable_id, :call_forward, :blf belongs_to :sip_account belongs_to :softkey_function belongs_to :softkeyable, :polymorphic => true - validates_presence_of :softkeyable_id, :if => Proc.new{ |softkey| self.softkey_function_id != nil && - self.softkey_function_id == SoftkeyFunction.find_by_name('call_forwarding').try(:id) } - # These functions need a number to act. # validates_presence_of :number, :if => Proc.new{ |softkey| self.softkey_function_id != nil && - ['blf','speed_dial','dtmf','conference'].include?(softkey.softkey_function.name) } + ['blf', 'speed_dial','dtmf','conference'].include?(softkey.softkey_function.name) } + + validates_presence_of :softkeyable_id, :if => Proc.new{ |softkey| self.softkey_function_id != nil && + ['call_forwarding'].include?(softkey.softkey_function.name) } validates_presence_of :uuid validates_uniqueness_of :uuid @@ -43,7 +43,16 @@ class Softkey < ActiveRecord::Base end def possible_blf_sip_accounts - self.sip_account.target_sip_accounts_by_permission('presence') + self.sip_account.target_sip_accounts_by_permission(:presence) + end + + def possible_pickup_groups + Group.where(:id => self.sip_account.target_group_ids_by_permission(:presence)) + end + + def possible_blf + blf = possible_pickup_groups.collect{ |g| ["#{g.class.name}: #{g.to_s}", "#{g.id}:#{g.class.name}"] } + blf + possible_blf_sip_accounts.collect{ |g| ["#{g.class.name}: #{g.to_s}", "#{g.id}:#{g.class.name}"] } end def to_s @@ -73,6 +82,7 @@ class Softkey < ActiveRecord::Base return self.position.to_i < Softkey.where(:sip_account_id => self.sip_account_id ).order(:position).last.position.to_i end + private # Make sure that no number is set when there is no need for one. # And make sure that there is no CallForward connected when not needed. -- cgit v1.2.3 From 800cf2f11ab5d7f03a52d5ca35e893654ef520ab Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 7 Mar 2013 15:22:06 -0500 Subject: call forwards view added --- app/models/hunt_group.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/hunt_group.rb b/app/models/hunt_group.rb index 7338606..93279ae 100644 --- a/app/models/hunt_group.rb +++ b/app/models/hunt_group.rb @@ -2,7 +2,8 @@ class HuntGroup < ActiveRecord::Base attr_accessible :name, :strategy, :seconds_between_jumps, :phone_numbers_attributes belongs_to :tenant, :touch => true - has_many :call_forwards, :as => :destinationable, :dependent => :destroy + has_many :destrination_call_forwards, :as => :destinationable, :dependent => :destroy + has_many :call_forwards, :as => :call_forwardable, :dependent => :destroy validates_uniqueness_of :name, :scope => :tenant_id, :allow_nil => true, :allow_blank => true -- cgit v1.2.3 From 2abc9cfb22e55b709a21b041e04a8221f605e9d7 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 7 Mar 2013 15:57:02 -0500 Subject: call forwards view added --- app/models/automatic_call_distributor.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app/models') diff --git a/app/models/automatic_call_distributor.rb b/app/models/automatic_call_distributor.rb index 5807757..b9d7c51 100644 --- a/app/models/automatic_call_distributor.rb +++ b/app/models/automatic_call_distributor.rb @@ -5,6 +5,8 @@ class AutomaticCallDistributor < ActiveRecord::Base has_many :acd_agents, :dependent => :destroy has_many :phone_numbers, :as => :phone_numberable, :dependent => :destroy + has_many :call_forwards, :as => :call_forwardable, :dependent => :destroy + accepts_nested_attributes_for :phone_numbers, :reject_if => lambda { |phone_number| phone_number[:number].blank? }, :allow_destroy => true -- cgit v1.2.3 From 4d7d5ad238990582d6c90a25272f2141ea9a3b28 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Fri, 8 Mar 2013 05:50:02 -0500 Subject: toggle action added to acd_agents --- app/models/ability.rb | 5 +++++ app/models/acd_agent.rb | 9 +++++++++ app/models/sip_account.rb | 2 ++ 3 files changed, 16 insertions(+) (limited to 'app/models') diff --git a/app/models/ability.rb b/app/models/ability.rb index 3cd1d4d..fe67547 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -170,6 +170,11 @@ class Ability can :manage, Ringtone, :ringtoneable_type => 'SipAccount', :ringtoneable_id => user.sip_account_ids can :create, Ringtone + # User can read and toggle status of ACD agents + # + can :read, AcdAgent, :destination_type => 'SipAccount', :destination_id => user.sip_account_ids + can :toggle, AcdAgent, :destination_type => 'SipAccount', :destination_id => user.sip_account_ids + # SoftkeyFunctions # can :read, SoftkeyFunction diff --git a/app/models/acd_agent.rb b/app/models/acd_agent.rb index 4be4700..61899f8 100644 --- a/app/models/acd_agent.rb +++ b/app/models/acd_agent.rb @@ -20,6 +20,15 @@ class AcdAgent < ActiveRecord::Base self.name || I18n.t('acd_agents.name') + ' ID ' + self.id.to_s end + def toggle_status + if self.status == 'active' + self.status = 'inactive' + else + self.status = 'active' + end + return self.save + end + private def set_presence dialplan_function = nil diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index 1ff3c9a..a5b8bad 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -41,6 +41,8 @@ class SipAccount < ActiveRecord::Base has_many :call_legs, :class_name => 'Call' has_many :b_call_legs, :class_name => 'Call', :foreign_key => 'b_sip_account_id' + has_many :acd_agents, :as => :destination, :dependent => :destroy + # Delegations: # delegate :host, :to => :sip_domain, :allow_nil => true -- cgit v1.2.3 From 6374c0b3e38dfc74eb1b4a5a1fcc5229eacdcaf2 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Fri, 8 Mar 2013 12:09:17 +0100 Subject: Added SwitchboardEntry scaffold. switchboard has_many switchboard_entries --- app/models/sip_account.rb | 2 ++ app/models/switchboard.rb | 2 ++ app/models/switchboard_entry.rb | 30 ++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 app/models/switchboard_entry.rb (limited to 'app/models') diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index cdb609d..74a2562 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -41,6 +41,8 @@ class SipAccount < ActiveRecord::Base has_many :call_legs, :class_name => 'Call' has_many :b_call_legs, :class_name => 'Call', :foreign_key => 'b_sip_account_id' + has_many :switchboard_entries, :dependent => :destroy + # Delegations: # delegate :host, :to => :sip_domain, :allow_nil => true diff --git a/app/models/switchboard.rb b/app/models/switchboard.rb index cb0c70f..74e2767 100644 --- a/app/models/switchboard.rb +++ b/app/models/switchboard.rb @@ -7,6 +7,8 @@ class Switchboard < ActiveRecord::Base :uniqueness => {:scope => :user_id} belongs_to :user, :touch => true + has_many :switchboard_entries, :dependent => :destroy + has_many :sip_accounts, :through => :switchboard_entries def to_s self.name.to_s diff --git a/app/models/switchboard_entry.rb b/app/models/switchboard_entry.rb new file mode 100644 index 0000000..d1e9a0c --- /dev/null +++ b/app/models/switchboard_entry.rb @@ -0,0 +1,30 @@ +class SwitchboardEntry < ActiveRecord::Base + # https://github.com/rails/strong_parameters + include ActiveModel::ForbiddenAttributesProtection + + belongs_to :switchboard, :touch => true + belongs_to :sip_account, :touch => true + + validates :switchboard, + :presence => true + + validates :sip_account, + :presence => true + + validates :name, + :uniqueness => {:scope => :switchboard_id}, + :allow_blank => true, + :allow_nil => true + + acts_as_list :scope => [ :switchboard_id ] + + default_scope order(:position) + + def to_s + if self.name.blank? && !self.sip_account.to_s.blank? + self.sip_account.to_s + else + self.name.to_s + end + end +end -- cgit v1.2.3 From bc450bb73fea9e8eb363f89e806e4f6084cf0511 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Sat, 9 Mar 2013 03:01:56 -0500 Subject: perimeter control method added --- app/models/intruder.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'app/models') diff --git a/app/models/intruder.rb b/app/models/intruder.rb index 9a1c39a..bdfa753 100644 --- a/app/models/intruder.rb +++ b/app/models/intruder.rb @@ -50,6 +50,17 @@ class Intruder < ActiveRecord::Base } end + def self.control(action, attributes={}) + require 'freeswitch_event' + event = FreeswitchEvent.new('CUSTOM') + event.add_header('Event-Subclass', 'perimeter::control') + event.add_header('action', action) + attributes.each do |name, value| + event.add_header(name, value) + end + return event.fire() + end + private def set_key_if_empty if self.key.blank? -- cgit v1.2.3 From cf506e96cfdd2f399934251f79c6f681503b7d5f Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Sat, 9 Mar 2013 03:56:10 -0500 Subject: perimeter_db_rescan class, instance methods added --- app/models/intruder.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/intruder.rb b/app/models/intruder.rb index bdfa753..97120a7 100644 --- a/app/models/intruder.rb +++ b/app/models/intruder.rb @@ -50,13 +50,23 @@ class Intruder < ActiveRecord::Base } end - def self.control(action, attributes={}) + def perimeter_db_rescan + Intruder.perimeter_control(:db_rescan, :key => self.key) + end + + def self.perimeter_db_rescan(key=nil) + Intruder.perimeter_control(:db_rescan, :key => key) + end + + def self.perimeter_control(action, attributes={}) require 'freeswitch_event' event = FreeswitchEvent.new('CUSTOM') event.add_header('Event-Subclass', 'perimeter::control') event.add_header('action', action) attributes.each do |name, value| - event.add_header(name, value) + if !name.blank? && value then + event.add_header(name, value) + end end return event.fire() end -- cgit v1.2.3 From 4d11efbd7b0dc1c7e89210a56ea5ca77fe801c7e Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Sat, 9 Mar 2013 04:12:52 -0500 Subject: send perimeter event after_save --- app/models/intruder.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'app/models') diff --git a/app/models/intruder.rb b/app/models/intruder.rb index 97120a7..9c01634 100644 --- a/app/models/intruder.rb +++ b/app/models/intruder.rb @@ -119,6 +119,7 @@ class Intruder < ActiveRecord::Base write_firewall_list restart_firewall end + self.perimeter_db_rescan end end @@ -129,6 +130,7 @@ class Intruder < ActiveRecord::Base restart_firewall end end + self.perimeter_db_rescan end def check_if_delete_relevant @@ -138,5 +140,6 @@ class Intruder < ActiveRecord::Base restart_firewall end end + self.perimeter_db_rescan end end -- cgit v1.2.3 From 595a48a91f8549b20109942e0b80df4f891d5999 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Sat, 9 Mar 2013 05:45:39 -0500 Subject: status method added --- app/models/sip_account.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'app/models') diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index a5b8bad..bb45a4c 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -184,6 +184,33 @@ class SipAccount < ActiveRecord::Base return sip_accounts end + def status + states = Array.new + + SipAccount.last.call_legs.each do |call_leg| + states << { + :status => call_leg.callstate, + :caller => true, + :endpoint_name => call_leg.callee_name, + :endpoint_number => call_leg.destination, + :endpoint_sip_account_id => call_leg.b_sip_account_id, + :start_stamp => call_leg.start_stamp, + } + end + + SipAccount.last.b_call_legs.each do |call_leg| + states << { + :status => call_leg.callstate, + :caller => false, + :endpoint_name => call_leg.caller_id_name, + :endpoint_number => call_leg.caller_id_number, + :endpoint_sip_account_id => call_leg.sip_account_id, + :start_stamp => call_leg.start_stamp, + } + end + + return states + end private -- cgit v1.2.3 From 21d0843117c0962bd962fc50fccaf276a5b3067f Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Sun, 10 Mar 2013 08:43:23 +0100 Subject: Misc --- app/models/switchboard_entry.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app/models') diff --git a/app/models/switchboard_entry.rb b/app/models/switchboard_entry.rb index d1e9a0c..76d002f 100644 --- a/app/models/switchboard_entry.rb +++ b/app/models/switchboard_entry.rb @@ -12,6 +12,7 @@ class SwitchboardEntry < ActiveRecord::Base :presence => true validates :name, + :length => { :maximum => 10 }, :uniqueness => {:scope => :switchboard_id}, :allow_blank => true, :allow_nil => true -- cgit v1.2.3 From 04730ba7acf55ed5310352eabf3876bf5b8d1f87 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Sun, 10 Mar 2013 09:52:08 +0100 Subject: Set the Ability for Switchboard and SwitchboardEntry. --- app/models/ability.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'app/models') diff --git a/app/models/ability.rb b/app/models/ability.rb index fe67547..2dd96b8 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -183,6 +183,11 @@ class Ability # can :manage, VoicemailMessage can :manage, VoicemailSetting + + # Switchboard + # + can :read, Switchboard, :id => user.switchboard_ids + can :read, SwitchboardEntry, :switchboard_id => user.switchboard_ids end end else -- cgit v1.2.3 From c563859fa60defd2b40f17a0b7cf1c4912f72792 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Sun, 10 Mar 2013 12:06:06 +0100 Subject: added non_e164_phone_numbers method --- app/models/sip_account.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'app/models') diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index 930069d..cea5f0e 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -213,6 +213,11 @@ class SipAccount < ActiveRecord::Base return states end + def non_e164_phone_numbers + array_of_phone_numbers_as_strings = self.phone_numbers.map{ |phone_number| phone_number.number.to_s }.sort + self.phone_numbers.where(:number => array_of_phone_numbers_as_strings.select { |phone_number| phone_number[0] != '+' }) + end + private def save_value_of_to_s -- cgit v1.2.3 From 52079a2434c7bf33d8f59ebf29614bf681777d3d Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 11 Mar 2013 03:18:24 -0400 Subject: inbound_username, inbound_password settings added --- app/models/gateway_setting.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/gateway_setting.rb b/app/models/gateway_setting.rb index 381dde5..f353dee 100644 --- a/app/models/gateway_setting.rb +++ b/app/models/gateway_setting.rb @@ -5,11 +5,13 @@ class GatewaySetting < ActiveRecord::Base 'domain' => 'String', 'username' => 'String', 'password' => 'String', - 'contact' => 'String', 'register' => 'Boolean', 'auth_source' => 'String', 'auth_pattern' => 'String', + 'inbound_username' => 'String', + 'inbound_password' => 'String', 'number_source' => 'String', + 'contact' => 'String', 'profile' => 'String', }, 'xmpp' => { -- cgit v1.2.3 From 576471586e781ad1f7535e5931b1e41e25fad71b Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 11 Mar 2013 05:57:32 -0400 Subject: dial_string setting added --- app/models/gateway_setting.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app/models') diff --git a/app/models/gateway_setting.rb b/app/models/gateway_setting.rb index f353dee..b412bc6 100644 --- a/app/models/gateway_setting.rb +++ b/app/models/gateway_setting.rb @@ -12,6 +12,7 @@ class GatewaySetting < ActiveRecord::Base 'inbound_password' => 'String', 'number_source' => 'String', 'contact' => 'String', + 'dial_string' => 'String', 'profile' => 'String', }, 'xmpp' => { -- cgit v1.2.3 From f9ab4cb6a477159e40bd7f48d9ed32ca077a8e34 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 12 Mar 2013 04:16:49 -0400 Subject: remove non decimal characters from pin --- app/models/conference.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'app/models') diff --git a/app/models/conference.rb b/app/models/conference.rb index aee75d5..6c89d60 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -7,6 +7,12 @@ class Conference < ActiveRecord::Base has_many :conference_invitees, :dependent => :destroy has_many :phone_numbers, :as => :phone_numberable, :dependent => :destroy + before_validation { + if !self.pin.blank? + self.pin = self.pin.to_s.gsub(/[^0-9]/, '') + end + } + validates_presence_of :conferenceable_type, :conferenceable_id validates_presence_of :conferenceable validates_presence_of :name @@ -21,15 +27,12 @@ class Conference < ActiveRecord::Base validates_inclusion_of :open_for_anybody, :in => [true, false] - validates_numericality_of :pin, :only_integer => true, - :greater_than => 0, - :allow_nil => true, - :allow_blank => true validates_length_of :pin, :minimum => (GsParameter.get('MINIMUM_PIN_LENGTH').nil? ? 4 : GsParameter.get('MINIMUM_PIN_LENGTH')), :allow_nil => true, :allow_blank => true validate :start_and_end_dates_must_make_sense, :if => Proc.new { |conference| !conference.start.blank? && !conference.end.blank? } + before_save :send_pin_email_when_pin_has_changed @@ -50,7 +53,6 @@ class Conference < ActiveRecord::Base private def start_and_end_dates_must_make_sense - errors.add(:start, 'must be in the future') if self.start < Time.now - 10.minutes errors.add(:end, 'must be later than the start') if self.end < self.start end -- cgit v1.2.3 From 1e2506e77d04d02b15f34cbdd83109ad579cc89e Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 12 Mar 2013 04:17:06 -0400 Subject: remove non decimal characters from pin --- app/models/conference_invitee.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'app/models') diff --git a/app/models/conference_invitee.rb b/app/models/conference_invitee.rb index d6e3bac..6a1349e 100644 --- a/app/models/conference_invitee.rb +++ b/app/models/conference_invitee.rb @@ -1,21 +1,23 @@ class ConferenceInvitee < ActiveRecord::Base attr_accessible :pin, :speaker, :moderator, :phone_number, :phone_number_attributes - + belongs_to :conference belongs_to :phone_book_entry has_one :phone_number, :as => :phone_numberable, :dependent => :destroy accepts_nested_attributes_for :phone_number + before_validation { + if !self.pin.blank? + self.pin = self.pin.to_s.gsub(/[^0-9]/, '') + end + } + validates_presence_of :conference_id validates_presence_of :conference validates_presence_of :phone_number - validates_numericality_of :pin, :only_integer => true, - :greater_than => 0, - :allow_nil => true, - :allow_blank => true - validates_length_of :pin, :minimum => (GsParameter.get('MINIMUM_PIN_LENGTH').nil? ? 4 : GsParameter.get('MINIMUM_PIN_LENGTH')), - :allow_nil => true, - :allow_blank => true + validates_length_of :pin, :minimum => (GsParameter.get('MINIMUM_PIN_LENGTH').nil? ? 4 : GsParameter.get('MINIMUM_PIN_LENGTH')), + :allow_nil => true, + :allow_blank => true validates_inclusion_of :speaker, :in => [true, false] validates_inclusion_of :moderator, :in => [true, false] -- cgit v1.2.3 From 1a9b4ef6d9ebbe77ba113d960d85c7097ae3368c Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 13 Mar 2013 06:49:40 -0400 Subject: transfer_blind method added --- app/models/call.rb | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/call.rb b/app/models/call.rb index 8f657fa..61d10ce 100644 --- a/app/models/call.rb +++ b/app/models/call.rb @@ -39,6 +39,30 @@ class Call < ActiveRecord::Base return FreeswitchAPI.execute('uuid_kill', self.uuid, true); end + def transfer_blind(destination, call_leg=:aleg, auth_account=nil) + if destination.blank? + return nil + end + + if call_leg == :bleg + channel_uuid = self.b_uuid + else + channel_uuid = self.uuid + end + + if channel_uuid.blank? + return nil + end + + if auth_account + FreeswitchAPI.api('uuid_setvar', channel_uuid, 'gs_auth_account_type', auth_account.class.name) + FreeswitchAPI.api('uuid_setvar', channel_uuid, 'gs_auth_account_uuid', auth_account.uuid) + end + + require 'freeswitch_event' + return FreeswitchAPI.api_result(FreeswitchAPI.api('uuid_transfer', channel_uuid, destination)) + end + def get_variable_from_uuid(channel_uuid, variable_name) if channel_uuid.blank? return nil @@ -61,5 +85,5 @@ class Call < ActiveRecord::Base def get_variable_bleg(variable_name) return get_variable_from_uuid(self.b_uuid, variable_name); end - + end -- cgit v1.2.3 From 3e1092b532d34141d77f1e9176831e2bf82845ac Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 13 Mar 2013 10:03:01 -0400 Subject: load freeswitch_event module before use --- app/models/call.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/call.rb b/app/models/call.rb index 61d10ce..a8a0d7f 100644 --- a/app/models/call.rb +++ b/app/models/call.rb @@ -54,12 +54,12 @@ class Call < ActiveRecord::Base return nil end + require 'freeswitch_event' if auth_account FreeswitchAPI.api('uuid_setvar', channel_uuid, 'gs_auth_account_type', auth_account.class.name) FreeswitchAPI.api('uuid_setvar', channel_uuid, 'gs_auth_account_uuid', auth_account.uuid) end - require 'freeswitch_event' return FreeswitchAPI.api_result(FreeswitchAPI.api('uuid_transfer', channel_uuid, destination)) end @@ -85,5 +85,5 @@ class Call < ActiveRecord::Base def get_variable_bleg(variable_name) return get_variable_from_uuid(self.b_uuid, variable_name); end - + end -- cgit v1.2.3 From d2cfd8203e0108db3b49d10a7ca3990f49667a9e Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 13 Mar 2013 10:03:39 -0400 Subject: list_members method added --- app/models/conference.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/conference.rb b/app/models/conference.rb index 6c89d60..880b958 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -49,9 +49,27 @@ class Conference < ActiveRecord::Base def to_s name end + + def list_conference + require 'freeswitch_event' + result = FreeswitchAPI.api_result(FreeswitchAPI.api('conference', "conference#{self.id}", 'xml_list')) + if result =~ /^\<\?xml/ + return Hash.from_xml(result) + end + return nil + end + + def list_members + data = self.list_conference + if data.blank? + return {} + end + + return data.fetch('conferences',{}).fetch('conference',{}).fetch('members',{}).fetch('member',{}) + end + private - def start_and_end_dates_must_make_sense errors.add(:end, 'must be later than the start') if self.end < self.start end -- cgit v1.2.3 From c9dde701750d237a9a07c31ecf402940af2d7d18 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Wed, 13 Mar 2013 16:35:23 +0100 Subject: Bugfix. closes #239 --- app/models/user.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'app/models') diff --git a/app/models/user.rb b/app/models/user.rb index 6091e32..b74fc06 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -74,8 +74,6 @@ class User < ActiveRecord::Base has_many :fax_accounts, :as => :fax_accountable, :dependent => :destroy - has_many :system_messages, :dependent => :destroy - has_many :auto_destroy_access_authorization_phone_numbers, :class_name => 'PhoneNumber', :foreign_key => 'access_authorization_user_id', :dependent => :destroy belongs_to :current_tenant, :class_name => 'Tenant' -- cgit v1.2.3 From ff991ce3d6c999783b8a5d3cae7b8e4635406a83 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 13 Mar 2013 11:55:21 -0400 Subject: routing test method added --- app/models/call_route.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'app/models') diff --git a/app/models/call_route.rb b/app/models/call_route.rb index 6c54549..590d49b 100644 --- a/app/models/call_route.rb +++ b/app/models/call_route.rb @@ -253,4 +253,20 @@ class CallRoute < ActiveRecord::Base end end + + def self.test_route(table, caller) + arguments = ["'#{table}' table"] + caller.each do |key, value| + arguments << "'#{value}' '#{key}'" + end + + require 'freeswitch_event' + result = FreeswitchAPI.api_result(FreeswitchAPI.api('lua', 'test_route.lua', arguments.join(' '))) + if result.blank? then + return + end + + return JSON.parse(result) + end + end -- cgit v1.2.3 From 0840ee7eb193d838724de7227b19824abd5b2bf3 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 14 Mar 2013 03:47:54 -0400 Subject: gateway status methods --- app/models/gateway.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'app/models') diff --git a/app/models/gateway.rb b/app/models/gateway.rb index 2f17b57..bf391fb 100644 --- a/app/models/gateway.rb +++ b/app/models/gateway.rb @@ -27,7 +27,34 @@ class Gateway < ActiveRecord::Base "#{GATEWAY_PREFIX}#{self.id}" end + def status + if self.technology == 'sip' then + return status_sip + end + end + + def inbound_register + username = self.gateway_settings.where(:name => 'inbound_username').first.try(:value) + if username.blank? + return + end + + return SipRegistration.where(:sip_user => username).first + end + private + def status_sip + require 'freeswitch_event' + result = FreeswitchAPI.api_result(FreeswitchAPI.api('sofia', 'xmlstatus', 'gateway', "gateway#{self.id}")) + if result =~ /^\<\?xml/ + data = Hash.from_xml(result) + if data + return data.fetch('gateway', nil) + end + end + return nil + end + def downcase_technology self.technology = self.technology.downcase if !self.technology.blank? end -- cgit v1.2.3 From 910fcee54d7ce3460815d4535556d497a343ea99 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Fri, 15 Mar 2013 05:29:49 -0400 Subject: status fixed --- app/models/sip_account.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'app/models') diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index cea5f0e..50124e9 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -188,25 +188,30 @@ class SipAccount < ActiveRecord::Base def status states = Array.new - SipAccount.last.call_legs.each do |call_leg| + self.call_legs.each do |call_leg| states << { - :status => call_leg.callstate, + :status => call_leg.b_callstate || call_leg.callstate, + :status_channel => call_leg.callstate, :caller => true, :endpoint_name => call_leg.callee_name, :endpoint_number => call_leg.destination, :endpoint_sip_account_id => call_leg.b_sip_account_id, :start_stamp => call_leg.start_stamp, + :secure => call_leg.secure, } end - SipAccount.last.b_call_legs.each do |call_leg| + self.b_call_legs.each do |call_leg| + call_status = states << { - :status => call_leg.callstate, + :status => call_leg.b_callstate, + :status_channel => call_leg.b_callstate, :caller => false, :endpoint_name => call_leg.caller_id_name, :endpoint_number => call_leg.caller_id_number, :endpoint_sip_account_id => call_leg.sip_account_id, :start_stamp => call_leg.start_stamp, + :secure => call_leg.b_secure, } end -- cgit v1.2.3 From 0ed2894ca7371199788c202b61f53a3f73c4b03b Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Sun, 17 Mar 2013 12:44:33 +0100 Subject: Reduce the push load. --- app/models/sip_account.rb | 5 ----- 1 file changed, 5 deletions(-) (limited to 'app/models') diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index cea5f0e..930069d 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -213,11 +213,6 @@ class SipAccount < ActiveRecord::Base return states end - def non_e164_phone_numbers - array_of_phone_numbers_as_strings = self.phone_numbers.map{ |phone_number| phone_number.number.to_s }.sort - self.phone_numbers.where(:number => array_of_phone_numbers_as_strings.select { |phone_number| phone_number[0] != '+' }) - end - private def save_value_of_to_s -- cgit v1.2.3 From e6e893009b763ac8013088a9f8d041e5e43c0bd3 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 19 Mar 2013 01:57:37 -0400 Subject: retrieve conference data --- app/models/conference.rb | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'app/models') diff --git a/app/models/conference.rb b/app/models/conference.rb index 880b958..a9d6708 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -54,18 +54,35 @@ class Conference < ActiveRecord::Base require 'freeswitch_event' result = FreeswitchAPI.api_result(FreeswitchAPI.api('conference', "conference#{self.id}", 'xml_list')) if result =~ /^\<\?xml/ - return Hash.from_xml(result) + data = Hash.from_xml(result) + if data + return data.fetch('conferences',{}).fetch('conference',{}) + end end return nil end - def list_members - data = self.list_conference + def list_members(data=self.list_conference()) if data.blank? return {} end - return data.fetch('conferences',{}).fetch('conference',{}).fetch('members',{}).fetch('member',{}) + members = data.fetch('members',{}).fetch('member',{}) + if members.class != Array + members = [members] + end + + members.each_with_index do |member, index| + members[index][:call] = Call.where(:uuid => member['uuid']).first + if !members[index][:call] + members[index][:call] = Call.where(:b_uuid => member['uuid']).first + if members[index][:call] + members[index][:call_bleg] = true; + end + end + end + + return members; end -- cgit v1.2.3 From 706ffe50d3bb6270682783acc1e7817e8f7cf0f6 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 21 Mar 2013 11:53:13 +0100 Subject: phone_book_entry needs not to be unique --- app/models/conference_invitee.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'app/models') diff --git a/app/models/conference_invitee.rb b/app/models/conference_invitee.rb index 6a1349e..5b99ca4 100644 --- a/app/models/conference_invitee.rb +++ b/app/models/conference_invitee.rb @@ -23,7 +23,6 @@ class ConferenceInvitee < ActiveRecord::Base validates_inclusion_of :moderator, :in => [true, false] validate :uniqueness_of_phone_number_in_the_parent_conference - validates_uniqueness_of :phone_book_entry_id, :scope => :conference_id, :allow_nil => true def to_s "ID #{self.id}" -- cgit v1.2.3 From 0f27f97cac5ac9283a2b2e403effa3b71afa673b Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 21 Mar 2013 12:46:19 +0100 Subject: whitespace --- app/models/softkey.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'app/models') diff --git a/app/models/softkey.rb b/app/models/softkey.rb index 7f77a25..27527f9 100644 --- a/app/models/softkey.rb +++ b/app/models/softkey.rb @@ -28,7 +28,6 @@ class Softkey < ActiveRecord::Base call_forwards = call_forwards + phone_number.call_forwards end - phone_numbers_ids = self.sip_account.phone_number_ids phone_numbers = PhoneNumber.where(:id => phone_numbers_ids).pluck(:number) -- cgit v1.2.3 From 844697e0398c128025df76810c6b091c2a3d4114 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 21 Mar 2013 12:46:39 +0100 Subject: to_s method --- app/models/ringtone.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/ringtone.rb b/app/models/ringtone.rb index 45ecd93..2b08c9f 100644 --- a/app/models/ringtone.rb +++ b/app/models/ringtone.rb @@ -24,6 +24,6 @@ class Ringtone < ActiveRecord::Base belongs_to :ringtoneable, :polymorphic => true def to_s - self.bellcore_id.to_s + CORE_RINGTONES_AVAILABLE.index(self.bellcore_id) end end -- cgit v1.2.3 From a9b2c7f508bfdf6d67389e39036d038b3c77f547 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Sat, 23 Mar 2013 04:21:48 +0100 Subject: "nice -n 19" for backup related background tasks --- app/models/backup_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/backup_job.rb b/app/models/backup_job.rb index 48dd27e..9cb4f53 100644 --- a/app/models/backup_job.rb +++ b/app/models/backup_job.rb @@ -37,7 +37,7 @@ class BackupJob < ActiveRecord::Base if tmp_backup_directory.blank? self.state = 'failed' else - system "cd #{backup_directory} && sudo /bin/tar czf #{backup_name_prefix}#{File.basename(tmp_backup_directory)}.tar.gz #{File.basename(tmp_backup_directory)}" + system "cd #{backup_directory} && nice -n 19 sudo /bin/tar czf #{backup_name_prefix}#{File.basename(tmp_backup_directory)}.tar.gz #{File.basename(tmp_backup_directory)}" require 'fileutils' FileUtils.rm_rf tmp_backup_directory file = File::Stat.new("#{backup_directory}/#{backup_name_prefix}#{File.basename(tmp_backup_directory)}.tar.gz") -- cgit v1.2.3