summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/ability.rb5
-rw-r--r--app/models/acd_agent.rb9
-rw-r--r--app/models/automatic_call_distributor.rb2
-rw-r--r--app/models/hunt_group.rb3
-rw-r--r--app/models/intruder.rb24
-rw-r--r--app/models/sip_account.rb38
-rw-r--r--app/models/softkey.rb22
7 files changed, 93 insertions, 10 deletions
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/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
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
diff --git a/app/models/intruder.rb b/app/models/intruder.rb
index 9a1c39a..9c01634 100644
--- a/app/models/intruder.rb
+++ b/app/models/intruder.rb
@@ -50,6 +50,27 @@ class Intruder < ActiveRecord::Base
}
end
+ 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|
+ if !name.blank? && value then
+ event.add_header(name, value)
+ end
+ end
+ return event.fire()
+ end
+
private
def set_key_if_empty
if self.key.blank?
@@ -98,6 +119,7 @@ class Intruder < ActiveRecord::Base
write_firewall_list
restart_firewall
end
+ self.perimeter_db_rescan
end
end
@@ -108,6 +130,7 @@ class Intruder < ActiveRecord::Base
restart_firewall
end
end
+ self.perimeter_db_rescan
end
def check_if_delete_relevant
@@ -117,5 +140,6 @@ class Intruder < ActiveRecord::Base
restart_firewall
end
end
+ self.perimeter_db_rescan
end
end
diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb
index 74a2562..930069d 100644
--- a/app/models/sip_account.rb
+++ b/app/models/sip_account.rb
@@ -41,6 +41,7 @@ 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
has_many :switchboard_entries, :dependent => :destroy
# Delegations:
@@ -162,12 +163,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
@@ -180,6 +185,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
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.