From 902447a1baf7e9d8385c269a601361c8c3f2f14b Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 12 Feb 2013 13:07:05 +0000 Subject: parking_stall added --- app/models/parking_stall.rb | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 app/models/parking_stall.rb (limited to 'app/models') diff --git a/app/models/parking_stall.rb b/app/models/parking_stall.rb new file mode 100644 index 0000000..52223a8 --- /dev/null +++ b/app/models/parking_stall.rb @@ -0,0 +1,3 @@ +class ParkingStall < ActiveRecord::Base + attr_accessible :name, :lot, :parking_stallable_id, :parking_stallable_type, :comment +end -- cgit v1.2.3 From 36d1a38594361dcd021c23ae9c5040a37d0918df Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 12 Feb 2013 15:53:49 +0100 Subject: make parking stall child of user/tenant --- app/models/parking_stall.rb | 14 ++++++++++++++ app/models/tenant.rb | 2 ++ app/models/user.rb | 2 ++ 3 files changed, 18 insertions(+) (limited to 'app/models') diff --git a/app/models/parking_stall.rb b/app/models/parking_stall.rb index 52223a8..6af1fcd 100644 --- a/app/models/parking_stall.rb +++ b/app/models/parking_stall.rb @@ -1,3 +1,17 @@ class ParkingStall < ActiveRecord::Base attr_accessible :name, :lot, :parking_stallable_id, :parking_stallable_type, :comment + + belongs_to :parking_stallable, :polymorphic => true, :touch => true + + validates :name, + :presence => true, + :uniqueness => true + + validates :lot, + :presence => true + + def to_s + name.to_s + end + end diff --git a/app/models/tenant.rb b/app/models/tenant.rb index 419ac3a..0622f52 100644 --- a/app/models/tenant.rb +++ b/app/models/tenant.rb @@ -39,6 +39,8 @@ class Tenant < ActiveRecord::Base has_many :automatic_call_distributors, :as => :automatic_call_distributorable, :dependent => :destroy has_many :acd_agents, :through => :automatic_call_distributors + has_many :parking_stalls, :as => :parking_stallable, :dependent => :destroy + # Phone numbers of the tenant. # has_many :phone_number_ranges_phone_numbers, :through => :phone_number_ranges, :source => :phone_numbers, :readonly => true diff --git a/app/models/user.rb b/app/models/user.rb index afb3f04..fdcd617 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -87,6 +87,8 @@ class User < ActiveRecord::Base validate :current_tenant_is_included_in_tenants, :if => Proc.new{ |user| user.current_tenant_id } belongs_to :gs_node + + has_many :parking_stalls, :as => :parking_stallable, :dependent => :destroy # Avatar like photo mount_uploader :image, ImageUploader -- cgit v1.2.3 From e7d1428b749024096b9a22b331d110bcf04f87d1 Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 12 Feb 2013 17:02:21 +0100 Subject: filter non-ascii characters --- app/models/intruder.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'app/models') diff --git a/app/models/intruder.rb b/app/models/intruder.rb index db14bf8..8877c4c 100644 --- a/app/models/intruder.rb +++ b/app/models/intruder.rb @@ -18,10 +18,10 @@ class Intruder < ActiveRecord::Base before_validation :set_key_if_empty - def whois - if ! self.contact_ip.blank? + def whois(ip_address = self.contact_ip) + if ! ip_address.blank? begin - return Whois.whois(self.contact_ip) + return Whois.whois(ip_address).to_s.gsub(/[^A-Za-z0-9\:\_\-\ \+\.\,\n]/, '') rescue return nil end -- cgit v1.2.3 From 345c2b2b67cde33de7825a2cde32316900793fe9 Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 12 Feb 2013 23:30:50 +0100 Subject: remove non-ascii characters from whois reply --- app/models/intruder.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/intruder.rb b/app/models/intruder.rb index 8877c4c..249fffc 100644 --- a/app/models/intruder.rb +++ b/app/models/intruder.rb @@ -17,11 +17,14 @@ class Intruder < ActiveRecord::Base before_validation :set_key_if_empty + def to_s + key + end def whois(ip_address = self.contact_ip) if ! ip_address.blank? begin - return Whois.whois(ip_address).to_s.gsub(/[^A-Za-z0-9\:\_\-\ \+\.\,\n]/, '') + return Whois.whois(ip_address).to_s.gsub(/[^\u{0000}-\u{007F}]/, '') rescue return nil end -- cgit v1.2.3 From 6875af1a6f193ecc74653ad9372ab0ef2d0ef85e Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 13 Feb 2013 08:44:45 +0100 Subject: display softkeyable --- app/models/softkey.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'app/models') diff --git a/app/models/softkey.rb b/app/models/softkey.rb index 83c88ab..4b758e0 100644 --- a/app/models/softkey.rb +++ b/app/models/softkey.rb @@ -48,14 +48,14 @@ class Softkey < ActiveRecord::Base end def to_s - if (['call_forwarding'].include?(self.softkey_function.name)) - "#{self.softkeyable}" - else + if self.softkeyable.blank? if ['log_out', 'log_in'].include?(self.softkey_function.name) I18n.t("softkeys.functions.#{self.softkey_function.name}") else - "#{self.softkey_function.name} : #{self.number.to_s}" + "#{self.softkey_function.name} : #{self.number.to_s}" end + else + "#{self.softkeyable}" end end -- cgit v1.2.3 From 14b400d563b2d33706491a20e997a1062b9acc69 Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 13 Feb 2013 10:08:01 +0100 Subject: language_code added to sip_account classes --- app/models/sip_account.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb index 9ba1f8b..7df8e3b 100644 --- a/app/models/sip_account.rb +++ b/app/models/sip_account.rb @@ -6,7 +6,7 @@ class SipAccount < ActiveRecord::Base attr_accessible :auth_name, :caller_name, :password, :voicemail_pin, :tenant_id, :call_waiting, :clir, :clip_no_screening, :clip, :description, :callforward_rules_act_per_sip_account, - :hotdeskable, :gs_node_id + :hotdeskable, :gs_node_id, :language_code # Associations: # @@ -31,6 +31,8 @@ class SipAccount < ActiveRecord::Base belongs_to :gs_node + belongs_to :language, :foreign_key => 'language_code', :primary_key => 'code' + # Delegations: # delegate :host, :to => :sip_domain, :allow_nil => true -- cgit v1.2.3 From 7d5aa2333f61ea8a89d52f09f0719e8cd8973c7f Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Wed, 13 Feb 2013 11:58:17 +0100 Subject: Removed def to_s which was buggy. closes #171 --- app/models/fax_document.rb | 4 ---- 1 file changed, 4 deletions(-) (limited to 'app/models') diff --git a/app/models/fax_document.rb b/app/models/fax_document.rb index be689e2..16fdc70 100644 --- a/app/models/fax_document.rb +++ b/app/models/fax_document.rb @@ -48,10 +48,6 @@ class FaxDocument < ActiveRecord::Base end end - def to_s - name - end - def render_thumbnails directory = "/tmp/GS-#{GsParameter.get('GEMEINSCHAFT_VERSION')}/fax_thumbnails/#{self.id}" system('mkdir -p ' + directory) -- cgit v1.2.3 From 3db09ff394b92b5d168c32c355d4529fd3861d36 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Wed, 13 Feb 2013 15:29:43 +0100 Subject: Improvements in the fax_document model and in FaxDocument#show. --- app/models/fax_document.rb | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'app/models') diff --git a/app/models/fax_document.rb b/app/models/fax_document.rb index 16fdc70..4db4980 100644 --- a/app/models/fax_document.rb +++ b/app/models/fax_document.rb @@ -47,19 +47,21 @@ class FaxDocument < ActiveRecord::Base transition [:new] => :inbound end end + + def to_s + "#{self.remote_station_id}-#{self.created_at}-#{self.id}".gsub(/[^a-zA-Z0-9]/,'') + end def render_thumbnails - directory = "/tmp/GS-#{GsParameter.get('GEMEINSCHAFT_VERSION')}/fax_thumbnails/#{self.id}" - system('mkdir -p ' + directory) - system("cd #{directory} && convert #{Rails.root.to_s}/public#{self.document.to_s}[0-100] -colorspace Gray PNG:'fax_page.png'") - number_of_thumbnails = Dir["#{directory}/fax_page-*.png"].count - (0..(number_of_thumbnails-1)).each do |i| + tmp_dir = "/tmp/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| fax_thumbnail = self.fax_thumbnails.build - fax_thumbnail.thumbnail = File.open("#{directory}/fax_page-#{i}.png") - fax_thumbnail.save! + fax_thumbnail.thumbnail = File.open(thumbnail) + fax_thumbnail.save end - system("rm -rf #{directory}") - self.update_attributes(:document_total_pages => number_of_thumbnails) if self.document_total_pages.nil? + FileUtils.rm_rf tmp_dir end private @@ -67,12 +69,12 @@ class FaxDocument < ActiveRecord::Base 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}" - system('mkdir -p ' + directory) + 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 - system("rm -rf #{directory}") + FileUtils.rm_rf directory end end -- cgit v1.2.3 From ed8e0ac76bddab0d74095313f36bd836d30dcb84 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Wed, 13 Feb 2013 17:33:32 +0100 Subject: The convertion of PDFs to fax thumbnails now gets done by a delayed_job. --- app/models/fax_document.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/fax_document.rb b/app/models/fax_document.rb index 4db4980..564d3bb 100644 --- a/app/models/fax_document.rb +++ b/app/models/fax_document.rb @@ -18,8 +18,8 @@ class FaxDocument < ActiveRecord::Base has_many :fax_thumbnails, :order => :position, :dependent => :destroy - after_create :render_thumbnails after_create :convert_pdf_to_tiff + after_create :render_thumbnails # Scopes scope :inbound, where(:state => 'inbound') @@ -51,8 +51,12 @@ class FaxDocument < ActiveRecord::Base def to_s "#{self.remote_station_id}-#{self.created_at}-#{self.id}".gsub(/[^a-zA-Z0-9]/,'') end - + def render_thumbnails + self.delay.create_thumbnails_and_save_them + end + + def create_thumbnails_and_save_them tmp_dir = "/tmp/fax_convertions/#{self.id}" FileUtils.mkdir_p tmp_dir system("cd #{tmp_dir} && convert #{self.document.path} -colorspace Gray PNG:'fax_page.png'") -- cgit v1.2.3 From 3d11d0a3a047a12bfd40b61252e269cabac76225 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Fri, 15 Feb 2013 14:49:16 +0100 Subject: Basic structure for sim_cards and sim_card_providers. --- app/models/ability.rb | 4 ++++ app/models/sim_card.rb | 25 +++++++++++++++++++++++++ app/models/sim_card_provider.rb | 28 ++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 app/models/sim_card.rb create mode 100644 app/models/sim_card_provider.rb (limited to 'app/models') diff --git a/app/models/ability.rb b/app/models/ability.rb index 4c0844c..d66577d 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -86,6 +86,10 @@ class Ability # An admin can not destroy his/her account # cannot [:destroy], User, :id => user.id + + # SIM cards + # + cannot [:edit, :update], SimCard else # Any user can do the following stuff. # diff --git a/app/models/sim_card.rb b/app/models/sim_card.rb new file mode 100644 index 0000000..2cbf76b --- /dev/null +++ b/app/models/sim_card.rb @@ -0,0 +1,25 @@ +class SimCard < ActiveRecord::Base + attr_accessible :auto_order_card, :sip_account_id, :auth_key, :sim_number + + # Validations + # + validates :sim_card_provider_id, + :presence => true + + belongs_to :sim_card_provider, :touch => true + + validates :sim_card_provider, + :presence => true + + validates :sip_account_id, + :presence => true + + belongs_to :sip_account + + validates :sip_account, + :presence => true + + validates :sim_number, + :presence => true + +end diff --git a/app/models/sim_card_provider.rb b/app/models/sim_card_provider.rb new file mode 100644 index 0000000..854c61a --- /dev/null +++ b/app/models/sim_card_provider.rb @@ -0,0 +1,28 @@ +class SimCardProvider < ActiveRecord::Base + attr_accessible :name, :homepage_url, :docu_url, :api_server_url, :api_username, :api_password, :ref, :sip_server, :include_order_card_function + + # Validations + # + validates :name, + :presence => true, + :uniqueness => true + + validates :api_username, + :presence => true + + validates :api_password, + :presence => true + + validates :api_server_url, + :presence => true + + validates :sip_server, + :presence => true + + has_many :sim_cards, :dependent => :destroy + + def to_s + name.to_s + end + +end -- cgit v1.2.3 From 14e8e9923666991703f747a4abfd6fbfb96d2dc1 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Fri, 15 Feb 2013 15:03:37 +0100 Subject: Show sim_cards of a user. Misc. --- app/models/sim_card.rb | 11 +++++++++++ app/models/user.rb | 4 ++++ 2 files changed, 15 insertions(+) (limited to 'app/models') diff --git a/app/models/sim_card.rb b/app/models/sim_card.rb index 2cbf76b..806beab 100644 --- a/app/models/sim_card.rb +++ b/app/models/sim_card.rb @@ -22,4 +22,15 @@ class SimCard < ActiveRecord::Base validates :sim_number, :presence => true + after_initialize :set_defaults + + def to_s + self.sim_number.to_s + end + + private + def set_defaults + self.state ||= 'not activated' + end + end diff --git a/app/models/user.rb b/app/models/user.rb index fdcd617..6c67351 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -150,6 +150,10 @@ class User < ActiveRecord::Base self.user_groups.include?(UserGroup.find(2)) end + def sim_cards + SimCard.where(:sip_account_id => self.sip_account_ids) + end + private def hash_new_pin -- cgit v1.2.3 From b1cbfe7a7bd5e966be14b71be4e201cc9e2b1aa6 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Fri, 15 Feb 2013 15:56:16 +0100 Subject: Activate a new sim_card. --- app/models/sim_card.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'app/models') diff --git a/app/models/sim_card.rb b/app/models/sim_card.rb index 806beab..2bf7304 100644 --- a/app/models/sim_card.rb +++ b/app/models/sim_card.rb @@ -24,6 +24,9 @@ class SimCard < ActiveRecord::Base after_initialize :set_defaults + before_validation :upcase_some_values + after_create :active_sim_card + def to_s self.sim_number.to_s end @@ -33,4 +36,28 @@ class SimCard < ActiveRecord::Base self.state ||= 'not activated' end + def upcase_some_values + self.sim_number = self.sim_number.to_s.upcase + end + + def active_sim_card + require 'open-uri' + + url = "#{self.sim_card_provider.api_server_url}/app/api/main?cmd=order&ref=#{self.sim_number}&s=#{self.sim_card_provider.sip_server}&u=#{self.sip_account.auth_name}&p=#{self.sip_account.password}&ordercard=0&apiuser=#{self.sim_card_provider.api_username}&apipass=#{self.sim_card_provider.api_password}" + + open(url, "User-Agent" => "Ruby/#{RUBY_VERSION}", + "From" => "admin@localhost", + "Referer" => "http://amooma.com/gemeinschaft/gs5") { |f| + # Save the response body + @response = f.read + } + + if @response.class == String && @response.split(/;/).first == 'OK' + self.state = 'activated' + self.auth_key = @response.split(/;/).last.chomp.split(/=/).last + self.save + end + + end + end -- cgit v1.2.3