diff options
Diffstat (limited to 'app/models/phone_number.rb')
-rw-r--r-- | app/models/phone_number.rb | 26 |
1 files changed, 26 insertions, 0 deletions
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: # |