summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/ability.rb4
-rw-r--r--app/models/call.rb46
-rw-r--r--app/models/call_forward.rb40
-rw-r--r--app/models/cdr.rb17
-rw-r--r--app/models/extension_module.rb58
-rw-r--r--app/models/freeswitch_cdr.rb4
-rw-r--r--app/models/gateway.rb10
-rw-r--r--app/models/gateway_header.rb25
-rw-r--r--app/models/gateway_setting.rb5
-rw-r--r--app/models/group_membership.rb9
-rw-r--r--app/models/hunt_group.rb2
-rw-r--r--app/models/phone.rb5
-rw-r--r--app/models/sip_account.rb13
-rw-r--r--app/models/switchboard.rb11
-rw-r--r--app/models/user.rb13
-rw-r--r--app/models/voicemail_account.rb8
16 files changed, 210 insertions, 60 deletions
diff --git a/app/models/ability.rb b/app/models/ability.rb
index 8718dc4..66f3c60 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -95,6 +95,10 @@ class Ability
#
cannot :manage, RestoreJob
+ # Admin can manage all switchboards.
+ #
+ can :manage, Switchboard
+
else
# Any user can do the following stuff.
#
diff --git a/app/models/call.rb b/app/models/call.rb
index 2bbd08b..6755a96 100644
--- a/app/models/call.rb
+++ b/app/models/call.rb
@@ -44,11 +44,7 @@ class Call < ActiveRecord::Base
return nil
end
- if call_leg == :bleg
- channel_uuid = self.b_uuid
- else
- channel_uuid = self.uuid
- end
+ channel_uuid = call_leg == :bleg ? self.b_uuid : channel_uuid = self.uuid
if channel_uuid.blank?
return nil
@@ -63,24 +59,28 @@ class Call < ActiveRecord::Base
return FreeswitchAPI.api_result(FreeswitchAPI.api('uuid_transfer', channel_uuid, destination))
end
+ def hold(call_leg=:aleg, action=:hold)
+ channel_uuid = call_leg == :bleg ? self.b_uuid : channel_uuid = self.uuid
+ hold_off = action == :retrieve ? 'off' : ''
- def self.bridge(call_uuid1, call_uuid2, hangup_uuids=[])
- if call_uuid1.blank? || call_uuid2.blank?
+ if channel_uuid.blank?
return nil
end
require 'freeswitch_event'
- result = FreeswitchAPI.api_result(FreeswitchAPI.api('uuid_bridge', call_uuid1, call_uuid2))
-
- if result
- hangup_uuids.each do |kill_uuid|
- FreeswitchAPI.execute('uuid_kill', kill_uuid, true)
- end
+ result = FreeswitchAPI.api_result(FreeswitchAPI.api('uuid_hold', hold_off, channel_uuid))
+ end
+
+ def park(call_leg=:aleg)
+ channel_uuid = call_leg == :bleg ? self.b_uuid : channel_uuid = self.uuid
+
+ if channel_uuid.blank?
+ return nil
end
- return result
+ require 'freeswitch_event'
+ result = FreeswitchAPI.api_result(FreeswitchAPI.api('uuid_park', channel_uuid))
end
-
def get_variable_from_uuid(channel_uuid, variable_name)
if channel_uuid.blank?
@@ -105,4 +105,20 @@ class Call < ActiveRecord::Base
return get_variable_from_uuid(self.b_uuid, variable_name);
end
+ def self.bridge(call_uuid1, call_uuid2, hangup_uuids=[])
+ if call_uuid1.blank? || call_uuid2.blank?
+ return nil
+ end
+
+ require 'freeswitch_event'
+ result = FreeswitchAPI.api_result(FreeswitchAPI.api('uuid_bridge', call_uuid1, call_uuid2))
+
+ if result
+ hangup_uuids.each do |kill_uuid|
+ FreeswitchAPI.execute('uuid_kill', kill_uuid, true)
+ end
+ end
+
+ return result
+ end
end
diff --git a/app/models/call_forward.rb b/app/models/call_forward.rb
index a4bfbb5..874a0de 100644
--- a/app/models/call_forward.rb
+++ b/app/models/call_forward.rb
@@ -7,7 +7,8 @@ class CallForward < ActiveRecord::Base
:hunt_group_id,
:call_forwardable_type, :call_forwardable_id,
:call_forwarding_destination, :position, :uuid,
- :destinationable_type, :destinationable_id
+ :destinationable_type, :destinationable_id,
+ :destination_phone_number, :destination_greeting
belongs_to :call_forwardable, :polymorphic => true
belongs_to :destinationable, :polymorphic => true
@@ -23,12 +24,6 @@ class CallForward < ActiveRecord::Base
:if => Proc.new { |cf| cf.to_voicemail == true }
belongs_to :call_forward_case
-
- validates_numericality_of :depth,
- :allow_nil => true,
- :only_integer => true,
- :greater_than_or_equal_to => 1,
- :less_than_or_equal_to => (GsParameter.get('MAX_CALL_FORWARD_DEPTH').nil? ? 0 : GsParameter.get('MAX_CALL_FORWARD_DEPTH'))
before_validation {
self.timeout = nil if self.call_forward_case_id != 3
@@ -49,13 +44,6 @@ class CallForward < ActiveRecord::Base
validates_presence_of :uuid
validates_uniqueness_of :uuid
- # Make sure the call forward's parent can't be changed:
- before_validation { |cfwd|
- if cfwd.id && (cfwd.call_forwardable_id != cfwd.call_forwardable_id_was || cfwd.call_forwardable_type != cfwd.call_forwardable_type_was)
- errors.add( :call_forwardable_id, "cannot be changed." )
- end
- }
-
before_validation :resolve_prerouting
after_save :set_presence
@@ -88,6 +76,30 @@ class CallForward < ActiveRecord::Base
self.destinationable_id, delimeter, self.destinationable_type = destination_record.to_s.partition(':')
end
+ def destination_phone_number
+ if self.destinationable_type.to_s.downcase == 'phonenumber'
+ return self.destination
+ end
+ end
+
+ def destination_phone_number=(destination_number)
+ if self.destinationable_type.to_s.downcase == 'phonenumber'
+ self.destination = destination_number
+ end
+ end
+
+ def destination_greeting
+ if self.destinationable_type.to_s.downcase == 'voicemailaccount'
+ return self.destination
+ end
+ end
+
+ def destination_greeting=(destination_file)
+ if self.destinationable_type.to_s.downcase == 'voicemailaccount'
+ self.destination = destination_file
+ end
+ end
+
def toggle
self.active = ! self.active
return self.save
diff --git a/app/models/cdr.rb b/app/models/cdr.rb
new file mode 100644
index 0000000..ff9198f
--- /dev/null
+++ b/app/models/cdr.rb
@@ -0,0 +1,17 @@
+class Cdr < ActiveRecord::Base
+ self.table_name = 'cdrs'
+ self.primary_key = 'uuid'
+
+ belongs_to :account
+ belongs_to :bleg_account
+ belongs_to :forwarding_account
+
+
+ def self.seconds_to_minutes_seconds(call_seconds)
+ if call_seconds.to_i > 0
+ minutes = (call_seconds / 1.minutes).to_i
+ seconds = call_seconds - minutes.minutes.seconds
+ return '%i:%02i' % [minutes, seconds]
+ end
+ end
+end
diff --git a/app/models/extension_module.rb b/app/models/extension_module.rb
new file mode 100644
index 0000000..98ef700
--- /dev/null
+++ b/app/models/extension_module.rb
@@ -0,0 +1,58 @@
+class ExtensionModule < ActiveRecord::Base
+ attr_accessible :model, :mac_address, :phone_id, :ip_address, :position, :active, :provisioning_key, :provisioning_key_active
+
+ MODELS = ['snom_vision']
+
+ belongs_to :phone
+ before_save :remove_ip_address_when_mac_address_was_changed
+
+ before_save :generate_key
+
+ def to_s
+ mac_address
+ end
+
+ def resync()
+ if ! self.model == 'snom_vision'
+ return false
+ end
+
+ http_user = nil
+ http_password = nil
+
+ if self.phone
+ http_user = self.phone.http_user
+ http_password = self.phone.http_password
+ end
+
+ require 'open-uri'
+ begin
+ if open("http://#{self.ip_address}/ConfigurationModule/restart", :http_basic_authentication=>[http_user, http_password], :proxy => nil)
+ return true
+ end
+ rescue
+ return false
+ end
+ end
+
+ private
+ def sanitize_mac_address
+ if self.mac_address.split(/:/).count == 6 && self.mac_address.length < 17
+ splitted_mac_address = self.mac_address.split(/:/)
+ self.mac_address = splitted_mac_address.map{|part| (part.size == 1 ? "0#{part}" : part)}.join('')
+ end
+ self.mac_address = self.mac_address.to_s.upcase.gsub( /[^A-F0-9]/, '' )
+ end
+
+ def remove_ip_address_when_mac_address_was_changed
+ if self.mac_address_changed?
+ self.ip_address = nil
+ end
+ end
+
+ def generate_key
+ if !GsParameter.get('PROVISIONING_KEY_LENGTH').nil? && GsParameter.get('PROVISIONING_KEY_LENGTH') > 0 && self.provisioning_key.blank?
+ self.provisioning_key = SecureRandom.hex(GsParameter.get('PROVISIONING_KEY_LENGTH'))
+ end
+ end
+end
diff --git a/app/models/freeswitch_cdr.rb b/app/models/freeswitch_cdr.rb
deleted file mode 100644
index fd0eb75..0000000
--- a/app/models/freeswitch_cdr.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-class FreeswitchCdr < ActiveRecord::Base
- self.table_name = 'cdrs'
- self.primary_key = 'uuid'
-end
diff --git a/app/models/gateway.rb b/app/models/gateway.rb
index 01b29b2..437d3af 100644
--- a/app/models/gateway.rb
+++ b/app/models/gateway.rb
@@ -6,6 +6,7 @@ class Gateway < ActiveRecord::Base
has_many :gateway_settings, :dependent => :destroy
has_many :gateway_parameters, :dependent => :destroy
+ has_many :gateway_headers, :dependent => :destroy
has_many :call_routes, :as => :endpoint, :dependent => :nullify
validates :name,
@@ -72,6 +73,15 @@ class Gateway < ActiveRecord::Base
GsParameter.where(:entity => 'sip_gateways', :section => 'settings').each do |default_setting|
self.gateway_settings.create(:name => default_setting.name, :value => default_setting.value, :class_type => default_setting.class_type, :description => default_setting.description)
end
+ GsParameter.where(:entity => 'sip_gateways', :section => 'headers_default').each do |default_header|
+ self.gateway_headers.create(:name => default_header.name, :value => default_header.value, :header_type => 'default', :description => default_header.description)
+ end
+ GsParameter.where(:entity => 'sip_gateways', :section => 'headers_default_clir_off').each do |default_header|
+ self.gateway_headers.create(:constraint_value => 'clir=false', :name => default_header.name, :value => default_header.value, :header_type => 'default', :description => default_header.description)
+ end
+ GsParameter.where(:entity => 'sip_gateways', :section => 'headers_default_clir_on').each do |default_header|
+ self.gateway_headers.create(:constraint_value => 'clir=true', :name => default_header.name, :value => default_header.value, :header_type => 'default', :description => default_header.description)
+ end
end
end
diff --git a/app/models/gateway_header.rb b/app/models/gateway_header.rb
new file mode 100644
index 0000000..474bfac
--- /dev/null
+++ b/app/models/gateway_header.rb
@@ -0,0 +1,25 @@
+class GatewayHeader < ActiveRecord::Base
+ HEADER_TYPES = [
+ 'default',
+ 'invite',
+ # 'provisional',
+ # 'request',
+ # 'bye',
+ ]
+
+ attr_accessible :gateway_id, :header_type, :constraint_source, :constraint_value, :name, :value, :description
+
+ belongs_to :gateway, :touch => true
+
+ validates :name,
+ :presence => true,
+ :uniqueness => {:scope => [:gateway_id, :header_type, :constraint_source, :constraint_value]}
+
+ validates :header_type,
+ :presence => true,
+ :inclusion => { :in => HEADER_TYPES }
+
+ def to_s
+ name
+ end
+end
diff --git a/app/models/gateway_setting.rb b/app/models/gateway_setting.rb
index e96bb52..a71b615 100644
--- a/app/models/gateway_setting.rb
+++ b/app/models/gateway_setting.rb
@@ -14,10 +14,7 @@ class GatewaySetting < ActiveRecord::Base
'contact' => 'String',
'dial_string' => 'String',
'profile' => 'String',
- 'from' => 'String',
- 'from_clir' => 'String',
- 'asserted_identity' => 'String',
- 'asserted_identity_clir' => 'String',
+ 'dtmf_type' => 'String',
},
'xmpp' => {
'server' => 'String',
diff --git a/app/models/group_membership.rb b/app/models/group_membership.rb
index 0f04ae1..d9d48e7 100644
--- a/app/models/group_membership.rb
+++ b/app/models/group_membership.rb
@@ -12,8 +12,6 @@ class GroupMembership < ActiveRecord::Base
:presence => true,
:uniqueness => { :scope => [:group_id, :item_id] }
- validate :validate_item_type_consitency
-
validates :item,
:presence => true
@@ -27,11 +25,4 @@ class GroupMembership < ActiveRecord::Base
return fist_item.class.name
end
end
-
- def validate_item_type_consitency
- type_allowed = self.item_type_allowed
- if type_allowed && type_allowed != self.item_type
- errors.add(:item_type, "must be of type: #{type_allowed}")
- end
- end
end
diff --git a/app/models/hunt_group.rb b/app/models/hunt_group.rb
index 93279ae..fac0cc5 100644
--- a/app/models/hunt_group.rb
+++ b/app/models/hunt_group.rb
@@ -2,7 +2,7 @@ class HuntGroup < ActiveRecord::Base
attr_accessible :name, :strategy, :seconds_between_jumps, :phone_numbers_attributes
belongs_to :tenant, :touch => true
- has_many :destrination_call_forwards, :as => :destinationable, :dependent => :destroy
+ has_many :destrination_call_forwards, :class_name => 'CallForward', :as => :destinationable, :dependent => :destroy
has_many :call_forwards, :as => :call_forwardable, :dependent => :destroy
validates_uniqueness_of :name, :scope => :tenant_id,
diff --git a/app/models/phone.rb b/app/models/phone.rb
index 8b41b59..93553a2 100644
--- a/app/models/phone.rb
+++ b/app/models/phone.rb
@@ -13,6 +13,8 @@ class Phone < ActiveRecord::Base
has_many :phone_sip_accounts, :dependent => :destroy, :uniq => true, :order => :position
has_many :sip_accounts, :through => :phone_sip_accounts
+
+ has_many :extension_modules
belongs_to :tenant
belongs_to :fallback_sip_account, :class_name => "SipAccount"
@@ -195,8 +197,7 @@ class Phone < ActiveRecord::Base
return true
end
- private
-
+ private
# Sanitize MAC address.
#
def sanitize_mac_address
diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb
index 668fbfe..a2644e9 100644
--- a/app/models/sip_account.rb
+++ b/app/models/sip_account.rb
@@ -154,14 +154,15 @@ class SipAccount < ActiveRecord::Base
return SipRegistration.where(:sip_user => self.auth_name).first
end
- def call( phone_number, origin_cid_number = nil, origin_cid_name = 'Call' )
- origin_cid_number = origin_cid_number || phone_number
+ def call( phone_number, caller_id_number = nil, caller_id_name = 'Call', auto_answer = false )
require 'freeswitch_event'
- return FreeswitchAPI.execute(
+ origination_uuid = UUID.new.generate
+ if FreeswitchAPI.execute(
'originate',
- "{origination_uuid=#{UUID.new.generate},origination_caller_id_number='#{phone_number}',origination_caller_id_name='#{origin_cid_name}'}user/#{self.auth_name} #{phone_number}",
- true
- );
+ "{origination_uuid=#{origination_uuid},origination_caller_id_number='#{caller_id_number||phone_number}',origination_caller_id_name='#{caller_id_name}',sip_auto_answer='#{auto_answer}'}user/#{self.auth_name} #{phone_number}",
+ true)
+ return origination_uuid
+ end
end
def target_group_ids_by_permission(permission)
diff --git a/app/models/switchboard.rb b/app/models/switchboard.rb
index 095f878..d62657f 100644
--- a/app/models/switchboard.rb
+++ b/app/models/switchboard.rb
@@ -25,8 +25,13 @@ class Switchboard < ActiveRecord::Base
}
belongs_to :user, :touch => true
+
has_many :switchboard_entries, :dependent => :destroy
+ has_many :switchable_switchboard_entries, :class_name => "SwitchboardEntry", :conditions => {:switchable => true}
+
has_many :sip_accounts, :through => :switchboard_entries
+ has_many :switchable_sip_accounts, :source => :sip_account, :through => :switchable_switchboard_entries, :uniq => true
+
has_many :phone_numbers, :through => :sip_accounts
before_validation :convert_0_to_nil
@@ -36,7 +41,11 @@ class Switchboard < ActiveRecord::Base
end
def active_calls
- self.switchboard_entries.where(:switchable => true).map{|se| se.sip_account}.uniq.map{|sip_account| sip_account.calls}.flatten
+ Call.where("sip_account_id = ? or b_sip_account_id = ?", self.switchable_sip_account_ids, self.switchable_sip_account_ids).order(:start_stamp)
+ end
+
+ def dispatchable_incoming_calls
+ Call.where("b_sip_account_id = ?", self.switchable_sip_account_ids).order(:start_stamp)
end
private
diff --git a/app/models/user.rb b/app/models/user.rb
index 5e97459..70c9042 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -107,6 +107,8 @@ class User < ActiveRecord::Base
after_save :become_a_member_of_default_user_groups
+ after_save :change_language_of_child_objects
+
def destroy
clean_whitelist_entries
super
@@ -246,4 +248,15 @@ class User < ActiveRecord::Base
end
end
+ def change_language_of_child_objects
+ if !self.language_id_changed?
+ return nil
+ end
+
+ code = self.language.code
+ self.sip_accounts.each do |sip_account|
+ sip_account.update_attributes(:language_code => code)
+ end
+ end
+
end
diff --git a/app/models/voicemail_account.rb b/app/models/voicemail_account.rb
index 8ec181f..298516e 100644
--- a/app/models/voicemail_account.rb
+++ b/app/models/voicemail_account.rb
@@ -21,9 +21,9 @@ class VoicemailAccount < ActiveRecord::Base
def notify_to
send_notification = nil
- if self.voicemail_settings.where(:name => 'notify', :value => true).first
+ if self.voicemail_settings.where(:name => 'notify', :value => 'true').first
send_notification = true
- elsif self.voicemail_settings.where(:name => 'notify', :value => false).first
+ elsif self.voicemail_settings.where(:name => 'notify', :value => 'false').first
send_notification = false
end
@@ -49,9 +49,9 @@ class VoicemailAccount < ActiveRecord::Base
def notification_setting(name)
setting = nil
- if self.voicemail_settings.where(:name => name, :value => true).first
+ if self.voicemail_settings.where(:name => name, :value => 'true').first
setting = true
- elsif self.voicemail_settings.where(:name => name, :value => false).first
+ elsif self.voicemail_settings.where(:name => name, :value => 'false').first
setting = false
end