From 6238abea422a1be14d5f3d8cbacd78f2e72fd466 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 28 Feb 2013 09:09:10 -0500 Subject: group defaults --- app/models/group.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'app/models') diff --git a/app/models/group.rb b/app/models/group.rb index e0cfaab..c459530 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -5,6 +5,9 @@ class Group < ActiveRecord::Base has_many :group_permissions, :dependent => :destroy has_many :permittances, :foreign_key => :target_group_id, :class_name => "GroupPermission", :dependent => :destroy + validates :name, + :presence => true + def to_s self.name end -- cgit v1.2.3 From 24fbc181d0f767103b4062be4482af92feb5ffd5 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 28 Feb 2013 22:37:11 +0100 Subject: call forwarding entry scope extended --- 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 a932e11..195ac36 100644 --- a/app/models/call_forward.rb +++ b/app/models/call_forward.rb @@ -177,7 +177,7 @@ class CallForward < ActiveRecord::Base end def deactivate_concurring_entries - 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| + 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, :source => self.source, :active => true).each do |call_forwarding_entry| if call_forwarding_entry.id != self.id call_forwarding_entry.update_attributes(:active => false) end -- cgit v1.2.3 From 6ed538ee9385245a7bbac838dd5b796bba2ea0c6 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Sat, 2 Mar 2013 03:38:16 -0500 Subject: use imagemagick when ghostscript fails --- app/models/fax_document.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/fax_document.rb b/app/models/fax_document.rb index 5b27965..3cb92ea 100644 --- a/app/models/fax_document.rb +++ b/app/models/fax_document.rb @@ -96,8 +96,17 @@ class FaxDocument < ActiveRecord::Base 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" 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}\"" + result = system "cd #{store_dir} && gs -q -r#{self.fax_resolution.resolution_value} -dNOPAUSE -dBATCH -dSAFER -sDEVICE=tiffg3 -sOutputFile=\"#{store_dir}/#{tiff_file}\" -c \"#{page_size_command}\" -- \"#{self.document.to_s}\"" + if !File.exists?("#{store_dir}/#{tiff_file}") + page_size = "1728x1078" or "1728x1186"; + command = "cd #{store_dir} && convert -quiet -density #{self.fax_resolution.resolution_value} -units PixelsPerInch -resize #{page_size}\! -monochrome -compress Fax \"#{self.document.to_s}\" \"#{store_dir}/#{tiff_file}\"" + result = system(command) + if result.nil? + logger.error "### FAX_DOCUMENT_TO_TIFF - error: #{$?}, command: #{command}" + end + end + if !File.exists?("#{store_dir}/#{tiff_file}") return nil end -- cgit v1.2.3 From b8425f5453eab4a0fe475952af89d55ace45878e Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Sun, 3 Mar 2013 04:03:24 -0500 Subject: firewall restart after intruder changes --- app/models/intruder.rb | 86 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 66 insertions(+), 20 deletions(-) (limited to 'app/models') diff --git a/app/models/intruder.rb b/app/models/intruder.rb index 97e3773..9a1c39a 100644 --- a/app/models/intruder.rb +++ b/app/models/intruder.rb @@ -17,6 +17,10 @@ class Intruder < ActiveRecord::Base before_validation :set_key_if_empty + after_create :check_if_new_entry_relevant + after_update :check_if_update_relevant + after_destroy :check_if_delete_relevant + def to_s key end @@ -31,26 +35,6 @@ 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, @@ -72,4 +56,66 @@ class Intruder < ActiveRecord::Base self.key = self.contact_ip end end + + def expand_variables(line, variables) + return line.gsub(/\{([a-z_]+)\}/) do |m| + variables[$1.to_sym] + end + end + + def write_firewall_list + firewall_blacklist_file = GsParameter.get('blacklist_file', 'perimeter', 'general') + blacklist_entry_template = GsParameter.get('blacklist_file_entry', 'perimeter', 'general') + whitelist_entry_template = GsParameter.get('whitelist_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 => ['whitelist', 'blacklist']).order('list_type DESC, contact_last ASC').all.each do |entry| + if !whitelist_entry_template.blank? && entry.list_type == 'whitelist' + if ! comment_template.blank? + file.write(expand_variables(comment_template, entry.to_hash) + "\n") + end + file.write(expand_variables(whitelist_entry_template, entry.to_hash) + "\n") + elsif !blacklist_entry_template.blank? && entry.list_type == 'blacklist' && entry.bans.to_i > 0 + if ! comment_template.blank? + file.write(expand_variables(comment_template, entry.to_hash) + "\n") + end + file.write(expand_variables(blacklist_entry_template, entry.to_hash) + "\n") + end + end + end + end + + def restart_firewall + command = GsParameter.get('ban_command', 'perimeter', 'general') + if !command.blank? + system expand_variables(command, self.to_hash) + end + end + + def check_if_update_relevant + if key_changed? || contact_ip_changed? || list_type_changed? || bans_changed? || points_changed? + if !GsParameter.get("#{self.list_type}_file_entry", 'perimeter', 'general').blank? + write_firewall_list + restart_firewall + end + end + end + + def check_if_new_entry_relevant + if !GsParameter.get("#{self.list_type}_file_entry", 'perimeter', 'general').blank? + if self.list_type != 'blacklist' || self.bans.to_i > 0 + write_firewall_list + restart_firewall + end + end + end + + def check_if_delete_relevant + if !GsParameter.get("#{self.list_type}_file_entry", 'perimeter', 'general').blank? + if self.list_type != 'blacklist' || self.bans.to_i > 0 + write_firewall_list + restart_firewall + end + end + end end -- cgit v1.2.3 From 92b79f7f1f43a9c95fdbb9df2a85b08eefb6c8d8 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 4 Mar 2013 05:27:18 -0500 Subject: presence permission type added --- app/models/group_permission.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/group_permission.rb b/app/models/group_permission.rb index fe988ba..c859f52 100644 --- a/app/models/group_permission.rb +++ b/app/models/group_permission.rb @@ -1,7 +1,7 @@ class GroupPermission < ActiveRecord::Base attr_accessible :group_id, :permission, :target_group_id - PERMISSION_TYPES = ['pickup'] + PERMISSION_TYPES = ['pickup', 'presence'] belongs_to :group belongs_to :target_group, :class_name => "Group" -- cgit v1.2.3 From 5b0c099cebaad0465380458d09aeeec904ae6691 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Mon, 4 Mar 2013 12:04:00 +0100 Subject: rake db:force_now (does a backup without queuing). --- app/models/backup_job.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/backup_job.rb b/app/models/backup_job.rb index a04f6c0..48dd27e 100644 --- a/app/models/backup_job.rb +++ b/app/models/backup_job.rb @@ -12,12 +12,17 @@ class BackupJob < ActiveRecord::Base private def set_state_to_queued - self.state = 'queued' + self.state ||= 'queued' self.started_at = Time.now end def initiate_backup - self.delay.make_a_backup + if self.state == 'force now' + self.state = 'queued' + self.make_a_backup + else + self.delay.make_a_backup + end end def make_a_backup -- cgit v1.2.3 From 2f2276dc424196ace5d1859dfa3d3999926effce Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 5 Mar 2013 01:45:31 -0500 Subject: bypassing softkeys controller --- app/models/softkey.rb | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'app/models') diff --git a/app/models/softkey.rb b/app/models/softkey.rb index 8049456..470605c 100644 --- a/app/models/softkey.rb +++ b/app/models/softkey.rb @@ -22,29 +22,24 @@ class Softkey < ActiveRecord::Base after_save :resync_phone after_destroy :resync_phone - def possible_blf_call_forwards - if self.sip_account.phone_numbers.count == 0 - nil - else - if self.sip_account.callforward_rules_act_per_sip_account == true - # 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(:call_forwardable_id => phone_number.id, :call_forwardable_type => 'PhoneNumber') - else - call_forwards = self.sip_account.call_forwards - end - - phone_numbers_ids = self.sip_account.phone_number_ids - phone_numbers = PhoneNumber.where(:id => phone_numbers_ids).pluck(:number) + def possible_call_forwards + call_forwards = self.sip_account.call_forwards + self.sip_account.phone_numbers.each do |phone_number| + call_forwards = call_forwards + phone_number.call_forwards + end - hunt_group_ids = PhoneNumber.where(:phone_numberable_type => 'HuntGroupMember', :number => phone_numbers). - map{ |phone_number| phone_number.phone_numberable.hunt_group.id }. - uniq - 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 + phone_numbers_ids = self.sip_account.phone_number_ids + phone_numbers = PhoneNumber.where(:id => phone_numbers_ids).pluck(:number) + + hunt_group_ids = PhoneNumber.where(:phone_numberable_type => 'HuntGroupMember', :number => phone_numbers). + map{ |phone_number| phone_number.phone_numberable.hunt_group.id }. + uniq + + call_forwards = 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) + + return call_forwards end def to_s -- cgit v1.2.3 From 860b346781a5c7508ad0158d26f34454be810860 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 6 Mar 2013 03:44:43 -0500 Subject: ringtone and call_forward abilities fixed --- app/models/ability.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'app/models') diff --git a/app/models/ability.rb b/app/models/ability.rb index 48cce84..3cd1d4d 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -134,9 +134,6 @@ 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, :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 @@ -161,10 +158,17 @@ class Ability can :manage, ConferenceInvitee, :conference_id => conference.id end - # User can manage CallForwards of the PhoneNumbers of his - # own SipAccounts: + # User can manage CallForwards of its SipAccount and PhoneNumbers # - can :manage, CallForward, :call_forwardable_id => user.phone_number_ids + can :manage, CallForward, :call_forwardable_type => 'PhoneNumber', :call_forwardable_id => user.phone_number_ids + can :manage, CallForward, :call_forwardable_type => 'SipAccount', :call_forwardable_id => user.sip_account_ids + can :create, CallForward + + # User can manage Ringtones of its SipAccount and PhoneNumbers + # + can :manage, Ringtone, :ringtoneable_type => 'PhoneNumber', :ringtoneable_id => user.phone_number_ids + can :manage, Ringtone, :ringtoneable_type => 'SipAccount', :ringtoneable_id => user.sip_account_ids + can :create, Ringtone # SoftkeyFunctions # -- cgit v1.2.3 From 3c3f90f4b43a41187dd65af3fe08e0409b30b68a Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 6 Mar 2013 09:12:05 -0500 Subject: tenant can have groups --- app/models/tenant.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'app/models') diff --git a/app/models/tenant.rb b/app/models/tenant.rb index 0622f52..ffa68a7 100644 --- a/app/models/tenant.rb +++ b/app/models/tenant.rb @@ -59,6 +59,10 @@ class Tenant < ActiveRecord::Base has_many :users_fax_accounts, :through => :users, :source => :fax_accounts, :readonly => true has_many :users_fax_accounts_phone_numbers, :through => :users_fax_accounts, :source => :phone_numbers, :readonly => true + # Groups + has_many :group_memberships, :as => :item, :dependent => :destroy, :uniq => true + has_many :groups, :through => :group_memberships + # Validations: # validates_presence_of :name, :state, :country, :language -- cgit v1.2.3 From 5ebafb77ecbfdb2cb22a6d3acdd4a9b56dca8ad0 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 6 Mar 2013 09:12:51 -0500 Subject: group methods added --- app/models/group.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'app/models') diff --git a/app/models/group.rb b/app/models/group.rb index c459530..993d274 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -11,4 +11,17 @@ class Group < ActiveRecord::Base def to_s self.name end + + def permission_targets(permission) + group_permissions.where(:permission => permission).pluck(:target_group_id) + end + + def self.union(sets=[]) + group_ids = [] + sets.each do |set| + group_ids = group_ids + set + end + + return group_ids.uniq + end end -- cgit v1.2.3 From bc3f8ae65689046f2b41123c7b392c4718d48dfd Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 6 Mar 2013 09:13:17 -0500 Subject: target_sip_accounts_by_permission method added --- app/models/sip_account.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'app/models') diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index 5660e37..1499d62 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -156,6 +156,24 @@ class SipAccount < ActiveRecord::Base end + def target_sip_accounts_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)}) + sip_accounts = [] + GroupMembership.where(:group_id => target_groups).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 + sip_accounts << group_membership.item + end + + sip_accounts = sip_accounts.uniq + end + + return sip_accounts + end + + private def save_value_of_to_s -- cgit v1.2.3 From c98072557273ff4383013f73621061ece34fc6d2 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 7 Mar 2013 02:36:38 -0500 Subject: call model table changed --- app/models/call.rb | 2 +- app/models/sip_account.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/call.rb b/app/models/call.rb index db6d9d6..b0cd9b2 100644 --- a/app/models/call.rb +++ b/app/models/call.rb @@ -1,5 +1,5 @@ class Call < ActiveRecord::Base - self.table_name = 'detailed_calls' + self.table_name = 'calls_active' self.primary_key = 'uuid' attr_writer :sip_account_id diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index 1499d62..81b9c1c 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -38,7 +38,7 @@ 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}@%' OR b_presence_id LIKE '#{self.auth_name}@%'" } + has_many :calls, :finder_sql => lambda { |s| "SELECT DISTINCT calls_active.* FROM calls_active WHERE sip_account_id = #{self.id} OR b_sip_account_id = #{self.id}" } # Delegations: # -- cgit v1.2.3 From 2964ebf277568536ac215f3a651e1841a73d68f8 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 7 Mar 2013 03:11:28 -0500 Subject: call origination fixed --- app/models/call.rb | 76 +++++++++++++----------------------------------------- 1 file changed, 18 insertions(+), 58 deletions(-) (limited to 'app/models') diff --git a/app/models/call.rb b/app/models/call.rb index b0cd9b2..8f657fa 100644 --- a/app/models/call.rb +++ b/app/models/call.rb @@ -2,29 +2,31 @@ class Call < ActiveRecord::Base self.table_name = 'calls_active' self.primary_key = 'uuid' - attr_writer :sip_account_id + belongs_to :sip_account + belongs_to :b_sip_account, :class_name => SipAccount - validates :dest, + validates :sip_account_id, :presence => 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 + validates :destination, + :presence => true + + def save(attributes=nil) end - def save(attributes=nil) - - end + def call + if self.sip_account && self.destination + return self.sip_account.call(self.destination) + end - def call(number=nil) - if @sip_account && self.dest - return @sip_account.call(self.dest) + if !self.sip_account + errors.add(:sip_account_id, 'no sip_account') end + + if self.destination.blank? + errors.add(:destination, 'no destination') + end + return false end @@ -37,38 +39,6 @@ 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 - @sip_account = SipAccount.where(:auth_name => result[1], :sip_domain_id => domain.id).first - end - end - - return @sip_account - end - - def sip_account_bleg - result = self.b_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 - end - end - end - def get_variable_from_uuid(channel_uuid, variable_name) if channel_uuid.blank? return nil @@ -92,14 +62,4 @@ class Call < ActiveRecord::Base return get_variable_from_uuid(self.b_uuid, variable_name); end - def is_sip - return self.name.match('^sofia') != nil - end - - def is_caller - if (self.uuid == self.call_uuid) || self.call_uuid.blank? - true - end - end - end -- cgit v1.2.3 From 1bcb85853b282606f28f1c9cd7f4e13d494a7290 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 7 Mar 2013 03:44:36 -0500 Subject: presence permissions for softkeys added --- app/models/softkey.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'app/models') diff --git a/app/models/softkey.rb b/app/models/softkey.rb index 470605c..6063017 100644 --- a/app/models/softkey.rb +++ b/app/models/softkey.rb @@ -42,6 +42,10 @@ class Softkey < ActiveRecord::Base return call_forwards end + def possible_blf_sip_accounts + self.sip_account.target_sip_accounts_by_permission('presence') + end + def to_s if self.softkeyable.blank? if ['log_out', 'log_in'].include?(self.softkey_function.name) @@ -77,7 +81,29 @@ class Softkey < ActiveRecord::Base if self.softkey_function_id != nil case self.softkey_function.name when 'blf' + has_permission = false self.softkeyable = PhoneNumber.where(:number => self.number, :phone_numberable_type => 'SipAccount').first.try(:phone_numberable) + if self.softkeyable + self.sip_account.groups.each do |group| + if group.has_permission(self.softkeyable.class.name, self.softkeyable.id, :presence) + has_permission = true + break + end + end + if !has_permission && self.sip_account.sip_accountable + self.sip_account.sip_accountable.groups.each do |group| + if group.has_permission(self.softkeyable.class.name, self.softkeyable.id, :presence) + has_permission = true + break + end + end + end + end + + if !has_permission + self.softkeyable = nil + self.number = nil + end when 'conference' self.softkeyable = PhoneNumber.where(:number => self.number, :phone_numberable_type => 'Conference').first.try(:phone_numberable) when 'call_forwarding' -- cgit v1.2.3 From 88785c0ca2189c47b0a994473ef73a542ed36688 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 7 Mar 2013 03:45:05 -0500 Subject: has_permission method added --- app/models/group.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'app/models') diff --git a/app/models/group.rb b/app/models/group.rb index 993d274..6c65f70 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -16,6 +16,11 @@ class Group < ActiveRecord::Base group_permissions.where(:permission => permission).pluck(:target_group_id) end + def has_permission(target_type, target_id, permission) + target_group_ids = GroupMembership.where(:item_id => target_id, :item_type => target_type).pluck(:group_id) + return group_permissions.where(:permission => permission, :target_group_id => target_group_ids).first != nil + end + def self.union(sets=[]) group_ids = [] sets.each do |set| -- cgit v1.2.3 From 846c6ca704e587621eab0c373693c4f52e4c8433 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Thu, 7 Mar 2013 11:25:33 +0100 Subject: Added a different VIEW definition for sqlite3 and refactored some has_many code for the sip_account. --- app/models/sip_account.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index 81b9c1c..cdb609d 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -38,7 +38,8 @@ class SipAccount < ActiveRecord::Base has_many :ringtones, :as => :ringtoneable, :dependent => :destroy - has_many :calls, :finder_sql => lambda { |s| "SELECT DISTINCT calls_active.* FROM calls_active WHERE sip_account_id = #{self.id} OR b_sip_account_id = #{self.id}" } + has_many :call_legs, :class_name => 'Call' + has_many :b_call_legs, :class_name => 'Call', :foreign_key => 'b_sip_account_id' # Delegations: # @@ -83,6 +84,10 @@ class SipAccount < ActiveRecord::Base def to_s truncate((self.caller_name || "SipAccount ID #{self.id}"), :length => GsParameter.get('TO_S_MAX_CALLER_NAME_LENGTH')) + " (#{truncate(self.auth_name, :length => GsParameter.get('TO_S_MAX_LENGTH_OF_AUTH_NAME'))}@...#{self.host.split(/\./)[2,3].to_a.join('.') if self.host })" end + + def calls + self.call_legs + self.b_call_legs + end def call_forwarding_toggle( call_forwarding_service, to_voicemail = nil ) if ! self.phone_numbers.first -- cgit v1.2.3 From 3e19646f46c772e10ed3d7a45e8c974ab23f625b Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Thu, 7 Mar 2013 11:34:22 +0100 Subject: Added belongs_to :call_route, :touch => true #223 --- app/models/route_element.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/route_element.rb b/app/models/route_element.rb index 94f0f84..7d37db0 100644 --- a/app/models/route_element.rb +++ b/app/models/route_element.rb @@ -3,7 +3,7 @@ class RouteElement < ActiveRecord::Base attr_accessible :call_route_id, :var_in, :var_out, :pattern, :replacement, :action, :mandatory, :position - belongs_to :call_route + belongs_to :call_route, :touch => true acts_as_list :scope => :call_route -- cgit v1.2.3