summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Kozak <spag@golwen.net>2013-03-28 14:27:22 +0100
committerPeter Kozak <spag@golwen.net>2013-03-28 14:27:22 +0100
commit68ee69efeca95e6fa5fb063ca77274cffb053692 (patch)
tree430956c002a17efdbfcf1c1956e0eeb03f1834a1
parentd8a6f81af4d1752c9c28c6560fb9bc1c52e7ab9c (diff)
call_forwarding_destinations method
-rw-r--r--app/controllers/call_forwards_controller.rb43
1 files changed, 34 insertions, 9 deletions
diff --git a/app/controllers/call_forwards_controller.rb b/app/controllers/call_forwards_controller.rb
index cdf6c06..917bee3 100644
--- a/app/controllers/call_forwards_controller.rb
+++ b/app/controllers/call_forwards_controller.rb
@@ -127,7 +127,7 @@ class CallForwardsController < ApplicationController
end
def call_forwarding_destination_types
-
+ destinations_hash = {}
phone_number_destination = CallForwardingDestination.new()
phone_number_destination.id = ':PhoneNumber'
phone_number_destination.label = 'Phone Number'
@@ -140,18 +140,37 @@ class CallForwardsController < ApplicationController
@parent.voicemail_accounts.each do |voicemail_account|
call_forwards_destination = CallForwardingDestination.new()
call_forwards_destination.id = "#{voicemail_account.id}:VoicemailAccount"
- call_forwards_destination.label = "VoicemailAccount: #{voicemail_account.to_s}"
- call_forwarding_destinations << call_forwards_destination
+ call_forwards_destination.label = "VoicemailAccount: #{voicemail_account.to_s}"
+ if !destinations_hash[call_forwards_destination.id]
+ destinations_hash[call_forwards_destination.id] = true
+ call_forwarding_destinations << call_forwards_destination
+ end
end
end
if @parent.class == SipAccount
sip_account = @parent
+ group_ids = Group.target_group_ids_by_permission(:forward_to, sip_account.groups)
+
if sip_account.sip_accountable.class == User || sip_account.sip_accountable.class == Tenant
+ group_ids = group_ids + Group.target_group_ids_by_permission(:forward_to, sip_account.sip_accountable.groups)
sip_account.sip_accountable.voicemail_accounts.each do |voicemail_account|
call_forwards_destination = CallForwardingDestination.new()
call_forwards_destination.id = "#{voicemail_account.id}:VoicemailAccount"
call_forwards_destination.label = "VoicemailAccount: #{voicemail_account.to_s}"
+ if !destinations_hash[call_forwards_destination.id]
+ destinations_hash[call_forwards_destination.id] = true
+ call_forwarding_destinations << call_forwards_destination
+ end
+ end
+ end
+
+ GroupMembership.where(:group_id => group_ids, :item_type => 'VoicemailAccount').each do |group_member|
+ call_forwards_destination = CallForwardingDestination.new()
+ call_forwards_destination.id = "#{group_member.item.id}:VoicemailAccount"
+ call_forwards_destination.label = "VoicemailAccount: #{group_member.item.to_s}"
+ if !destinations_hash[call_forwards_destination.id]
+ destinations_hash[call_forwards_destination.id] = true
call_forwarding_destinations << call_forwards_destination
end
end
@@ -165,7 +184,10 @@ class CallForwardsController < ApplicationController
call_forwards_destination = CallForwardingDestination.new()
call_forwards_destination.id = "#{voicemail_account.id}:VoicemailAccount"
call_forwards_destination.label = "VoicemailAccount: #{voicemail_account.to_s}"
- call_forwarding_destinations << call_forwards_destination
+ if !destinations_hash[call_forwards_destination.id]
+ destinations_hash[call_forwards_destination.id] = true
+ call_forwarding_destinations << call_forwards_destination
+ end
end
end
end
@@ -173,14 +195,17 @@ class CallForwardsController < ApplicationController
if GuiFunction.display?('huntgroup_in_destination_field_in_call_forward_form', current_user)
HuntGroup.all.each do |hunt_group|
- hunt_group_destination = CallForwardingDestination.new()
- hunt_group_destination.id = "#{hunt_group.id}:HuntGroup"
- hunt_group_destination.label = "HuntGroup: #{hunt_group.to_s}"
- call_forwarding_destinations.push(hunt_group_destination)
+ call_forwards_destination = CallForwardingDestination.new()
+ call_forwards_destination.id = "#{hunt_group.id}:HuntGroup"
+ call_forwards_destination.label = "HuntGroup: #{hunt_group.to_s}"
+ if !destinations_hash[call_forwards_destination.id]
+ destinations_hash[call_forwards_destination.id] = true
+ call_forwarding_destinations << call_forwards_destination
+ end
end
end
- return call_forwarding_destinations.uniq
+ return call_forwarding_destinations
end
end