summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/models/call_forward.rb14
-rw-r--r--app/models/phone_number.rb26
2 files changed, 40 insertions, 0 deletions
diff --git a/app/models/call_forward.rb b/app/models/call_forward.rb
index de3afc4..a4bfbb5 100644
--- a/app/models/call_forward.rb
+++ b/app/models/call_forward.rb
@@ -56,6 +56,8 @@ class CallForward < ActiveRecord::Base
end
}
+ before_validation :resolve_prerouting
+
after_save :set_presence
after_save :deactivate_concurring_entries, :if => Proc.new { |cf| cf.active == true }
before_destroy :deactivate_connected_softkeys
@@ -135,6 +137,18 @@ class CallForward < ActiveRecord::Base
end
end
+ def resolve_prerouting
+ if self.destinationable_type == 'PhoneNumber' && GsParameter.get('CALLFORWARD_DESTINATION_RESOLVE') != false
+ if self.call_forwardable.class == PhoneNumber
+ prerouting = PhoneNumber.resolve_prerouting(self.destination, self.call_forwardable.phone_numberable)
+ else
+ prerouting = PhoneNumber.resolve_prerouting(self.destination, self.call_forwardable)
+ end
+ if prerouting && !prerouting['destination_number'].blank? && prerouting['type'] == 'phonenumber'
+ self.destination = prerouting['destination_number']
+ end
+ end
+ end
def send_presence_event(state, call_forwarding_service = nil)
dialplan_function = "cftg-#{self.id}"
diff --git a/app/models/phone_number.rb b/app/models/phone_number.rb
index f6453ce..193e4a8 100644
--- a/app/models/phone_number.rb
+++ b/app/models/phone_number.rb
@@ -210,6 +210,10 @@ class PhoneNumber < ActiveRecord::Base
self.central_office_code = nil
self.extension = self.number.to_s.strip
else
+ prerouting = resolve_prerouting
+ if prerouting && !prerouting['destination_number'].blank? && prerouting['type'] == 'phonenumber'
+ self.number = prerouting['destination_number']
+ end
parsed_number = PhoneNumber.parse( self.number )
if parsed_number
self.country_code = parsed_number[:country_code]
@@ -223,6 +227,28 @@ class PhoneNumber < ActiveRecord::Base
end
end
end
+
+ def resolve_prerouting
+ return PhoneNumber.resolve_prerouting(self.number.strip, self.phone_numberable)
+ end
+
+ def self.resolve_prerouting(number, account = nil)
+ account = account || SipAccount.first
+
+ routes = CallRoute.test_route(:prerouting, {
+ 'caller.destination_number' => number,
+ 'caller.auth_account_type' => account.class.name,
+ 'caller.auth_account_id' => account.id,
+ 'caller.auth_account_uuid' => account.try(:uuid),
+ 'caller.account_type' => account.class.name,
+ 'caller.account_id' => account.id,
+ 'caller.account_uuid' => account.try(:uuid),
+ })
+
+ if routes
+ return routes['routes']['1']
+ end
+ end
# Find the (grand-)parent tenant of this phone number:
#