From 24208a654fe65a2016244f0ebb99af66ed0bd8d7 Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 18 Feb 2013 12:13:30 +0100 Subject: received fax documents --- app/models/fax_document.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'app/models') diff --git a/app/models/fax_document.rb b/app/models/fax_document.rb index 564d3bb..a0d2100 100644 --- a/app/models/fax_document.rb +++ b/app/models/fax_document.rb @@ -68,6 +68,29 @@ class FaxDocument < ActiveRecord::Base FileUtils.rm_rf tmp_dir end + def tiff_to_pdf() + tiff_file = self.tiff.to_s.gsub(self.tiff.store_path, '') + if !File.exists?(tiff_file) + return nil + end + + working_path, file_name = File.split(tiff_file) + pdf_file = "#{working_path}/#{File.basename(tiff_file, '.tiff')}.pdf" + + system "tiff2pdf \\ + -o \"#{pdf_file}\" \\ + -p letter \\ + -a \"#{self.remote_station_id}\" \\ + -c \"AMOOMA Gemeinschaft version #{GsParameter.get('GEMEINSCHAFT_VERSION')}\" \\ + -t \"#{self.remote_station_id}\" \"#{tiff_file}\"" + + if !File.exists?(pdf_file) + return nil + end + + return pdf_file, tiff_file + end + private def convert_pdf_to_tiff page_size_a4 = '595 842' -- cgit v1.2.3 From 99af7fc0788735bec2a450ca0fa3e264ea9625c1 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Mon, 18 Feb 2013 13:14:16 +0100 Subject: use /var/spool/gemeinschaft as spooling dir --- app/models/fax_document.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/fax_document.rb b/app/models/fax_document.rb index 564d3bb..2e37998 100644 --- a/app/models/fax_document.rb +++ b/app/models/fax_document.rb @@ -57,7 +57,7 @@ class FaxDocument < ActiveRecord::Base end def create_thumbnails_and_save_them - tmp_dir = "/tmp/fax_convertions/#{self.id}" + tmp_dir = "/var/spool/gemeinschaft/fax_convertions/#{self.id}" FileUtils.mkdir_p tmp_dir system("cd #{tmp_dir} && convert #{self.document.path} -colorspace Gray PNG:'fax_page.png'") Dir.glob("#{tmp_dir}/fax_page*.png").each do |thumbnail| @@ -72,7 +72,7 @@ class FaxDocument < ActiveRecord::Base def convert_pdf_to_tiff page_size_a4 = '595 842' page_size_command = "<< /Policies << /PageSize 3 >> /InputAttributes currentpagedevice /InputAttributes get dup { pop 1 index exch undef } forall dup 0 << /PageSize [ #{page_size_a4} ] >> put >> setpagedevice" - directory = "/tmp/GS-#{GsParameter.get('GEMEINSCHAFT_VERSION')}/faxes/#{self.id}" + directory = "/var/spool/gemeinschaft/GS-#{GsParameter.get('GEMEINSCHAFT_VERSION')}/faxes/#{self.id}" FileUtils.mkdir_p directory tiff_file_name = File.basename(self.document.to_s.downcase, ".pdf") + '.tiff' system "cd #{directory} && gs -q -r#{self.fax_resolution.resolution_value} -dNOPAUSE -dBATCH -dSAFER -sDEVICE=tiffg3 -sOutputFile=\"#{tiff_file_name}\" -c \"#{page_size_command}\" -- \"#{Rails.root.to_s}/public#{self.document.to_s}\"" -- cgit v1.2.3 From de845aa642e22b0ae08c5ce991bcdef9b656e079 Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 19 Feb 2013 09:30:47 +0100 Subject: phone number name tag --- app/models/phone_book_entry.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app/models') diff --git a/app/models/phone_book_entry.rb b/app/models/phone_book_entry.rb index 275c7b6..96c8468 100644 --- a/app/models/phone_book_entry.rb +++ b/app/models/phone_book_entry.rb @@ -1,6 +1,8 @@ # encoding: UTF-8 class PhoneBookEntry < ActiveRecord::Base + PHONE_NUMBER_NAMES = ['Phone', 'Office', 'Home', 'Mobile', 'Fax'] + before_save :run_phonetic_algorithm before_save :save_value_of_to_s -- cgit v1.2.3 From 2b3892ac24bb61c4814e0afe141bf53765fb1e4b Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 19 Feb 2013 13:16:12 +0100 Subject: fax storage directory --- app/models/fax_document.rb | 55 ++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 19 deletions(-) (limited to 'app/models') diff --git a/app/models/fax_document.rb b/app/models/fax_document.rb index c73fa3d..e9bb5f1 100644 --- a/app/models/fax_document.rb +++ b/app/models/fax_document.rb @@ -1,8 +1,7 @@ class FaxDocument < ActiveRecord::Base # attr_accessible :inbound, :transmission_time, :sent_at, :document_total_pages, :document_transferred_pages, :ecm_requested, :ecm_used, :image_resolution, :image_size, :local_station_id, :result_code, :result_text, :remote_station_id, :success, :transfer_rate, :t38_gateway_format, :t38_peer, :document - mount_uploader :document, DocumentUploader - mount_uploader :tiff, TiffUploader + mount_uploader :document, FaxDocumentUploader validates_presence_of :document validates_numericality_of :retry_counter, :only_integer => true, :greater_than_or_equal_to => 0 @@ -18,7 +17,7 @@ class FaxDocument < ActiveRecord::Base has_many :fax_thumbnails, :order => :position, :dependent => :destroy - after_create :convert_pdf_to_tiff + after_save :convert_to_tiff after_create :render_thumbnails # Scopes @@ -68,40 +67,58 @@ class FaxDocument < ActiveRecord::Base FileUtils.rm_rf tmp_dir end - def tiff_to_pdf() - tiff_file = self.tiff.to_s.gsub(self.tiff.store_path, '') - if !File.exists?(tiff_file) + def tiff_to_pdf + if !File.exists?(self.tiff) return nil end - working_path, file_name = File.split(tiff_file) - pdf_file = "#{working_path}/#{File.basename(tiff_file, '.tiff')}.pdf" + working_path, file_name = File.split(self.tiff) + pdf_file = "#{working_path}/#{File.basename(self.tiff, '.tiff')}.pdf" system "tiff2pdf \\ -o \"#{pdf_file}\" \\ -p letter \\ -a \"#{self.remote_station_id}\" \\ -c \"AMOOMA Gemeinschaft version #{GsParameter.get('GEMEINSCHAFT_VERSION')}\" \\ - -t \"#{self.remote_station_id}\" \"#{tiff_file}\"" + -t \"#{self.remote_station_id}\" \"#{self.tiff}\"" if !File.exists?(pdf_file) return nil end - return pdf_file, tiff_file + return pdf_file end - private - def convert_pdf_to_tiff + def to_tiff page_size_a4 = '595 842' page_size_command = "<< /Policies << /PageSize 3 >> /InputAttributes currentpagedevice /InputAttributes get dup { pop 1 index exch undef } forall dup 0 << /PageSize [ #{page_size_a4} ] >> put >> setpagedevice" - directory = "/var/spool/gemeinschaft/GS-#{GsParameter.get('GEMEINSCHAFT_VERSION')}/faxes/#{self.id}" - FileUtils.mkdir_p directory - tiff_file_name = File.basename(self.document.to_s.downcase, ".pdf") + '.tiff' - system "cd #{directory} && gs -q -r#{self.fax_resolution.resolution_value} -dNOPAUSE -dBATCH -dSAFER -sDEVICE=tiffg3 -sOutputFile=\"#{tiff_file_name}\" -c \"#{page_size_command}\" -- \"#{Rails.root.to_s}/public#{self.document.to_s}\"" - self.tiff = File.open("#{directory}/#{tiff_file_name}") - self.save - FileUtils.rm_rf directory + working_path, file_name = File.split(self.document.to_s) + tiff_file = File.basename(file_name.to_s.downcase, File.extname(file_name)) + '.tiff' + result = system "cd #{store_dir} && gs -q -r#{self.fax_resolution.resolution_value} -dNOPAUSE -dBATCH -dSAFER -sDEVICE=tiffg3 -sOutputFile=\"#{tiff_file}\" -c \"#{page_size_command}\" -- \"#{self.document.to_s}\"" + + if !File.exists?("#{store_dir}/#{tiff_file}") + return nil + end + + return "#{store_dir}/#{tiff_file}" + end + + def store_dir + if self.try(:inbound) + "/var/opt/gemeinschaft/fax/in/#{self.id}" + else + "/var/opt/gemeinschaft/fax/out/#{self.id}" + end + end + + private + def convert_to_tiff + if self.tiff.blank? + self.tiff = self.to_tiff + if self.tiff + return self.save + end + end end end -- cgit v1.2.3 From 22d581aa38ae4e015c654356fb61d110456e69ee Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 19 Feb 2013 14:05:11 +0100 Subject: preserve tiff file --- app/models/fax_document.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/fax_document.rb b/app/models/fax_document.rb index e9bb5f1..5b27965 100644 --- a/app/models/fax_document.rb +++ b/app/models/fax_document.rb @@ -19,6 +19,8 @@ class FaxDocument < ActiveRecord::Base after_save :convert_to_tiff after_create :render_thumbnails + + after_destroy :remove_storage_dir # Scopes scope :inbound, where(:state => 'inbound') @@ -105,9 +107,9 @@ class FaxDocument < ActiveRecord::Base def store_dir if self.try(:inbound) - "/var/opt/gemeinschaft/fax/in/#{self.id}" + "/var/opt/gemeinschaft/fax/in/#{self.id.to_i}" else - "/var/opt/gemeinschaft/fax/out/#{self.id}" + "/var/opt/gemeinschaft/fax/out/#{self.id.to_i}" end end @@ -121,4 +123,10 @@ class FaxDocument < ActiveRecord::Base end end + def remove_storage_dir + if File.directory?(self.store_dir) + FileUtils.rm_rf(self.store_dir) + end + end + end -- cgit v1.2.3 From aa54ca3ea7b726d6e9c411ed41952ac8b483484c Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 20 Feb 2013 08:40:15 +0100 Subject: write firewall blacklist method --- app/models/intruder.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'app/models') diff --git a/app/models/intruder.rb b/app/models/intruder.rb index 249fffc..97e3773 100644 --- a/app/models/intruder.rb +++ b/app/models/intruder.rb @@ -31,6 +31,41 @@ class Intruder < ActiveRecord::Base end end + def self.write_firewall_blacklist + firewall_blacklist_file = GsParameter.get('blacklist_file', 'perimeter', 'general') + entry_template = GsParameter.get('blacklist_file_entry', 'perimeter', 'general') + comment_template = GsParameter.get('blacklist_file_comment', 'perimeter', 'general') + File.open(firewall_blacklist_file, 'w') do |file| + Intruder.where(:list_type => 'blacklist').where('bans > 0').all.each do |entry| + if ! comment_template.blank? + file.write(self.expand_variables(comment_template, entry.to_hash) + "\n") + end + file.write(self.expand_variables(entry_template, entry.to_hash) + "\n") + end + end + end + + def self.expand_variables(line, variables) + return line.gsub(/\{([a-z_]+)\}/) do |m| + variables[$1.to_sym] + end + end + + def to_hash + return { + :key => self.key, + :points => self.points, + :bans => self.bans, + :received_port => self.contact_port, + :received_ip => self.contact_ip, + :contact_count => self.contact_count, + :user_agent => self.user_agent, + :to_user => self.to_user, + :comment => self.comment, + :date => DateTime.now.strftime('%Y-%m-%d %X') + } + end + private def set_key_if_empty if self.key.blank? -- cgit v1.2.3 From 32fac3575ab52dba1a39925d61465702ee11eb9c Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 20 Feb 2013 08:40:33 +0100 Subject: entity, section added --- app/models/gs_parameter.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/gs_parameter.rb b/app/models/gs_parameter.rb index fe2a845..cd4f47b 100644 --- a/app/models/gs_parameter.rb +++ b/app/models/gs_parameter.rb @@ -10,9 +10,13 @@ class GsParameter < ActiveRecord::Base :presence => true, :inclusion => { :in => ['String', 'Integer', 'Boolean', 'YAML', 'Nil'] } - def self.get(wanted_variable) + def self.get(wanted_variable, entity=nil, section=nil) if GsParameter.table_exists? - item = GsParameter.where(:name => wanted_variable).first + if entity || section + item = GsParameter.where(:name => wanted_variable, :entity => entity, :section => section).first + else + item = GsParameter.where(:name => wanted_variable).first + end if item.nil? || item.class_type == 'Nil' return nil else -- cgit v1.2.3 From 2a9b798f9e122582abb36605a7d4a1da0e70eca9 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Fri, 22 Feb 2013 07:08:23 -0500 Subject: pickup group permission model added --- app/models/group.rb | 11 +++++++++++ app/models/group_membership.rb | 37 +++++++++++++++++++++++++++++++++++++ app/models/group_permission.rb | 24 ++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 app/models/group.rb create mode 100644 app/models/group_membership.rb create mode 100644 app/models/group_permission.rb (limited to 'app/models') diff --git a/app/models/group.rb b/app/models/group.rb new file mode 100644 index 0000000..e0cfaab --- /dev/null +++ b/app/models/group.rb @@ -0,0 +1,11 @@ +class Group < ActiveRecord::Base + attr_accessible :name, :active, :comment + + has_many :group_memberships, :dependent => :destroy + has_many :group_permissions, :dependent => :destroy + has_many :permittances, :foreign_key => :target_group_id, :class_name => "GroupPermission", :dependent => :destroy + + def to_s + self.name + end +end diff --git a/app/models/group_membership.rb b/app/models/group_membership.rb new file mode 100644 index 0000000..0f04ae1 --- /dev/null +++ b/app/models/group_membership.rb @@ -0,0 +1,37 @@ +class GroupMembership < ActiveRecord::Base + attr_accessible :group_id, :item_type, :item_id + + belongs_to :group + belongs_to :item, :polymorphic => true + + validates :item_id, + :presence => true, + :uniqueness => { :scope => [:group_id, :item_type] } + + validates :item_type, + :presence => true, + :uniqueness => { :scope => [:group_id, :item_id] } + + validate :validate_item_type_consitency + + validates :item, + :presence => true + + def to_s + "#{self.item_type}: #{self.item}" + end + + def item_type_allowed + fist_item = self.group.group_memberships.first.try(:item) + if fist_item + 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/group_permission.rb b/app/models/group_permission.rb new file mode 100644 index 0000000..fe988ba --- /dev/null +++ b/app/models/group_permission.rb @@ -0,0 +1,24 @@ +class GroupPermission < ActiveRecord::Base + attr_accessible :group_id, :permission, :target_group_id + + PERMISSION_TYPES = ['pickup'] + + belongs_to :group + belongs_to :target_group, :class_name => "Group" + + validates :target_group_id, + :presence => true, + :uniqueness => { :scope => [:group_id, :permission] } + + validates :target_group, + :presence => true + + validates :permission, + :presence => true, + :uniqueness => { :scope => [:group_id, :target_group_id] }, + :inclusion => { :in => PERMISSION_TYPES } + + def to_s + "#{self.permission} => #{self.target_group}" + end +end -- cgit v1.2.3 From 966b8733a82f07f825ce07baff0d37e2a5863960 Mon Sep 17 00:00:00 2001 From: Gemeinschaft Service Account Date: Sun, 24 Feb 2013 06:02:29 -0500 Subject: add default groups --- app/models/sip_account.rb | 31 ++++++++++++++++++++++++++++++- app/models/user.rb | 16 ++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index 7df8e3b..2b8e95f 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -33,6 +33,9 @@ class SipAccount < ActiveRecord::Base belongs_to :language, :foreign_key => 'language_code', :primary_key => 'code' + has_many :group_memberships, :as => :item, :dependent => :destroy, :uniq => true + has_many :groups, :through => :group_memberships + # Delegations: # delegate :host, :to => :sip_domain, :allow_nil => true @@ -67,6 +70,7 @@ class SipAccount < ActiveRecord::Base validates_uniqueness_of :uuid after_create { self.create_on_other_gs_nodes('sip_accountable', self.sip_accountable.try(:uuid)) } + after_create :create_default_group_memberships after_destroy :destroy_on_other_gs_nodes after_update { self.update_on_other_gs_nodes('sip_accountable', self.sip_accountable.try(:uuid)) } @@ -146,7 +150,7 @@ class SipAccount < ActiveRecord::Base true ); end - + private @@ -220,4 +224,29 @@ class SipAccount < ActiveRecord::Base voicemail_setting.purge = false voicemail_setting.save end + + def create_default_group_memberships + default_groups = Hash.new() + templates = GsParameter.get('SipAccount', 'group', 'default') + if templates.class == Array + templates.each do |group_name| + default_groups[group_name] = true + end + end + + templates = GsParameter.get("SipAccount.#{self.sip_accountable_type}", 'group', 'default') + if templates.class == Array + templates.each do |group_name| + default_groups[group_name] = true + end + end + + default_groups.each do |group_name, value| + group = Group.where(:name => group_name).first + if group + self.group_memberships.create(:group_id => group.id) + end + end + end + end diff --git a/app/models/user.rb b/app/models/user.rb index 6c67351..913d75f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -6,6 +6,7 @@ class User < ActiveRecord::Base # Sync other nodes when this is a cluster. # after_create :create_on_other_gs_nodes + after_create :create_default_group_memberships after_destroy :destroy_on_other_gs_nodes after_update :update_on_other_gs_nodes @@ -89,6 +90,9 @@ class User < ActiveRecord::Base belongs_to :gs_node has_many :parking_stalls, :as => :parking_stallable, :dependent => :destroy + + has_many :group_memberships, :as => :item, :dependent => :destroy, :uniq => true + has_many :groups, :through => :group_memberships # Avatar like photo mount_uploader :image, ImageUploader @@ -226,4 +230,16 @@ class User < ActiveRecord::Base end end + def create_default_group_memberships + templates = GsParameter.get('User', 'group', 'default') + if templates.class == Array + templates.each do |group_name| + group = Group.where(:name => group_name).first + if group + self.group_memberships.create(:group_id => group.id) + end + end + end + end + end -- cgit v1.2.3 From 86a77e472a54f6091eebffae42d638c3c826c13d Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 25 Feb 2013 02:39:39 -0500 Subject: softkeys are polymorphic --- app/models/call_forward.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/call_forward.rb b/app/models/call_forward.rb index c668993..088bd23 100644 --- a/app/models/call_forward.rb +++ b/app/models/call_forward.rb @@ -10,7 +10,7 @@ class CallForward < ActiveRecord::Base belongs_to :phone_number belongs_to :call_forwardable, :polymorphic => true - has_many :softkeys + has_many :softkeys, :as => :softkeyable acts_as_list :scope => [ :phone_number_id, :call_forward_case_id ] -- cgit v1.2.3 From 5dcdeb1c1f8c53fd80a0443d61a289e583091416 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 25 Feb 2013 02:51:46 -0500 Subject: logout if node ip and homebase ip differ on multi node setups only --- app/models/sip_account.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index 2b8e95f..420e395 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -206,7 +206,7 @@ class SipAccount < ActiveRecord::Base # log out phone if sip_account is not on this node def log_out_phone_if_not_local - if self.gs_node_id && ! GsNode.where(:ip_address => GsParameter.get('HOMEBASE_IP_ADDRESS'), :id => self.gs_node_id).first + if self.gs_node_id && GsNode.count > 1 && ! GsNode.where(:ip_address => GsParameter.get('HOMEBASE_IP_ADDRESS'), :id => self.gs_node_id).first self.phones.each do |phone| phone.user_logout; end -- cgit v1.2.3 From 0442cd19bc9383669b506185356227361a16e442 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 25 Feb 2013 09:29:40 -0500 Subject: call_forwards - polymorphism added --- app/models/ability.rb | 4 +- app/models/call_forward.rb | 123 +++++++++++---------------------------------- app/models/hunt_group.rb | 2 +- app/models/phone_number.rb | 2 +- app/models/sip_account.rb | 8 +-- app/models/softkey.rb | 6 +-- 6 files changed, 39 insertions(+), 106 deletions(-) (limited to 'app/models') diff --git a/app/models/ability.rb b/app/models/ability.rb index d66577d..d886d53 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -129,7 +129,7 @@ class Ability can :read, SipAccount, :sip_accountable_type => 'User', :sip_accountable_id => user.id user.sip_accounts.each do |sip_account| can :read, PhoneNumber, :id => sip_account.phone_number_ids - can :manage, CallForward, :phone_number_id => sip_account.phone_number_ids + can :manage, CallForward, :call_forwardable_id => sip_account.phone_number_ids can :manage, Ringtone, :ringtoneable_type => 'PhoneNumber', :ringtoneable_id => sip_account.phone_number_ids can [:read, :destroy, :call] , CallHistory, :id => sip_account.call_history_ids end @@ -158,7 +158,7 @@ class Ability # User can manage CallForwards of the PhoneNumbers of his # own SipAccounts: # - can :manage, CallForward, :phone_number_id => user.phone_number_ids + can :manage, CallForward, :call_forwardable_id => user.phone_number_ids # SoftkeyFunctions # diff --git a/app/models/call_forward.rb b/app/models/call_forward.rb index 088bd23..b304439 100644 --- a/app/models/call_forward.rb +++ b/app/models/call_forward.rb @@ -6,17 +6,17 @@ class CallForward < ActiveRecord::Base :destination, :source, :depth, :active, :to_voicemail, :hunt_group_id, :call_forwardable_type, :call_forwardable_id, - :call_forwarding_destination, :position, :uuid + :call_forwarding_destination, :position, :uuid, + :destinationable_type, :destinationable_id - belongs_to :phone_number belongs_to :call_forwardable, :polymorphic => true + belongs_to :destinationable, :polymorphic => true has_many :softkeys, :as => :softkeyable - acts_as_list :scope => [ :phone_number_id, :call_forward_case_id ] + acts_as_list :scope => [ :call_forwardable_id, :call_forwardable_type, :call_forward_case_id ] - validates_presence_of :phone_number validates_presence_of :call_forward_case_id - validates_presence_of :destination, :if => Proc.new { |cf| cf.call_forwardable_type.to_s.downcase == 'phonenumber' || cf.call_forwardable_type.blank? } + validates_presence_of :destination, :if => Proc.new { |cf| cf.destinationable_type.to_s.downcase == 'phonenumber' || cf.destinationable_type.blank? } validates_inclusion_of :destination, :in => [ nil, '' ], @@ -44,23 +44,20 @@ class CallForward < ActiveRecord::Base :in => [ nil ], :if => Proc.new { |cf| cf.call_forward_case_id != 3 } - validate :validate_empty_hunt_group, :if => Proc.new { |cf| cf.active == true && cf.call_forwardable_type == 'HuntGroup' && cf.call_forward_case.value == 'assistant' } + validate :validate_empty_hunt_group, :if => Proc.new { |cf| cf.active == true && cf.destinationable_type == 'HuntGroup' && cf.call_forward_case.value == 'assistant' } 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.phone_number_id != cfwd.phone_number_id_was - errors.add( :phone_number_id, "cannot be changed." ) + 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 :set_call_forwardable before_save :split_and_format_destination_numbers after_save :set_presence - after_save :work_through_callforward_rules_act_per_sip_account after_save :deactivate_concurring_entries, :if => Proc.new { |cf| cf.active == true } before_destroy :check_if_other_callforward_rules_have_to_be_destroyed before_destroy :deactivate_connected_softkeys @@ -70,70 +67,25 @@ class CallForward < ActiveRecord::Base end def to_s - if self.call_forwardable_type.blank? - self.call_forwardable_type = '' + if self.destinationable_type.blank? + self.destinationable_type = '' else - call_forwardable_type = " #{self.call_forwardable_type}" + destinationable_type = " #{self.destinationable_type}" end - if self.call_forwardable - destination = "#{self.call_forwardable}#{call_forwardable_type}" + if self.destinationable + destination = "#{self.destinationable}#{destinationable_type}" else - destination = "#{self.destination}#{call_forwardable_type}" + destination = "#{self.destination}#{destinationable_type}" end - "#{self.phone_number} (#{I18n.t("call_forward_cases.#{self.call_forward_case}")}) -> #{destination}" - end - - def set_this_callforward_rule_to_all_phone_numbers_of_the_parent_sip_account - # This is to make sure that no recursion kicks in. - # - if ! self.phone_number.phone_numberable.respond_to? :callforward_rules_act_per_sip_account - return false - end - - old_value_of_callforward_rules_act_per_sip_account = self.phone_number.phone_numberable.callforward_rules_act_per_sip_account - self.phone_number.phone_numberable.update_attributes({:callforward_rules_act_per_sip_account => false}) - - attributes_of_this_call_forward = self.attributes.delete_if {|key, value| ['id','updated_at','created_at','phone_number_id','call_forward_case_id', 'uuid'].include?(key)} - phone_numbers = self.phone_number.phone_numberable.phone_numbers.where('id != ?', self.phone_number.id) - - phone_numbers.each do |phone_number| - # Problem - call_forward = phone_number.call_forwards.find_or_create_by_call_forward_case_id_and_position(self.call_forward_case_id, self.position, attributes_of_this_call_forward) - call_forward.update_attributes(attributes_of_this_call_forward) - end - - self.phone_number.phone_numberable.update_attributes({:callforward_rules_act_per_sip_account => old_value_of_callforward_rules_act_per_sip_account}) - end - - def destroy_all_similar_callforward_rules_of_the_parent_sip_account - # This is to make sure that no recursion kicks in. - # - if ! self.phone_number.phone_numberable.respond_to? :callforward_rules_act_per_sip_account - return false - end - - old_value_of_callforward_rules_act_per_sip_account = self.phone_number.phone_numberable.callforward_rules_act_per_sip_account - self.phone_number.phone_numberable.update_attributes({:callforward_rules_act_per_sip_account => false}) - - phone_numbers_of_parent_sip_account = self.phone_number.phone_numberable.phone_numbers.where('id != ?', self.phone_number.id) - - phone_numbers_of_parent_sip_account.each do |phone_number| - if self.call_forwardable_type != 'Voicemail' - phone_number.call_forwards.where(:call_forward_case_id => self.call_forward_case_id, :destination => self.destination).destroy_all - else - phone_number.call_forwards.where(:call_forward_case_id => self.call_forward_case_id, :call_forwardable_type => self.call_forwardable_type).destroy_all - end - end - - self.phone_number.phone_numberable.update_attributes({:callforward_rules_act_per_sip_account => old_value_of_callforward_rules_act_per_sip_account}) + "#{self.call_forwardable} (#{I18n.t("call_forward_cases.#{self.call_forward_case}")}) -> #{destination}" end def call_forwarding_destination - "#{self.call_forwardable_id}:#{self.call_forwardable_type}" + "#{self.destinationable_id}:#{self.destinationable_type}" end def call_forwarding_destination=(destination_record) - self.call_forwardable_id, delimeter, self.call_forwardable_type = destination_record.to_s.partition(':') + self.destinationable_id, delimeter, self.destinationable_type = destination_record.to_s.partition(':') end def toggle @@ -168,7 +120,7 @@ class CallForward < ActiveRecord::Base state = 'terminated' if self.active - if self.call_forwardable_type and self.call_forwardable_type.downcase() == 'voicemail' + if self.destinationable_type and self.destinationable_type.downcase() == 'voicemail' state = 'early' else state = 'confirmed' @@ -187,47 +139,28 @@ class CallForward < ActiveRecord::Base #return send_presence_event(self.call_forward_case.value, state) end - def set_call_forwardable + def set_destinationable if @hunt_group_id && HuntGroup.where(:id => @hunt_group_id.to_i).count > 0 - self.call_forwardable = HuntGroup.where(:id => @hunt_group_id.to_i).first + self.destinationable = HuntGroup.where(:id => @hunt_group_id.to_i).first end if @to_voicemail && @to_voicemail.first.downcase == 'true' - self.call_forwardable_type = 'Voicemail' - self.call_forwardable_id = nil + self.destinationable_type = 'Voicemail' + self.destinationable_id = nil end end - def work_through_callforward_rules_act_per_sip_account - if ! self.phone_number.phone_numberable.respond_to? :callforward_rules_act_per_sip_account - return false - end - - if self.phone_number.phone_numberable.callforward_rules_act_per_sip_account == true - self.set_this_callforward_rule_to_all_phone_numbers_of_the_parent_sip_account - end - end - - def check_if_other_callforward_rules_have_to_be_destroyed - if ! self.phone_number.phone_numberable.respond_to? :callforward_rules_act_per_sip_account - return false - end - - if self.phone_number.phone_numberable.callforward_rules_act_per_sip_account == true - self.destroy_all_similar_callforward_rules_of_the_parent_sip_account - end - end def send_presence_event(state, call_forwarding_service = nil) dialplan_function = "cftg-#{self.id}" unique_id = "call_forwarding_#{self.id}" if call_forwarding_service == 'always' - dialplan_function = "cfutg-#{self.phone_number.id}" - unique_id = "call_forwarding_number_#{self.phone_number.id}" + dialplan_function = "cfutg-#{self.call_forwardable.id}" + unique_id = "call_forwarding_number_#{self.call_forwardable.id}" elsif call_forwarding_service == 'assistant' - dialplan_function = "cfatg-#{self.phone_number.id}" - unique_id = "call_forwarding_number_#{self.phone_number.id}" + dialplan_function = "cfatg-#{self.call_forwardable.id}" + unique_id = "call_forwarding_number_#{self.call_forwardable.id}" end if dialplan_function @@ -245,7 +178,7 @@ class CallForward < ActiveRecord::Base end def deactivate_concurring_entries - CallForward.where(:phone_number_id => self.phone_number_id, :call_forward_case_id => self.call_forward_case_id, :active => true).each do |call_forwarding_entry| + CallForward.where(:call_forwardable_id => self.call_forwardable_id, :call_forwardable_type => self.call_forwardable_type, :call_forward_case_id => self.call_forward_case_id, :active => true).each do |call_forwarding_entry| if call_forwarding_entry.id != self.id call_forwarding_entry.update_attributes(:active => false) end @@ -253,7 +186,7 @@ class CallForward < ActiveRecord::Base end def validate_empty_hunt_group - hunt_group = self.call_forwardable + hunt_group = self.destinationable if hunt_group && hunt_group.hunt_group_members.where(:active => true).count == 0 errors.add(:call_forwarding_destination, 'HuntGroup has no active members') end diff --git a/app/models/hunt_group.rb b/app/models/hunt_group.rb index 5011bf0..7338606 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 :call_forwards, :as => :call_forwardable, :dependent => :destroy + has_many :call_forwards, :as => :destinationable, :dependent => :destroy validates_uniqueness_of :name, :scope => :tenant_id, :allow_nil => true, :allow_blank => true diff --git a/app/models/phone_number.rb b/app/models/phone_number.rb index d1e950f..f6453ce 100644 --- a/app/models/phone_number.rb +++ b/app/models/phone_number.rb @@ -3,7 +3,7 @@ class PhoneNumber < ActiveRecord::Base attr_accessible :name, :number, :gs_node_id, :access_authorization_user_id - has_many :call_forwards, :dependent => :destroy + has_many :call_forwards, :as => :call_forwardable, :dependent => :destroy has_many :ringtones, :as => :ringtoneable, :dependent => :destroy diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index 420e395..a39982b 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -16,7 +16,7 @@ class SipAccount < ActiveRecord::Base has_many :phones, :through => :phone_sip_accounts has_many :phone_numbers, :as => :phone_numberable, :dependent => :destroy - has_many :call_forwards, :through => :phone_numbers + has_many :call_forwards, :as => :call_forwardable, :dependent => :destroy belongs_to :tenant belongs_to :sip_domain @@ -96,8 +96,8 @@ class SipAccount < ActiveRecord::Base if call_forwarding_master.active call_forwarding_master.active = false else - if call_forwarding_service = 'assistant' && call_forwarding_master.call_forwardable_type == 'HuntGroup' && call_forwarding_master.call_forwardable - if call_forwarding_master.call_forwardable.hunt_group_members.where(:active => true).count > 0 + if call_forwarding_service = 'assistant' && call_forwarding_master.destinationable_type == 'HuntGroup' && call_forwarding_master.destinationable + if call_forwarding_master.destinationable.hunt_group_members.where(:active => true).count > 0 call_forwarding_master.active = true else call_forwarding_master.active = false @@ -109,7 +109,7 @@ class SipAccount < ActiveRecord::Base call_forwarding = phone_number.call_forwards.where(:call_forward_case_id => service_id).order(:active).all(:conditions => 'source IS NULL OR source = ""').first if ! call_forwarding call_forwarding = CallForward.new() - call_forwarding.phone_number_id = phone_number.id + call_forwarding.call_forwardable = phone_number end if to_voicemail == nil diff --git a/app/models/softkey.rb b/app/models/softkey.rb index 4b758e0..8049456 100644 --- a/app/models/softkey.rb +++ b/app/models/softkey.rb @@ -30,7 +30,7 @@ class Softkey < ActiveRecord::Base # We pick one phone_number and display the rules of it. # phone_number = self.sip_account.phone_numbers.order(:number).first - call_forwards = self.sip_account.call_forwards.where(:phone_number_id => phone_number.id) + call_forwards = self.sip_account.call_forwards.where(:call_forwardable_id => phone_number.id, :call_forwardable_type => 'PhoneNumber') else call_forwards = self.sip_account.call_forwards end @@ -42,8 +42,8 @@ class Softkey < ActiveRecord::Base map{ |phone_number| phone_number.phone_numberable.hunt_group.id }. uniq - call_forwards + CallForward.where(:call_forwardable_type => 'HuntGroup', :call_forwardable_id => hunt_group_ids). - where('phone_number_id NOT IN (?)', phone_numbers_ids) + call_forwards + CallForward.where(:destinationable_type => 'HuntGroup', :destinationable_id => hunt_group_ids, :call_forwardable_type => 'PhoneNumber'). + where('call_forwardable_id NOT IN (?)', phone_numbers_ids) end end -- cgit v1.2.3 From fd07b7b85d2d40d7d2999c2899cc890eda2095fd Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 25 Feb 2013 11:41:55 -0500 Subject: more polymorphic objects --- app/models/call_forward.rb | 3 +-- app/models/ringtone.rb | 14 ++++++++++++++ app/models/sip_account.rb | 2 ++ 3 files changed, 17 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/call_forward.rb b/app/models/call_forward.rb index b304439..a932e11 100644 --- a/app/models/call_forward.rb +++ b/app/models/call_forward.rb @@ -24,8 +24,8 @@ class CallForward < ActiveRecord::Base belongs_to :call_forward_case - validates_presence_of :depth 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')) @@ -59,7 +59,6 @@ class CallForward < ActiveRecord::Base before_save :split_and_format_destination_numbers after_save :set_presence after_save :deactivate_concurring_entries, :if => Proc.new { |cf| cf.active == true } - before_destroy :check_if_other_callforward_rules_have_to_be_destroyed before_destroy :deactivate_connected_softkeys def case_string diff --git a/app/models/ringtone.rb b/app/models/ringtone.rb index 36053c0..45ecd93 100644 --- a/app/models/ringtone.rb +++ b/app/models/ringtone.rb @@ -1,11 +1,25 @@ class Ringtone < ActiveRecord::Base attr_accessible :audio, :bellcore_id + CORE_RINGTONES_AVAILABLE = { + 'Silence' => 0, + 'Ringtone 1' => 1, + 'Ringtone 2' => 2, + 'Ringtone 3' => 3, + 'Ringtone 4' => 4, + 'Ringtone 5' => 5, + 'Ringtone 6' => 6, + 'Ringtone 7' => 7, + 'Ringtone 8' => 8, + 'Ringtone 9' => 9, + 'Ringtone 10' => 10, + } mount_uploader :audio, AudioUploader validates_presence_of :audio, :if => Proc.new{ |ringtone| ringtone.bellcore_id.blank? } validates_presence_of :ringtoneable_type validates_presence_of :ringtoneable_id validates_presence_of :ringtoneable + validates_uniqueness_of :ringtoneable_id, :scope => [:ringtoneable_type] belongs_to :ringtoneable, :polymorphic => true diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index a39982b..034af7c 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -36,6 +36,8 @@ class SipAccount < ActiveRecord::Base has_many :group_memberships, :as => :item, :dependent => :destroy, :uniq => true has_many :groups, :through => :group_memberships + has_many :ringtones, :as => :ringtoneable, :dependent => :destroy + # Delegations: # delegate :host, :to => :sip_domain, :allow_nil => true -- cgit v1.2.3 From ffaa80e8d46b3b6b7597af6f157724005f48bae4 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 26 Feb 2013 10:48:08 +0100 Subject: RestoreJob scaffold --- app/models/ability.rb | 1 + app/models/restore_job.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 app/models/restore_job.rb (limited to 'app/models') diff --git a/app/models/ability.rb b/app/models/ability.rb index d886d53..690ee76 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -176,6 +176,7 @@ class Ability # can :create, GemeinschaftSetup can :manage, SipDomain + can [:create, :new, :show, :index], RestoreJob end end diff --git a/app/models/restore_job.rb b/app/models/restore_job.rb new file mode 100644 index 0000000..2c2da54 --- /dev/null +++ b/app/models/restore_job.rb @@ -0,0 +1,13 @@ +class RestoreJob < ActiveRecord::Base + attr_accessible :state, :backup_file + + mount_uploader :backup_file, BackupFileUploader + + def to_s + if self.backup_file? + File.basename(self.backup_file.to_s) + else + "RestoreJob ID #{self.id}" + end + end +end -- cgit v1.2.3 From 774bb634d17190a30ed0e22183368ab46f74fe5d Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 26 Feb 2013 18:18:12 +0100 Subject: after_create :queue_the_restore_rake_task --- app/models/restore_job.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/restore_job.rb b/app/models/restore_job.rb index 2c2da54..571d967 100644 --- a/app/models/restore_job.rb +++ b/app/models/restore_job.rb @@ -3,11 +3,24 @@ class RestoreJob < ActiveRecord::Base mount_uploader :backup_file, BackupFileUploader + after_create :queue_the_restore_rake_task + def to_s if self.backup_file? File.basename(self.backup_file.to_s) else "RestoreJob ID #{self.id}" end - end + end + + private + def queue_the_restore_rake_task + self.delay.run_the_restore_rake_task + end + + def run_the_restore_rake_task + system "cd #{Rails.root} && rake backup:restore" + end + + end -- cgit v1.2.3 From 23fdaceefb8854756e42ac190f603b0ae73e8d61 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 26 Feb 2013 18:19:47 +0100 Subject: Deleted white space. --- app/models/restore_job.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'app/models') diff --git a/app/models/restore_job.rb b/app/models/restore_job.rb index 571d967..80741ac 100644 --- a/app/models/restore_job.rb +++ b/app/models/restore_job.rb @@ -21,6 +21,4 @@ class RestoreJob < ActiveRecord::Base def run_the_restore_rake_task system "cd #{Rails.root} && rake backup:restore" end - - end -- cgit v1.2.3 From 9dd3fa175bb7fd18f81f8e32468a842babe63e7f Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Tue, 26 Feb 2013 18:40:06 +0100 Subject: run tar commands via sudo --- app/models/backup_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/backup_job.rb b/app/models/backup_job.rb index 96574a7..91345e5 100644 --- a/app/models/backup_job.rb +++ b/app/models/backup_job.rb @@ -32,7 +32,7 @@ class BackupJob < ActiveRecord::Base if tmp_backup_directory.blank? self.state = 'failed' else - system "cd #{backup_directory} && tar czf #{backup_name_prefix}#{File.basename(tmp_backup_directory)}.tar.gz #{File.basename(tmp_backup_directory)}" + system "cd #{backup_directory} && sudo /usr/bin/tar czf #{backup_name_prefix}#{File.basename(tmp_backup_directory)}.tar.gz #{File.basename(tmp_backup_directory)}" require 'fileutils' FileUtils.rm_rf tmp_backup_directory file = File::Stat.new("#{backup_directory}/#{backup_name_prefix}#{File.basename(tmp_backup_directory)}.tar.gz") -- cgit v1.2.3 From 177a2c037468e222191b6668eb8e64a94833b18c Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Tue, 26 Feb 2013 21:34:33 +0100 Subject: correct path for tar --- app/models/backup_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/backup_job.rb b/app/models/backup_job.rb index 91345e5..a04f6c0 100644 --- a/app/models/backup_job.rb +++ b/app/models/backup_job.rb @@ -32,7 +32,7 @@ class BackupJob < ActiveRecord::Base if tmp_backup_directory.blank? self.state = 'failed' else - system "cd #{backup_directory} && sudo /usr/bin/tar czf #{backup_name_prefix}#{File.basename(tmp_backup_directory)}.tar.gz #{File.basename(tmp_backup_directory)}" + system "cd #{backup_directory} && sudo /bin/tar czf #{backup_name_prefix}#{File.basename(tmp_backup_directory)}.tar.gz #{File.basename(tmp_backup_directory)}" require 'fileutils' FileUtils.rm_rf tmp_backup_directory file = File::Stat.new("#{backup_directory}/#{backup_name_prefix}#{File.basename(tmp_backup_directory)}.tar.gz") -- cgit v1.2.3 From ba0dc7a5cefe825fe0b09e2d6ccf9821bb20c7f9 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 26 Feb 2013 16:37:14 -0500 Subject: manage ringtones ability added --- app/models/ability.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app/models') diff --git a/app/models/ability.rb b/app/models/ability.rb index 690ee76..e885c53 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -131,6 +131,7 @@ class Ability can :read, PhoneNumber, :id => sip_account.phone_number_ids can :manage, CallForward, :call_forwardable_id => sip_account.phone_number_ids can :manage, Ringtone, :ringtoneable_type => 'PhoneNumber', :ringtoneable_id => sip_account.phone_number_ids + can :manage, Ringtone, :ringtoneable_type => 'SipAccount', :ringtoneable_id => sip_account.id can [:read, :destroy, :call] , CallHistory, :id => sip_account.call_history_ids end can :read, Phone, :phoneable_type => 'User', :phoneable_id => user.id -- cgit v1.2.3 From 22eb173c74893114350e4b5351a58b48673f63b3 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 26 Feb 2013 18:21:52 -0500 Subject: call ability added to SipAccount --- app/models/ability.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/ability.rb b/app/models/ability.rb index e885c53..be64528 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -126,7 +126,7 @@ class Ability # SipAccounts and Phones # - can :read, SipAccount, :sip_accountable_type => 'User', :sip_accountable_id => user.id + can [:read, :call], SipAccount, :sip_accountable_type => 'User', :sip_accountable_id => user.id user.sip_accounts.each do |sip_account| can :read, PhoneNumber, :id => sip_account.phone_number_ids can :manage, CallForward, :call_forwardable_id => sip_account.phone_number_ids -- cgit v1.2.3 From 7f404c454afc6c546fba6885dbcf409f67a73d0f Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Wed, 27 Feb 2013 06:53:20 +0100 Subject: Rights for the call action of a SipAccount. --- app/models/ability.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'app/models') diff --git a/app/models/ability.rb b/app/models/ability.rb index be64528..2e270da 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -169,6 +169,10 @@ class Ability # can :manage, VoicemailMessage can :manage, VoicemailSetting + + # Can initiate a call + # + can :call, SipAccount end end else -- cgit v1.2.3 From 15d5f410afafce67b61a27479a21546cebd48ed9 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Wed, 27 Feb 2013 10:23:26 +0100 Subject: Show a restore link in the setup navigation bar. --- app/models/ability.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'app/models') diff --git a/app/models/ability.rb b/app/models/ability.rb index 2e270da..23af525 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -90,6 +90,11 @@ class Ability # SIM cards # cannot [:edit, :update], SimCard + + # Restore is only possible on a new system. + # + cannot :manage, RestoreJob + else # Any user can do the following stuff. # -- cgit v1.2.3 From cf5938150ba3efc38feaf28f9dee6b174893430e Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Wed, 27 Feb 2013 10:41:20 +0100 Subject: Delete dupe entry. --- app/models/ability.rb | 4 ---- 1 file changed, 4 deletions(-) (limited to 'app/models') diff --git a/app/models/ability.rb b/app/models/ability.rb index 23af525..3ba4481 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -174,10 +174,6 @@ class Ability # can :manage, VoicemailMessage can :manage, VoicemailSetting - - # Can initiate a call - # - can :call, SipAccount end end else -- cgit v1.2.3 From ed0117210837dd1d0d2dbf403799b70225caf0cd Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 27 Feb 2013 06:04:50 -0500 Subject: calls views added --- app/models/call.rb | 39 ++++++++++++++++++++++++++++++++++++--- app/models/sip_account.rb | 2 ++ 2 files changed, 38 insertions(+), 3 deletions(-) (limited to 'app/models') diff --git a/app/models/call.rb b/app/models/call.rb index c0f0f08..db6d9d6 100644 --- a/app/models/call.rb +++ b/app/models/call.rb @@ -1,9 +1,31 @@ class Call < ActiveRecord::Base self.table_name = 'detailed_calls' self.primary_key = 'uuid' + + attr_writer :sip_account_id + + validates :dest, + :presence => true - def readonly? - return true + def create(attributes=nil) + if ! attributes + return + end + + self.sip_account = SipAccount.where(:id => attributes[:sip_account_id]).first + self.dest = attributes[:dest] + return self + end + + def save(attributes=nil) + + end + + def call(number=nil) + if @sip_account && self.dest + return @sip_account.call(self.dest) + end + return false end def destroy @@ -15,15 +37,25 @@ class Call < ActiveRecord::Base return FreeswitchAPI.execute('uuid_kill', self.uuid, true); end + def sip_account=(sip_a) + @sip_account = sip_a + end + def sip_account + if @sip_account + return @sip_account + end + result = self.presence_id.match('^(.+)@(.+)$') if result && ! result[1].blank? and ! result[2].blank? domain = SipDomain.where(:host => result[2]).first if domain - return SipAccount.where(:auth_name => result[1], :sip_domain_id => domain.id).first + @sip_account = SipAccount.where(:auth_name => result[1], :sip_domain_id => domain.id).first end end + + return @sip_account end def sip_account_bleg @@ -69,4 +101,5 @@ class Call < ActiveRecord::Base true end end + end diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index 034af7c..2040b41 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -38,6 +38,8 @@ class SipAccount < ActiveRecord::Base has_many :ringtones, :as => :ringtoneable, :dependent => :destroy + has_many :calls, :finder_sql => lambda { |s| "SELECT DISTINCT detailed_calls.* FROM detailed_calls WHERE presence_id LIKE '#{self.auth_name}@%'" } + # Delegations: # delegate :host, :to => :sip_domain, :allow_nil => true -- cgit v1.2.3