summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/ability.rb4
-rw-r--r--app/models/fax_document.rb32
-rw-r--r--app/models/intruder.rb9
-rw-r--r--app/models/parking_stall.rb17
-rw-r--r--app/models/sim_card.rb63
-rw-r--r--app/models/sim_card_provider.rb28
-rw-r--r--app/models/sip_account.rb4
-rw-r--r--app/models/softkey.rb8
-rw-r--r--app/models/tenant.rb2
-rw-r--r--app/models/user.rb6
10 files changed, 150 insertions, 23 deletions
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/fax_document.rb b/app/models/fax_document.rb
index be689e2..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')
@@ -47,23 +47,25 @@ class FaxDocument < ActiveRecord::Base
transition [:new] => :inbound
end
end
-
+
def to_s
- name
+ "#{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|
+ 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'")
+ 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
@@ -71,12 +73,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
diff --git a/app/models/intruder.rb b/app/models/intruder.rb
index db14bf8..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
- 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(/[^\u{0000}-\u{007F}]/, '')
rescue
return nil
end
diff --git a/app/models/parking_stall.rb b/app/models/parking_stall.rb
new file mode 100644
index 0000000..6af1fcd
--- /dev/null
+++ b/app/models/parking_stall.rb
@@ -0,0 +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/sim_card.rb b/app/models/sim_card.rb
new file mode 100644
index 0000000..2bf7304
--- /dev/null
+++ b/app/models/sim_card.rb
@@ -0,0 +1,63 @@
+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
+
+ after_initialize :set_defaults
+
+ before_validation :upcase_some_values
+ after_create :active_sim_card
+
+ def to_s
+ self.sim_number.to_s
+ end
+
+ private
+ def set_defaults
+ 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
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
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
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
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..6c67351 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
@@ -148,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