From 4f89e10f2aaeeeb2696f8e456149e8f66e7bb02b Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Mon, 18 Feb 2013 11:19:06 +0100 Subject: change fax spool directory --- app/controllers/trigger_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/controllers/trigger_controller.rb b/app/controllers/trigger_controller.rb index 2b491be..9a03979 100644 --- a/app/controllers/trigger_controller.rb +++ b/app/controllers/trigger_controller.rb @@ -1,7 +1,7 @@ class TriggerController < ApplicationController TIFF_FUFFIX = ".tiff" PDF_SUFFIX = ".pdf" - TMP_DIR = "/tmp/" + TMP_DIR = "/var/spool/freeswitch/" def voicemail if !params[:sip_account_id].blank? -- cgit v1.2.3 From 45855989c9f1b9122d57f3328102730b49236432 Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 18 Feb 2013 12:11:56 +0100 Subject: indent --- app/controllers/config_snom_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/controllers/config_snom_controller.rb b/app/controllers/config_snom_controller.rb index 76fa633..eb94038 100644 --- a/app/controllers/config_snom_controller.rb +++ b/app/controllers/config_snom_controller.rb @@ -799,7 +799,7 @@ AAAA' end phone_book_entry.phone_numbers.each do |phone_number| if phone_book_entry.phone_numbers.count > 1 - entry_name = " #{phone_number.name} #{phone_number.number}" + entry_name = "- #{phone_number.name} #{phone_number.number}" else entry_name = "#{phone_book_entry.to_s} #{phone_number.number}" end -- cgit v1.2.3 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/controllers/trigger_controller.rb | 31 ++++++------------------------- app/models/fax_document.rb | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 25 deletions(-) (limited to 'app') diff --git a/app/controllers/trigger_controller.rb b/app/controllers/trigger_controller.rb index 9a03979..7840498 100644 --- a/app/controllers/trigger_controller.rb +++ b/app/controllers/trigger_controller.rb @@ -1,7 +1,4 @@ class TriggerController < ApplicationController - TIFF_FUFFIX = ".tiff" - PDF_SUFFIX = ".pdf" - TMP_DIR = "/var/spool/freeswitch/" def voicemail if !params[:sip_account_id].blank? @@ -68,25 +65,9 @@ class TriggerController < ApplicationController if fax_account fax_account.fax_documents.where(:state => 'received').each do |fax_document| - tiff_file = File.basename(fax_document.tiff.to_s) + pdf_file, tiff_file = fax_document.tiff_to_pdf.blank? - if !File.exists?( "#{TMP_DIR}#{tiff_file}" ) - fax_document.state = 'unsuccessful' - fax_document.save - next - end - - paper_size = "letter" - pdf_file = "#{TMP_DIR}#{File.basename(tiff_file, TIFF_FUFFIX)}#{PDF_SUFFIX}" - - system "tiff2pdf \\ - -o \"#{pdf_file}\" \\ - -p #{paper_size} \\ - -a \"#{fax_document.remote_station_id}\" \\ - -c \"AMOOMA Gemeinschaft version #{GsParameter.get('GEMEINSCHAFT_VERSION')}\" \\ - -t \"#{fax_document.remote_station_id}\" \"#{TMP_DIR}#{tiff_file}\"" - - if !File.exists?( pdf_file ) + if !pdf_file fax_document.state = 'unsuccessful' fax_document.save next @@ -98,14 +79,14 @@ class TriggerController < ApplicationController if fax_document.save Notifications.new_fax(fax_document).deliver begin - File.delete("#{TMP_DIR}#{tiff_file}"); + File.delete(tiff_file) rescue => e - logger.error "Raw fax file could not be deleted: #{TMP_DIR}#{tiff_file} => #{e.inspect}" + logger.error "Raw fax file could not be deleted: #{tiff_file} => #{e.inspect}" end begin - File.delete(pdf_file); + File.delete(pdf_file) rescue => e - logger.error "PDF fax file could not be deleted: #{TMP_DIR}#{pdf_file} => #{e.inspect}" + logger.error "PDF fax file could not be deleted: #{pdf_file} => #{e.inspect}" end fax_document.tiff = nil fax_document.save 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') 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 e0bd56db83104a2a38e88af2eadaefd389aa798b Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 18 Feb 2013 13:17:16 +0100 Subject: result fixed --- app/controllers/trigger_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/controllers/trigger_controller.rb b/app/controllers/trigger_controller.rb index 7840498..136c3d0 100644 --- a/app/controllers/trigger_controller.rb +++ b/app/controllers/trigger_controller.rb @@ -65,7 +65,7 @@ class TriggerController < ApplicationController if fax_account fax_account.fax_documents.where(:state => 'received').each do |fax_document| - pdf_file, tiff_file = fax_document.tiff_to_pdf.blank? + pdf_file, tiff_file = fax_document.tiff_to_pdf if !pdf_file fax_document.state = 'unsuccessful' -- 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 ++ app/views/phone_numbers/_form_core.html.haml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'app') 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 diff --git a/app/views/phone_numbers/_form_core.html.haml b/app/views/phone_numbers/_form_core.html.haml index a0a69db..1589e7e 100644 --- a/app/views/phone_numbers/_form_core.html.haml +++ b/app/views/phone_numbers/_form_core.html.haml @@ -1,7 +1,7 @@ .inputs - if @phone_book_entry - = f.input :name, :collection => ['Office', 'Home', 'Mobile', 'Fax'], :include_blank => false, :label => t('phone_numbers.form.name.label'), :hint => conditional_hint('phone_numbers.form.name.hint') + = f.input :name, :collection => PhoneBookEntry::PHONE_NUMBER_NAMES, :include_blank => false, :label => t('phone_numbers.form.name.label'), :hint => conditional_hint('phone_numbers.form.name.hint') = f.input :number, :label => t('phone_numbers.form.number.label'), :hint => conditional_hint('phone_numbers.form.number.hint'), :autofocus => true - else - if @callthrough || @hunt_group_member || @access_authorization || current_user.current_tenant.array_of_available_internal_extensions_and_dids.count == 0 || current_user.current_tenant.array_of_available_internal_extensions_and_dids.count > 250 -- 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/controllers/trigger_controller.rb | 2 +- app/models/fax_document.rb | 55 ++++++++++++++++++--------- app/uploaders/fax_document_uploader.rb | 19 +++++++++ app/views/fax_documents/_index_core.html.haml | 2 +- app/views/fax_documents/show.html.haml | 2 +- 5 files changed, 58 insertions(+), 22 deletions(-) create mode 100644 app/uploaders/fax_document_uploader.rb (limited to 'app') diff --git a/app/controllers/trigger_controller.rb b/app/controllers/trigger_controller.rb index 136c3d0..894c18b 100644 --- a/app/controllers/trigger_controller.rb +++ b/app/controllers/trigger_controller.rb @@ -65,7 +65,7 @@ class TriggerController < ApplicationController if fax_account fax_account.fax_documents.where(:state => 'received').each do |fax_document| - pdf_file, tiff_file = fax_document.tiff_to_pdf + pdf_file = fax_document.tiff_to_pdf if !pdf_file fax_document.state = 'unsuccessful' 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 diff --git a/app/uploaders/fax_document_uploader.rb b/app/uploaders/fax_document_uploader.rb new file mode 100644 index 0000000..bfb7e07 --- /dev/null +++ b/app/uploaders/fax_document_uploader.rb @@ -0,0 +1,19 @@ +# encoding: utf-8 + +class FaxDocumentUploader < CarrierWave::Uploader::Base + include CarrierWave::MiniMagick + + storage :file + + def store_dir + model.store_dir + end + + def cache_dir + '/tmp/gs_fax_uploader' + end + + def extension_white_list + %w(pdf ps jpg jpeg gif png tif tiff) + end +end diff --git a/app/views/fax_documents/_index_core.html.haml b/app/views/fax_documents/_index_core.html.haml index 5355521..2f9b214 100644 --- a/app/views/fax_documents/_index_core.html.haml +++ b/app/views/fax_documents/_index_core.html.haml @@ -50,7 +50,7 @@ - if fax_document.document? %p - %a{:href => fax_document.document.url} + %a{:href => fax_account_fax_document_path(@fax_account, fax_document, :format => :pdf), :method => :get} %i{:class => 'icon-download'} = t("fax_documents.index.actions.download_pdf") + " (#{number_to_human_size(fax_document.document.size, :precision => 2)})" diff --git a/app/views/fax_documents/show.html.haml b/app/views/fax_documents/show.html.haml index 9925c2f..b8f3e9e 100644 --- a/app/views/fax_documents/show.html.haml +++ b/app/views/fax_documents/show.html.haml @@ -46,7 +46,7 @@ - if @fax_document.document? %p - %a{:href => @fax_document.document.url} + %a{:href => fax_account_fax_document_path(@fax_account, @fax_document, :format => :pdf), :method => :get} %i{:class => 'icon-download'} = t("fax_documents.index.actions.download_pdf") + " (#{number_to_human_size(@fax_document.document.size, :precision => 2)})" -- 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/controllers/trigger_controller.rb | 13 +++++++------ app/models/fax_document.rb | 12 ++++++++++-- 2 files changed, 17 insertions(+), 8 deletions(-) (limited to 'app') diff --git a/app/controllers/trigger_controller.rb b/app/controllers/trigger_controller.rb index 894c18b..64a5f91 100644 --- a/app/controllers/trigger_controller.rb +++ b/app/controllers/trigger_controller.rb @@ -73,16 +73,17 @@ class TriggerController < ApplicationController next end + working_path, tiff_file = File.split(fax_document.tiff) + if fax_document.store_dir != working_path + FileUtils.mkdir(fax_document.store_dir) + FileUtils.mv(fax_document.tiff, fax_document.store_dir) + fax_document.tiff = "#{fax_document.store_dir}/#{tiff_file}" + end + fax_document.document = File.open(pdf_file) fax_document.state = 'successful' if fax_document.save - Notifications.new_fax(fax_document).deliver - begin - File.delete(tiff_file) - rescue => e - logger.error "Raw fax file could not be deleted: #{tiff_file} => #{e.inspect}" - end begin File.delete(pdf_file) rescue => e 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 4715082b46073d7ca4108b1093d2304eb5999e1b Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 19 Feb 2013 14:09:11 +0100 Subject: tiff download --- app/controllers/fax_documents_controller.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'app') diff --git a/app/controllers/fax_documents_controller.rb b/app/controllers/fax_documents_controller.rb index 5653683..c2b3083 100644 --- a/app/controllers/fax_documents_controller.rb +++ b/app/controllers/fax_documents_controller.rb @@ -31,6 +31,24 @@ class FaxDocumentsController < ApplicationController ) end } + format.tiff { + caller_number = @fax_document.caller_id_number.to_s.gsub(/[^0-9]/, '') + if caller_number.blank? + caller_number = 'anonymous' + end + + if @fax_document.tiff + send_file @fax_document.tiff, :type => "image/tiff", + :filename => "#{@fax_document.created_at.strftime('%Y%m%d-%H%M%S')}-#{caller_number}.tiff" + else + render( + :status => 404, + :layout => false, + :content_type => 'text/plain', + :text => "", + ) + end + } end end -- cgit v1.2.3 From e702dcbd01feccadc3d8d070448597ed63bb642d Mon Sep 17 00:00:00 2001 From: "Mario \"Kuroir\" Ricalde" Date: Tue, 19 Feb 2013 23:49:58 -0600 Subject: Makes Forms responsive again. --- app/assets/stylesheets/gemeinschaft-generic.css.scss | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'app') diff --git a/app/assets/stylesheets/gemeinschaft-generic.css.scss b/app/assets/stylesheets/gemeinschaft-generic.css.scss index fbeaa1f..7077c87 100644 --- a/app/assets/stylesheets/gemeinschaft-generic.css.scss +++ b/app/assets/stylesheets/gemeinschaft-generic.css.scss @@ -25,6 +25,23 @@ li.display { } input, textarea, .uneditable-input { width: 500px; + @media (max-width: 979px) { + width: 200px; + } + @media (max-width: 480px) { + width: 96%; + } +} + +select { + width: 520px; + @media (max-width: 979px) { + width: 220px; + } + @media (max-width: 480px) { + width: 99.5%; + } + } @media (max-width: 979px) { -- cgit v1.2.3 From cb0d2acf3cd0c6a8e07ef564ac906fe623673978 Mon Sep 17 00:00:00 2001 From: "Mario \"Kuroir\" Ricalde" Date: Wed, 20 Feb 2013 01:15:26 -0600 Subject: Immediate Feedback for Inputs that are Missing --- app/assets/javascripts/forms.js.coffee | 11 +++++++++++ app/assets/stylesheets/gemeinschaft-generic.css.scss | 5 +++++ 2 files changed, 16 insertions(+) create mode 100644 app/assets/javascripts/forms.js.coffee (limited to 'app') diff --git a/app/assets/javascripts/forms.js.coffee b/app/assets/javascripts/forms.js.coffee new file mode 100644 index 0000000..42b1c45 --- /dev/null +++ b/app/assets/javascripts/forms.js.coffee @@ -0,0 +1,11 @@ +# Simple Form Toggle for required fields +$(document).ready -> + validate_fields = (obj)-> + if ($(obj).val() == "") + $(obj).addClass "invalid" + else + $(obj).removeClass "invalid" + + sel = "input.required, textarea.required" + $(sel).each (i, e)-> validate_fields(e) + $(sel).keyup -> validate_fields(this) diff --git a/app/assets/stylesheets/gemeinschaft-generic.css.scss b/app/assets/stylesheets/gemeinschaft-generic.css.scss index 7077c87..9448b84 100644 --- a/app/assets/stylesheets/gemeinschaft-generic.css.scss +++ b/app/assets/stylesheets/gemeinschaft-generic.css.scss @@ -32,6 +32,11 @@ input, textarea, .uneditable-input { width: 96%; } } +input, textarea { + &.invalid { + box-shadow: inset -9px 0px 0px rgb(255, 219, 219), inset -14px 0px 0px rgb(255, 245, 245) !important; + } +} select { width: 520px; -- 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') 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') 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/controllers/group_memberships_controller.rb | 51 +++++++++++++++++++++++ app/controllers/group_permissions_controller.rb | 48 +++++++++++++++++++++ app/controllers/groups_controller.rb | 49 ++++++++++++++++++++++ app/helpers/group_memberships_helper.rb | 2 + app/helpers/group_permissions_helper.rb | 2 + app/helpers/groups_helper.rb | 2 + app/models/group.rb | 11 +++++ app/models/group_membership.rb | 37 ++++++++++++++++ app/models/group_permission.rb | 24 +++++++++++ app/views/group_memberships/_form.html.haml | 7 ++++ app/views/group_memberships/_form_core.html.haml | 4 ++ app/views/group_memberships/_index_core.html.haml | 11 +++++ app/views/group_memberships/edit.html.haml | 3 ++ app/views/group_memberships/index.html.haml | 6 +++ app/views/group_memberships/new.html.haml | 3 ++ app/views/group_memberships/show.html.haml | 10 +++++ app/views/group_permissions/_form.html.haml | 7 ++++ app/views/group_permissions/_form_core.html.haml | 3 ++ app/views/group_permissions/_index_core.html.haml | 11 +++++ app/views/group_permissions/edit.html.haml | 3 ++ app/views/group_permissions/index.html.haml | 6 +++ app/views/group_permissions/new.html.haml | 3 ++ app/views/group_permissions/show.html.haml | 10 +++++ app/views/groups/_form.html.haml | 7 ++++ app/views/groups/_form_core.html.haml | 4 ++ app/views/groups/_index_core.html.haml | 13 ++++++ app/views/groups/edit.html.haml | 3 ++ app/views/groups/index.html.haml | 6 +++ app/views/groups/new.html.haml | 3 ++ app/views/groups/show.html.haml | 25 +++++++++++ 30 files changed, 374 insertions(+) create mode 100644 app/controllers/group_memberships_controller.rb create mode 100644 app/controllers/group_permissions_controller.rb create mode 100644 app/controllers/groups_controller.rb create mode 100644 app/helpers/group_memberships_helper.rb create mode 100644 app/helpers/group_permissions_helper.rb create mode 100644 app/helpers/groups_helper.rb create mode 100644 app/models/group.rb create mode 100644 app/models/group_membership.rb create mode 100644 app/models/group_permission.rb create mode 100644 app/views/group_memberships/_form.html.haml create mode 100644 app/views/group_memberships/_form_core.html.haml create mode 100644 app/views/group_memberships/_index_core.html.haml create mode 100644 app/views/group_memberships/edit.html.haml create mode 100644 app/views/group_memberships/index.html.haml create mode 100644 app/views/group_memberships/new.html.haml create mode 100644 app/views/group_memberships/show.html.haml create mode 100644 app/views/group_permissions/_form.html.haml create mode 100644 app/views/group_permissions/_form_core.html.haml create mode 100644 app/views/group_permissions/_index_core.html.haml create mode 100644 app/views/group_permissions/edit.html.haml create mode 100644 app/views/group_permissions/index.html.haml create mode 100644 app/views/group_permissions/new.html.haml create mode 100644 app/views/group_permissions/show.html.haml create mode 100644 app/views/groups/_form.html.haml create mode 100644 app/views/groups/_form_core.html.haml create mode 100644 app/views/groups/_index_core.html.haml create mode 100644 app/views/groups/edit.html.haml create mode 100644 app/views/groups/index.html.haml create mode 100644 app/views/groups/new.html.haml create mode 100644 app/views/groups/show.html.haml (limited to 'app') diff --git a/app/controllers/group_memberships_controller.rb b/app/controllers/group_memberships_controller.rb new file mode 100644 index 0000000..df9f6b3 --- /dev/null +++ b/app/controllers/group_memberships_controller.rb @@ -0,0 +1,51 @@ +class GroupMembershipsController < ApplicationController + load_and_authorize_resource :group + load_and_authorize_resource :group_membership, :through => [:group] + + def index + end + + def show + end + + def new + end + + def create + if params[:group_membership][:item_type].blank? + params[:group_membership][:item_type] = @group.group_memberships.first.item_type + end + @group_membership = @group.group_memberships.new(params[:group_membership]) + if @group_membership.save + redirect_to action: "index", :notice => t('group_memberships.controller.successfuly_created') + else + render :new + end + end + + def edit + end + + def update + if @group_membership.update_attributes(params[:group_membership]) + redirect_to action: "index", :notice => t('group_memberships.controller.successfuly_updated') + else + render :edit + end + end + + def destroy + @group_membership.destroy + redirect_to action: "index", :notice => t('group_memberships.controller.successfuly_destroyed') + end + + private + def spread_breadcrumbs + add_breadcrumb t("groups.index.page_title"), groups_path + add_breadcrumb @group, group_path(@group) + add_breadcrumb t("group_memberships.index.page_title"), group_group_memberships_path(@group) + if @group_membership && !@group_membership.new_record? + add_breadcrumb @group_membership, group_group_membership_path(@group, @group_membership) + end + end +end diff --git a/app/controllers/group_permissions_controller.rb b/app/controllers/group_permissions_controller.rb new file mode 100644 index 0000000..3abdc51 --- /dev/null +++ b/app/controllers/group_permissions_controller.rb @@ -0,0 +1,48 @@ +class GroupPermissionsController < ApplicationController + load_and_authorize_resource :group + load_and_authorize_resource :group_permission, :through => [:group] + + def index + end + + def show + end + + def new + end + + def create + @group_permission = @group.group_permissions.new(params[:group_permission]) + if @group_permission.save + redirect_to action: "index", :notice => t('group_permissions.controller.successfuly_created') + else + render :new + end + end + + def edit + end + + def update + if @group_permission.update_attributes(params[:group_permission]) + redirect_to action: "index", :notice => t('group_permissions.controller.successfuly_updated') + else + render :edit + end + end + + def destroy + @group_permission.destroy + redirect_to action: "index", :notice => t('group_permissions.controller.successfuly_destroyed') + end + + private + def spread_breadcrumbs + add_breadcrumb t("groups.index.page_title"), groups_path + add_breadcrumb @group, group_path(@group) + add_breadcrumb t("group_permissions.index.page_title"), group_group_permissions_path(@group) + if @group_permission && !@group_permission.new_record? + add_breadcrumb @group_permission, group_group_permission_path(@group, @group_permission) + end + end +end diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb new file mode 100644 index 0000000..1ab7a4f --- /dev/null +++ b/app/controllers/groups_controller.rb @@ -0,0 +1,49 @@ +class GroupsController < ApplicationController + def index + @groups = Group.all + end + + def show + @group = Group.find(params[:id]) + end + + def new + @group = Group.new + end + + def create + @group = Group.new(params[:group]) + if @group.save + redirect_to @group, :notice => t('groups.controller.successfuly_created') + else + render :new + end + end + + def edit + @group = Group.find(params[:id]) + end + + def update + @group = Group.find(params[:id]) + if @group.update_attributes(params[:group]) + redirect_to @group, :notice => t('groups.controller.successfuly_updated') + else + render :edit + end + end + + def destroy + @group = Group.find(params[:id]) + @group.destroy + redirect_to groups_url, :notice => t('groups.controller.successfuly_destroyed') + end + + private + def spread_breadcrumbs + add_breadcrumb t("groups.index.page_title"), groups_path + if @group && !@group.new_record? + add_breadcrumb @group, @group + end + end +end diff --git a/app/helpers/group_memberships_helper.rb b/app/helpers/group_memberships_helper.rb new file mode 100644 index 0000000..837bafd --- /dev/null +++ b/app/helpers/group_memberships_helper.rb @@ -0,0 +1,2 @@ +module GroupMembershipsHelper +end diff --git a/app/helpers/group_permissions_helper.rb b/app/helpers/group_permissions_helper.rb new file mode 100644 index 0000000..45571d0 --- /dev/null +++ b/app/helpers/group_permissions_helper.rb @@ -0,0 +1,2 @@ +module GroupPermissionsHelper +end diff --git a/app/helpers/groups_helper.rb b/app/helpers/groups_helper.rb new file mode 100644 index 0000000..c091b2f --- /dev/null +++ b/app/helpers/groups_helper.rb @@ -0,0 +1,2 @@ +module GroupsHelper +end 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 diff --git a/app/views/group_memberships/_form.html.haml b/app/views/group_memberships/_form.html.haml new file mode 100644 index 0000000..c8a6a51 --- /dev/null +++ b/app/views/group_memberships/_form.html.haml @@ -0,0 +1,7 @@ += simple_form_for([@group, @group_membership]) do |f| + = f.error_notification + + = render "form_core", :f => f + + .form-actions + = f.button :submit, conditional_t('group_memberships.form.submit') diff --git a/app/views/group_memberships/_form_core.html.haml b/app/views/group_memberships/_form_core.html.haml new file mode 100644 index 0000000..4a28a06 --- /dev/null +++ b/app/views/group_memberships/_form_core.html.haml @@ -0,0 +1,4 @@ +.inputs + - if @group.group_memberships.count < 1 + = f.input :item_type, :label => t('group_memberships.form.item_type.label'), :hint => conditional_hint('group_memberships.form.item_type.hint') + = f.input :item_id, :label => t('group_memberships.form.item_id.label'), :hint => conditional_hint('group_memberships.form.item_id.hint') diff --git a/app/views/group_memberships/_index_core.html.haml b/app/views/group_memberships/_index_core.html.haml new file mode 100644 index 0000000..beeefc9 --- /dev/null +++ b/app/views/group_memberships/_index_core.html.haml @@ -0,0 +1,11 @@ +%table.table.table-striped + %tr + %th= t('group_memberships.index.item_type') + %th= t('group_memberships.index.item_id') + + + - for group_membership in group_memberships + %tr + %td= group_membership.item_type + %td= group_membership.item_id + =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => group_membership.group, :child => group_membership} diff --git a/app/views/group_memberships/edit.html.haml b/app/views/group_memberships/edit.html.haml new file mode 100644 index 0000000..643c095 --- /dev/null +++ b/app/views/group_memberships/edit.html.haml @@ -0,0 +1,3 @@ +- content_for :title, t("group_memberships.edit.page_title") + += render "form" \ No newline at end of file diff --git a/app/views/group_memberships/index.html.haml b/app/views/group_memberships/index.html.haml new file mode 100644 index 0000000..b493017 --- /dev/null +++ b/app/views/group_memberships/index.html.haml @@ -0,0 +1,6 @@ +- content_for :title, t("group_memberships.index.page_title") + +- if @group_memberships && @group_memberships.count > 0 + = render "index_core", :group_memberships => @group_memberships + += render :partial => 'shared/create_link', :locals => {:parent => @group, :child_class => GroupMembership} diff --git a/app/views/group_memberships/new.html.haml b/app/views/group_memberships/new.html.haml new file mode 100644 index 0000000..6cf2ce7 --- /dev/null +++ b/app/views/group_memberships/new.html.haml @@ -0,0 +1,3 @@ +- content_for :title, t("group_memberships.new.page_title") + += render "form" \ No newline at end of file diff --git a/app/views/group_memberships/show.html.haml b/app/views/group_memberships/show.html.haml new file mode 100644 index 0000000..0875f0b --- /dev/null +++ b/app/views/group_memberships/show.html.haml @@ -0,0 +1,10 @@ +- content_for :title, t("group_memberships.show.page_title") + +%p + %strong= t('group_memberships.show.item_type') + ":" + = @group_membership.item_type +%p + %strong= t('group_memberships.show.item_id') + ":" + = @group_membership.item_id + += render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @group, :child => @group_membership } diff --git a/app/views/group_permissions/_form.html.haml b/app/views/group_permissions/_form.html.haml new file mode 100644 index 0000000..5f593f2 --- /dev/null +++ b/app/views/group_permissions/_form.html.haml @@ -0,0 +1,7 @@ += simple_form_for([@group, @group_permission]) do |f| + = f.error_notification + + = render "form_core", :f => f + + .form-actions + = f.button :submit, conditional_t('group_permissions.form.submit') diff --git a/app/views/group_permissions/_form_core.html.haml b/app/views/group_permissions/_form_core.html.haml new file mode 100644 index 0000000..49c9e7c --- /dev/null +++ b/app/views/group_permissions/_form_core.html.haml @@ -0,0 +1,3 @@ +.inputs + = f.input :permission, :collection => GroupPermission::PERMISSION_TYPES, :label => t('group_permissions.form.permission.label'), :hint => conditional_hint('group_permissions.form.permission.hint'), :include_blank => false + = f.input :target_group_id, :collection => Group.all.collect, :label => t('group_permissions.form.target_group_id.label'), :hint => conditional_hint('group_permissions.form.target_group_id.hint'), :include_blank => false diff --git a/app/views/group_permissions/_index_core.html.haml b/app/views/group_permissions/_index_core.html.haml new file mode 100644 index 0000000..ad06b38 --- /dev/null +++ b/app/views/group_permissions/_index_core.html.haml @@ -0,0 +1,11 @@ +%table.table.table-striped + %tr + %th= t('group_permissions.index.permission') + %th= t('group_permissions.index.target_group_id') + + + - for group_permission in group_permissions + %tr + %td= group_permission.permission + %td= group_permission.target_group + =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => group_permission.group, :child => group_permission} diff --git a/app/views/group_permissions/edit.html.haml b/app/views/group_permissions/edit.html.haml new file mode 100644 index 0000000..c673eea --- /dev/null +++ b/app/views/group_permissions/edit.html.haml @@ -0,0 +1,3 @@ +- content_for :title, t("group_permissions.edit.page_title") + += render "form" \ No newline at end of file diff --git a/app/views/group_permissions/index.html.haml b/app/views/group_permissions/index.html.haml new file mode 100644 index 0000000..0bc0c37 --- /dev/null +++ b/app/views/group_permissions/index.html.haml @@ -0,0 +1,6 @@ +- content_for :title, t("group_permissions.index.page_title") + +- if @group_permissions && @group_permissions.count > 0 + = render "index_core", :group_permissions => @group_permissions + += render :partial => 'shared/create_link', :locals => {:parent => @group, :child_class => GroupPermission} \ No newline at end of file diff --git a/app/views/group_permissions/new.html.haml b/app/views/group_permissions/new.html.haml new file mode 100644 index 0000000..8012273 --- /dev/null +++ b/app/views/group_permissions/new.html.haml @@ -0,0 +1,3 @@ +- content_for :title, t("group_permissions.new.page_title") + += render "form" \ No newline at end of file diff --git a/app/views/group_permissions/show.html.haml b/app/views/group_permissions/show.html.haml new file mode 100644 index 0000000..402c5ce --- /dev/null +++ b/app/views/group_permissions/show.html.haml @@ -0,0 +1,10 @@ +- content_for :title, t("group_permissions.show.page_title") + +%p + %strong= t('group_permissions.show.permission') + ":" + = @group_permission.permission +%p + %strong= t('group_permissions.show.target_group_id') + ":" + = @group_permission.target_group_id + += render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @group, :child => @group_permission } diff --git a/app/views/groups/_form.html.haml b/app/views/groups/_form.html.haml new file mode 100644 index 0000000..f5bdece --- /dev/null +++ b/app/views/groups/_form.html.haml @@ -0,0 +1,7 @@ += simple_form_for(@group) do |f| + = f.error_notification + + = render "form_core", :f => f + + .form-actions + = f.button :submit, conditional_t('groups.form.submit') diff --git a/app/views/groups/_form_core.html.haml b/app/views/groups/_form_core.html.haml new file mode 100644 index 0000000..1f9a39f --- /dev/null +++ b/app/views/groups/_form_core.html.haml @@ -0,0 +1,4 @@ +.inputs + = f.input :name, :label => t('groups.form.name.label'), :hint => conditional_hint('groups.form.name.hint') + = f.input :active, :label => t('groups.form.active.label'), :hint => conditional_hint('groups.form.active.hint') + = f.input :comment, :label => t('groups.form.comment.label'), :hint => conditional_hint('groups.form.comment.hint') diff --git a/app/views/groups/_index_core.html.haml b/app/views/groups/_index_core.html.haml new file mode 100644 index 0000000..d99874a --- /dev/null +++ b/app/views/groups/_index_core.html.haml @@ -0,0 +1,13 @@ +%table.table.table-striped + %tr + %th= t('groups.index.name') + %th= t('groups.index.active') + %th= t('groups.index.comment') + + + - for group in groups + %tr + %td= group.name + %td= group.active + %td= group.comment + =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => group} \ No newline at end of file diff --git a/app/views/groups/edit.html.haml b/app/views/groups/edit.html.haml new file mode 100644 index 0000000..7a3f784 --- /dev/null +++ b/app/views/groups/edit.html.haml @@ -0,0 +1,3 @@ +- content_for :title, t("groups.edit.page_title") + += render "form" \ No newline at end of file diff --git a/app/views/groups/index.html.haml b/app/views/groups/index.html.haml new file mode 100644 index 0000000..7984b9e --- /dev/null +++ b/app/views/groups/index.html.haml @@ -0,0 +1,6 @@ +- content_for :title, t("groups.index.page_title") + +- if @groups && @groups.count > 0 + = render "index_core", :groups => @groups + += render :partial => 'shared/create_link', :locals => {:child_class => Group} \ No newline at end of file diff --git a/app/views/groups/new.html.haml b/app/views/groups/new.html.haml new file mode 100644 index 0000000..e8017a8 --- /dev/null +++ b/app/views/groups/new.html.haml @@ -0,0 +1,3 @@ +- content_for :title, t("groups.new.page_title") + += render "form" \ No newline at end of file diff --git a/app/views/groups/show.html.haml b/app/views/groups/show.html.haml new file mode 100644 index 0000000..fc291f3 --- /dev/null +++ b/app/views/groups/show.html.haml @@ -0,0 +1,25 @@ +- content_for :title, t("groups.show.page_title") + +%p + %strong= t('groups.show.name') + ":" + = @group.name +%p + %strong= t('groups.show.active') + ":" + = @group.active +%p + %strong= t('groups.show.comment') + ":" + = @group.comment + += render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @group } + +%h3= t('group_permissions.index.page_title') +- if @group.group_permissions.any? + = render "group_permissions/index_core", :group_permissions => @group.group_permissions + %br += render :partial => 'shared/create_link', :locals => { :parent => @group, :child_class => GroupPermission } + +%h3= t('group_memberships.index.page_title') +- if @group.group_memberships.any? + = render "group_memberships/index_core", :group_memberships => @group.group_memberships + %br += render :partial => 'shared/create_link', :locals => { :parent => @group, :child_class => GroupMembership } -- cgit v1.2.3 From 0eb056b92e9eaf091146c13dcb3fdc9d7fb34baf Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Fri, 22 Feb 2013 13:08:46 -0500 Subject: breadcrumbs --- app/controllers/group_memberships_controller.rb | 2 ++ app/controllers/group_permissions_controller.rb | 2 ++ app/controllers/groups_controller.rb | 3 +++ 3 files changed, 7 insertions(+) (limited to 'app') diff --git a/app/controllers/group_memberships_controller.rb b/app/controllers/group_memberships_controller.rb index df9f6b3..e0f897b 100644 --- a/app/controllers/group_memberships_controller.rb +++ b/app/controllers/group_memberships_controller.rb @@ -2,6 +2,8 @@ class GroupMembershipsController < ApplicationController load_and_authorize_resource :group load_and_authorize_resource :group_membership, :through => [:group] + before_filter :spread_breadcrumbs + def index end diff --git a/app/controllers/group_permissions_controller.rb b/app/controllers/group_permissions_controller.rb index 3abdc51..dda800e 100644 --- a/app/controllers/group_permissions_controller.rb +++ b/app/controllers/group_permissions_controller.rb @@ -2,6 +2,8 @@ class GroupPermissionsController < ApplicationController load_and_authorize_resource :group load_and_authorize_resource :group_permission, :through => [:group] + before_filter :spread_breadcrumbs + def index end diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 1ab7a4f..74ad7c8 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -1,4 +1,7 @@ class GroupsController < ApplicationController + load_and_authorize_resource :group + before_filter :spread_breadcrumbs + def index @groups = Group.all end -- cgit v1.2.3 From 3404cb248f32951aaf0508cfcfc87bfad533c6e5 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Sat, 23 Feb 2013 01:25:13 -0500 Subject: set target_group=group on new --- app/controllers/group_permissions_controller.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app') diff --git a/app/controllers/group_permissions_controller.rb b/app/controllers/group_permissions_controller.rb index dda800e..b6517b1 100644 --- a/app/controllers/group_permissions_controller.rb +++ b/app/controllers/group_permissions_controller.rb @@ -11,6 +11,7 @@ class GroupPermissionsController < ApplicationController end def new + @group_permission.target_group_id = @group_permission.group_id end def create -- 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') 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') 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') 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/controllers/call_forwards_controller.rb | 58 ++++++++---- app/controllers/config_siemens_controller.rb | 4 +- 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 +- app/views/call_forwards/_form.html.haml | 2 +- app/views/call_forwards/_index_core.html.haml | 14 +-- app/views/call_forwards/index.html.haml | 2 +- app/views/call_forwards/show.html.haml | 24 +++-- app/views/gs_nodes/sync.xml.haml | 2 +- app/views/sip_accounts/_form_core.html.haml | 2 +- 14 files changed, 102 insertions(+), 151 deletions(-) (limited to 'app') diff --git a/app/controllers/call_forwards_controller.rb b/app/controllers/call_forwards_controller.rb index b1ced87..cd72a38 100644 --- a/app/controllers/call_forwards_controller.rb +++ b/app/controllers/call_forwards_controller.rb @@ -1,7 +1,9 @@ class CallForwardsController < ApplicationController - load_and_authorize_resource :phone_number - load_and_authorize_resource :call_forward, :through => [:phone_number] + load_resource :phone_number + load_resource :sip_account + load_and_authorize_resource :call_forward, :through => [:phone_number, :sip_account] + before_filter :set_and_authorize_parent before_filter :spread_breadcrumbs class CallForwardingDestination @@ -20,7 +22,7 @@ class CallForwardsController < ApplicationController end def new - @call_forward = @phone_number.call_forwards.build + @call_forward = @parent.call_forwards.build @call_forward.depth = GsParameter.get('DEFAULT_CALL_FORWARD_DEPTH') @call_forward.active = true @call_forwarding_destinations = call_forwarding_destination_types() @@ -33,7 +35,7 @@ class CallForwardsController < ApplicationController end end - if @phone_number.call_forwards.where( + if @parent.call_forwards.where( :call_forward_case_id => CallForwardCase.find_by_value('noanswer').id, :active => true ).count == 0 @@ -43,10 +45,11 @@ class CallForwardsController < ApplicationController end def create - @call_forward = @phone_number.call_forwards.build( params[:call_forward] ) + @call_forward = @parent.call_forwards.build( params[:call_forward] ) if @call_forward.save - redirect_to phone_number_call_forward_path( @phone_number, @call_forward ), :notice => t('call_forwards.controller.successfuly_created') + m = method( :"#{@parent.class.name.underscore}_call_forward_path" ) + redirect_to m.( @parent, @call_forward ), :notice => t('call_forwards.controller.successfuly_created') else @available_call_forward_cases = CallForwardCase.all render :new @@ -61,7 +64,8 @@ class CallForwardsController < ApplicationController def update @available_call_forward_cases = CallForwardCase.all if @call_forward.update_attributes(params[:call_forward]) - redirect_to phone_number_call_forward_path( @phone_number, @call_forward ), :notice => t('call_forwards.controller.successfuly_updated') + m = method( :"#{@parent.class.name.underscore}_call_forward_path" ) + redirect_to m.( @parent, @call_forward ), :notice => t('call_forwards.controller.successfuly_updated') else @call_forwarding_destinations = call_forwarding_destination_types() render :edit @@ -70,30 +74,46 @@ class CallForwardsController < ApplicationController def destroy @call_forward.destroy - redirect_to phone_number_call_forwards_path( @phone_number ), :notice => t('call_forwards.controller.successfuly_destroyed') + redirect_to :root, :notice => t('call_forwards.controller.successfuly_destroyed') end private + private + def set_and_authorize_parent + @parent = @sip_account || @phone_number + authorize! :read, @parent + end + def spread_breadcrumbs - if @phone_number && @phone_number.phone_numberable_type == 'SipAccount' - @sip_account = @phone_number.phone_numberable + if @parent + if @parent.class == PhoneNumber && @parent.phone_numberable_type == 'SipAccount' + @sip_account = @parent.phone_numberable + end if @sip_account.sip_accountable_type == 'User' - @user = @phone_number.phone_numberable.sip_accountable - add_breadcrumb t("users.index.page_title"), tenant_users_path(@user.current_tenant) - add_breadcrumb @user, tenant_users_path(@user.current_tenant, @user) - add_breadcrumb t("sip_accounts.index.page_title"), user_sip_accounts_path(@user) - add_breadcrumb @sip_account, user_sip_account_path(@user, @sip_account) + @user = @sip_account.sip_accountable + if @parent.class == PhoneNumber + add_breadcrumb t("users.index.page_title"), tenant_users_path(@user.current_tenant) + add_breadcrumb @user, tenant_users_path(@user.current_tenant, @user) + add_breadcrumb t("sip_accounts.index.page_title"), user_sip_accounts_path(@user) + add_breadcrumb @sip_account, user_sip_account_path(@user, @sip_account) + add_breadcrumb t("phone_numbers.index.page_title"), sip_account_phone_numbers_path(@sip_account) + add_breadcrumb @parent, sip_account_phone_number_path(@sip_account, @parent) + elsif @parent.class == SipAccount + add_breadcrumb t("users.index.page_title"), tenant_users_path(@user.current_tenant) + add_breadcrumb @user, tenant_users_path(@user.current_tenant, @user) + add_breadcrumb t("sip_accounts.index.page_title"), user_sip_accounts_path(@user) + end end if @sip_account.sip_accountable_type == 'Tenant' @tenant = @sip_account.sip_accountable add_breadcrumb t("sip_accounts.index.page_title"), tenant_sip_accounts_path(@tenant) add_breadcrumb @sip_account, tenant_sip_account_path(@tenant, @sip_account) end - add_breadcrumb t("phone_numbers.index.page_title"), sip_account_phone_numbers_path(@sip_account) - add_breadcrumb @phone_number, sip_account_phone_number_path(@sip_account, @phone_number) - add_breadcrumb t("call_forwards.index.page_title"), phone_number_call_forwards_path(@phone_number) + + add_breadcrumb t("call_forwards.index.page_title"), phone_number_call_forwards_path(@parent) if @call_forward && !@call_forward.new_record? - add_breadcrumb @call_forward, phone_number_call_forward_path(@phone_number, @call_forward) + m = method( :"#{@parent.class.name.underscore}_call_forward_path" ) + add_breadcrumb @call_forward, m.(@parent, @call_forward) end end end diff --git a/app/controllers/config_siemens_controller.rb b/app/controllers/config_siemens_controller.rb index bbeba46..1966d49 100644 --- a/app/controllers/config_siemens_controller.rb +++ b/app/controllers/config_siemens_controller.rb @@ -1068,8 +1068,8 @@ class ConfigSiemensController < ApplicationController phone_numbers.push(phone_number.number) assistant_call_forwardings = phone_number.call_forwards.where(:call_forward_case_id => CallForwardCase.where(:value => 'assistant').first.id) assistant_call_forwardings.each do |assistant_call_forwarding| - if assistant_call_forwarding.call_forwardable_type == 'HuntGroup' && assistant_call_forwarding.call_forwardable_id.to_i > 0 - hunt_groups.push(assistant_call_forwarding.call_forwardable_id.to_i) + if assistant_call_forwarding.destinationable_type == 'HuntGroup' && assistant_call_forwarding.destinationable_id.to_i > 0 + hunt_groups.push(assistant_call_forwarding.destinationable_id.to_i) end end end 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 diff --git a/app/views/call_forwards/_form.html.haml b/app/views/call_forwards/_form.html.haml index 58ffd78..1944fc4 100644 --- a/app/views/call_forwards/_form.html.haml +++ b/app/views/call_forwards/_form.html.haml @@ -1,4 +1,4 @@ -= simple_form_for([ @phone_number, @call_forward ]) do |f| += simple_form_for([ @parent, @call_forward ]) do |f| = f.error_notification = render "form_core", :f => f diff --git a/app/views/call_forwards/_index_core.html.haml b/app/views/call_forwards/_index_core.html.haml index 878e0e2..48afa54 100644 --- a/app/views/call_forwards/_index_core.html.haml +++ b/app/views/call_forwards/_index_core.html.haml @@ -2,7 +2,7 @@ %thead %tr - if !@phone_number - %th= t('call_forwards.index.phone_number_id') + %th= t('call_forwards.index.call_forwardable') %th= t('call_forwards.index.call_forward_case_id') %th= t('call_forwards.index.timeout') %th= t('call_forwards.index.destination') @@ -15,18 +15,18 @@ - for call_forward in call_forwards %tr - if !@phone_number - %td= call_forward.phone_number + %td= call_forward.call_forwardable %td= t("call_forward_cases.#{call_forward.call_forward_case.value}") %td= call_forward.timeout %td = call_forward.destination - - if call_forward.call_forwardable_type + - if call_forward.destinationable_type %br - = call_forward.call_forwardable_type - - if call_forward.call_forwardable - = ": #{call_forward.call_forwardable}" + = call_forward.destinationable_type + - if call_forward.destinationable_id + = ": #{call_forward.destinationable}" %td= call_forward.source - if GuiFunction.display?('depth_field_value_in_index_table', current_user) %td= call_forward.depth %td= call_forward.active - =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => call_forward.phone_number, :child => call_forward} \ No newline at end of file + =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => call_forward.call_forwardable, :child => call_forward} \ No newline at end of file diff --git a/app/views/call_forwards/index.html.haml b/app/views/call_forwards/index.html.haml index 91b923a..e206653 100644 --- a/app/views/call_forwards/index.html.haml +++ b/app/views/call_forwards/index.html.haml @@ -3,4 +3,4 @@ - if @call_forwards.count > 0 = render "index_core", :call_forwards => @call_forwards -= render :partial => 'shared/create_link', :locals => {:parent => @phone_number, :child_class => CallForward} \ No newline at end of file += render :partial => 'shared/create_link', :locals => {:parent => @parent, :child_class => CallForward} \ No newline at end of file diff --git a/app/views/call_forwards/show.html.haml b/app/views/call_forwards/show.html.haml index c2187b1..9f9d27a 100644 --- a/app/views/call_forwards/show.html.haml +++ b/app/views/call_forwards/show.html.haml @@ -1,25 +1,23 @@ - content_for :title, t("call_forwards.show.page_title") %p - %strong= t('call_forwards.show.phone_number_id') + ":" - = @call_forward.phone_number + %strong= t('call_forwards.show.call_forwardable') + ":" + = "#{@call_forward.call_forwardable_type}: #{@call_forward.call_forwardable}" %p - %strong= t('call_forwards.show.call_forward_case_id') + ":" + %strong= t('call_forwards.show.call_forward_case') + ":" = t("call_forward_cases.#{@call_forward.call_forward_case.value}") %p %strong= t('call_forwards.show.timeout') + ":" = @call_forward.timeout %p %strong= t('call_forwards.show.destination') + ":" - = @call_forward.destination -- if @call_forward.call_forwardable_type == 'HuntGroup' && @call_forward.call_forwardable.class == HuntGroup - %p - %strong= t('call_forwards.show.hunt_group') + ":" - = @call_forward.call_forwardable -- if @call_forward.call_forwardable_type == 'Voicemail' - %p - %strong= t('call_forwards.show.to_voicemail') + ":" - = 'active' + - if @call_forward.destinationable_id && @call_forward.destinationable + = "#{@call_forward.destinationable_type}: #{@call_forward.destinationable}" + - elsif !@call_forward.destinationable_type.blank? + = "#{@call_forward.destinationable_type}: #{@call_forward.destination}" + - else + = @call_forward.destination + %p %strong= t('call_forwards.show.source') + ":" = @call_forward.source @@ -30,4 +28,4 @@ %strong= t('call_forwards.show.active') + ":" = @call_forward.active -= render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @phone_number, :child => @call_forward } \ No newline at end of file += render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @parent, :child => @call_forward } \ No newline at end of file diff --git a/app/views/gs_nodes/sync.xml.haml b/app/views/gs_nodes/sync.xml.haml index a2fa71a..bba5c4e 100644 --- a/app/views/gs_nodes/sync.xml.haml +++ b/app/views/gs_nodes/sync.xml.haml @@ -55,7 +55,7 @@ - if !@call_forwards.blank? %call_forwards - @call_forwards.each do |call_forward| - %call_forward{ :uuid => call_forward.uuid, :service => call_forward.call_forward_case.try(:value), :timeout => call_forward.timeout, :destination => call_forward.destination, :source => call_forward.source, :active => call_forward.active.to_s, :created_at => call_forward.created_at, :updated_at => call_forward.updated_at, :phone_number_uuid => call_forward.phone_number.try(:uuid), :depth => call_forward.depth, :call_forwardable_type => call_forward.call_forwardable_type, :call_forwardable_uuid => call_forward.call_forwardable.try(:uuid), :position => call_forward.position} + %call_forward{ :uuid => call_forward.uuid, :service => call_forward.call_forward_case.try(:value), :timeout => call_forward.timeout, :destination => call_forward.destination, :source => call_forward.source, :active => call_forward.active.to_s, :created_at => call_forward.created_at, :updated_at => call_forward.updated_at, :phone_number_uuid => call_forward.phone_number.try(:uuid), :depth => call_forward.depth, :call_forwardable_type => call_forward.call_forwardable_type, :call_forwardable_uuid => call_forward.call_forwardable.try(:uuid), :destinationable_type => call_forward.destinationable_type, :destinationable_uuid => call_forward.destinationable.try(:uuid), :position => call_forward.position} - if !@softkeys.blank? %softkeys diff --git a/app/views/sip_accounts/_form_core.html.haml b/app/views/sip_accounts/_form_core.html.haml index 1a8876a..1a09912 100644 --- a/app/views/sip_accounts/_form_core.html.haml +++ b/app/views/sip_accounts/_form_core.html.haml @@ -13,6 +13,6 @@ - if @sip_account.sip_accountable_type == 'User' = f.input :hotdeskable, :label => t('sip_accounts.form.hotdeskable.label'), :hint => conditional_hint('sip_accounts.form.hotdeskable.hint') = f.input :clip_no_screening, :label => t('sip_accounts.form.clip_no_screening.label'), :hint => conditional_hint('sip_accounts.form.clip_no_screening.hint') - - if CallForward.where(:phone_number_id => @sip_account.phone_number_ids).count == 0 || @sip_account.callforward_rules_act_per_sip_account == true + - if CallForward.where(:call_forwardable_id => @sip_account.phone_number_ids, :call_forwardable_type => 'PhoneNumber').count == 0 || @sip_account.callforward_rules_act_per_sip_account == true = f.input :callforward_rules_act_per_sip_account, :label => t('sip_accounts.form.callforward_rules_act_per_sip_account.label'), :hint => conditional_hint('sip_accounts.form.callforward_rules_act_per_sip_account.hint') = f.input :language_code, :collection => Language.all.collect{|l| [l.to_s, l.code]}, :label => t('sip_accounts.form.language_code.label'), :hint => conditional_hint('sip_accounts.form.language_id.hint'), :include_blank => false -- 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/controllers/call_forwards_controller.rb | 14 ++++++++------ app/controllers/ringtones_controller.rb | 11 ++++++----- app/models/call_forward.rb | 3 +-- app/models/ringtone.rb | 14 ++++++++++++++ app/models/sip_account.rb | 2 ++ app/views/call_forwards/_form_core.html.haml | 6 +----- app/views/call_forwards/_index_core.html.haml | 10 +--------- app/views/call_forwards/show.html.haml | 8 +------- app/views/ringtones/_form_core.html.haml | 2 +- app/views/ringtones/_index_core.html.haml | 4 ++-- app/views/ringtones/index.html.haml | 4 ++-- app/views/sip_accounts/show.html.haml | 7 +++++++ app/views/users/show.html.haml | 2 +- 13 files changed, 47 insertions(+), 40 deletions(-) (limited to 'app') diff --git a/app/controllers/call_forwards_controller.rb b/app/controllers/call_forwards_controller.rb index cd72a38..34fb77a 100644 --- a/app/controllers/call_forwards_controller.rb +++ b/app/controllers/call_forwards_controller.rb @@ -48,8 +48,8 @@ class CallForwardsController < ApplicationController @call_forward = @parent.call_forwards.build( params[:call_forward] ) if @call_forward.save - m = method( :"#{@parent.class.name.underscore}_call_forward_path" ) - redirect_to m.( @parent, @call_forward ), :notice => t('call_forwards.controller.successfuly_created') + m = method( :"#{@parent.class.name.underscore}_call_forwards_url" ) + redirect_to m.( @parent ), :notice => t('call_forwards.controller.successfuly_created') else @available_call_forward_cases = CallForwardCase.all render :new @@ -64,8 +64,8 @@ class CallForwardsController < ApplicationController def update @available_call_forward_cases = CallForwardCase.all if @call_forward.update_attributes(params[:call_forward]) - m = method( :"#{@parent.class.name.underscore}_call_forward_path" ) - redirect_to m.( @parent, @call_forward ), :notice => t('call_forwards.controller.successfuly_updated') + m = method( :"#{@parent.class.name.underscore}_call_forwards_url" ) + redirect_to m.( @parent ), :notice => t('call_forwards.controller.successfuly_updated') else @call_forwarding_destinations = call_forwarding_destination_types() render :edit @@ -74,7 +74,8 @@ class CallForwardsController < ApplicationController def destroy @call_forward.destroy - redirect_to :root, :notice => t('call_forwards.controller.successfuly_destroyed') + m = method( :"#{@parent.class.name.underscore}_call_forwards_url" ) + redirect_to m.( @parent ), :notice => t('call_forwards.controller.successfuly_destroyed') end private @@ -110,7 +111,8 @@ class CallForwardsController < ApplicationController add_breadcrumb @sip_account, tenant_sip_account_path(@tenant, @sip_account) end - add_breadcrumb t("call_forwards.index.page_title"), phone_number_call_forwards_path(@parent) + m = method( :"#{@parent.class.name.underscore}_call_forwards_url" ) + add_breadcrumb t("call_forwards.index.page_title"), m.(@parent) if @call_forward && !@call_forward.new_record? m = method( :"#{@parent.class.name.underscore}_call_forward_path" ) add_breadcrumb @call_forward, m.(@parent, @call_forward) diff --git a/app/controllers/ringtones_controller.rb b/app/controllers/ringtones_controller.rb index 7ffe30e..f726650 100644 --- a/app/controllers/ringtones_controller.rb +++ b/app/controllers/ringtones_controller.rb @@ -1,7 +1,8 @@ class RingtonesController < ApplicationController load_resource :phone_number + load_resource :sip_account load_resource :boss_assistant_cooperation - load_and_authorize_resource :ringtone, :through => [:phone_number, :boss_assistant_cooperation] + load_and_authorize_resource :ringtone, :through => [:phone_number, :sip_account, :boss_assistant_cooperation] before_filter :set_parent before_filter :spread_breadcrumbs @@ -19,7 +20,7 @@ class RingtonesController < ApplicationController def create @ringtone = @parent.ringtones.build(params[:ringtone]) if @ringtone.save - redirect_to phone_number_ringtone_path(@parent, @ringtone), :notice => t('ringtones.controller.successfuly_created') + redirect_to method( :"#{@parent.class.name.underscore}_ringtones_url" ).(@parent), :notice => t('ringtones.controller.successfuly_created') else render :new end @@ -30,7 +31,7 @@ class RingtonesController < ApplicationController def update if @ringtone.update_attributes(params[:ringtone]) - redirect_to method( :"#{@parent.class.name.underscore}_ringtone_path" ).(@ringtone.ringtoneable, @ringtone), :notice => t('ringtones.controller.successfuly_updated') + redirect_to method( :"#{@parent.class.name.underscore}_ringtones_url" ).(@parent), :notice => t('ringtones.controller.successfuly_updated') else render :edit end @@ -38,12 +39,12 @@ class RingtonesController < ApplicationController def destroy @ringtone.destroy - redirect_to phone_number_ringtones_path(@parent), :notice => t('ringtones.controller.successfuly_destroyed') + redirect_to method( :"#{@parent.class.name.underscore}_ringtones_url" ).(@parent), :notice => t('ringtones.controller.successfuly_destroyed') end private def set_parent - @parent = @phone_number || @boss_assistant_cooperation + @parent = @phone_number || @boss_assistant_cooperation || @sip_account end def spread_breadcrumbs 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 diff --git a/app/views/call_forwards/_form_core.html.haml b/app/views/call_forwards/_form_core.html.haml index b751fb3..83de044 100644 --- a/app/views/call_forwards/_form_core.html.haml +++ b/app/views/call_forwards/_form_core.html.haml @@ -1,5 +1,5 @@ .inputs - = f.input :call_forward_case_id, :as => :select, :collection => @available_call_forward_cases.map {|x| [I18n.t("call_forward_cases.#{x.value}"), x.id] }, :label => t('call_forwards.form.call_forward_case_id.label'), :hint => conditional_hint('call_forwards.form.call_forward_case_id.hint'), :include_blank => false, :autofocus => true + = f.input :call_forward_case_id, :as => :select, :collection => @available_call_forward_cases.map {|x| [I18n.t("call_forward_cases.#{x.value}"), x.id] }, :label => t('call_forwards.form.call_forward_case.label'), :hint => conditional_hint('call_forwards.form.call_forward_case_id.hint'), :include_blank => false, :autofocus => true = f.input :timeout, :label => t('call_forwards.form.timeout.label'), :hint => conditional_hint('call_forwards.form.timeout.hint') = f.input :call_forwarding_destination , :as => :select, :collection => @call_forwarding_destinations, :label => t('call_forwards.form.call_forwarding_destination.label'), :hint => conditional_hint('call_forwards.form.call_forwarding_destination.hint'), :include_blank => false @@ -8,8 +8,4 @@ = f.input :source, :label => t('call_forwards.form.source.label'), :hint => conditional_hint('call_forwards.form.source.hint') - - if GuiFunction.display?('depth_field_in_call_forward_form', current_user) - = f.input :depth, :collection => 1..GsParameter.get('MAX_CALL_FORWARD_DEPTH'), :label => t('call_forwards.form.depth.label'), :hint => conditional_hint('call_forwards.form.depth.hint') - - else - = f.hidden_field :depth = f.input :active, :label => t('call_forwards.form.active.label'), :hint => conditional_hint('call_forwards.form.active.hint') diff --git a/app/views/call_forwards/_index_core.html.haml b/app/views/call_forwards/_index_core.html.haml index 48afa54..221baf2 100644 --- a/app/views/call_forwards/_index_core.html.haml +++ b/app/views/call_forwards/_index_core.html.haml @@ -1,21 +1,15 @@ %table.table.table-striped %thead %tr - - if !@phone_number - %th= t('call_forwards.index.call_forwardable') - %th= t('call_forwards.index.call_forward_case_id') + %th= t('call_forwards.index.call_forward_case') %th= t('call_forwards.index.timeout') %th= t('call_forwards.index.destination') %th= t('call_forwards.index.source') - - if GuiFunction.display?('depth_field_value_in_index_table', current_user) - %th= t('call_forwards.index.depth') %th= t('call_forwards.index.active') %tbody - for call_forward in call_forwards %tr - - if !@phone_number - %td= call_forward.call_forwardable %td= t("call_forward_cases.#{call_forward.call_forward_case.value}") %td= call_forward.timeout %td @@ -26,7 +20,5 @@ - if call_forward.destinationable_id = ": #{call_forward.destinationable}" %td= call_forward.source - - if GuiFunction.display?('depth_field_value_in_index_table', current_user) - %td= call_forward.depth %td= call_forward.active =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => call_forward.call_forwardable, :child => call_forward} \ No newline at end of file diff --git a/app/views/call_forwards/show.html.haml b/app/views/call_forwards/show.html.haml index 9f9d27a..ad9ab16 100644 --- a/app/views/call_forwards/show.html.haml +++ b/app/views/call_forwards/show.html.haml @@ -1,8 +1,5 @@ - content_for :title, t("call_forwards.show.page_title") -%p - %strong= t('call_forwards.show.call_forwardable') + ":" - = "#{@call_forward.call_forwardable_type}: #{@call_forward.call_forwardable}" %p %strong= t('call_forwards.show.call_forward_case') + ":" = t("call_forward_cases.#{@call_forward.call_forward_case.value}") @@ -21,11 +18,8 @@ %p %strong= t('call_forwards.show.source') + ":" = @call_forward.source -%p - %strong= t('call_forwards.show.depth') + ":" - = @call_forward.depth %p %strong= t('call_forwards.show.active') + ":" = @call_forward.active -= render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @parent, :child => @call_forward } \ No newline at end of file += render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @parent, :child => @call_forward } diff --git a/app/views/ringtones/_form_core.html.haml b/app/views/ringtones/_form_core.html.haml index e44c950..de1cc38 100644 --- a/app/views/ringtones/_form_core.html.haml +++ b/app/views/ringtones/_form_core.html.haml @@ -1,3 +1,3 @@ .inputs / = f.input :audio, :label => t('ringtones.form.audio.label'), :hint => conditional_hint('ringtones.form.audio.hint') - = f.input :bellcore_id, :collection => 0..10, :label => t('ringtones.form.bellcore_id.label'), :hint => conditional_hint('ringtones.form.bellcore_id.hint'), :include_blank => true + = f.input :bellcore_id, :collection => Ringtone::CORE_RINGTONES_AVAILABLE, :label => t('ringtones.form.bellcore_id.label'), :hint => conditional_hint('ringtones.form.bellcore_id.hint'), :include_blank => false diff --git a/app/views/ringtones/_index_core.html.haml b/app/views/ringtones/_index_core.html.haml index 715db3c..51347a5 100644 --- a/app/views/ringtones/_index_core.html.haml +++ b/app/views/ringtones/_index_core.html.haml @@ -1,12 +1,12 @@ %table.table.table-striped %thead %tr - %th= t('ringtones.index.audio') + /%th= t('ringtones.index.audio') %th= t('ringtones.index.bellcore_id') %tbody - for ringtone in ringtones %tr - %td= ringtone.audio + /%td= ringtone.audio %td= ringtone.bellcore_id =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => ringtone.ringtoneable, :child => ringtone} \ No newline at end of file diff --git a/app/views/ringtones/index.html.haml b/app/views/ringtones/index.html.haml index 2eea5fe..2e316a5 100644 --- a/app/views/ringtones/index.html.haml +++ b/app/views/ringtones/index.html.haml @@ -2,5 +2,5 @@ - if @ringtones.count > 0 = render "index_core", :ringtones => @ringtones - -= render :partial => 'shared/create_link', :locals => {:parent => @parent, :child_class => Ringtone} \ No newline at end of file +- else + = render :partial => 'shared/create_link', :locals => {:parent => @parent, :child_class => Ringtone} \ No newline at end of file diff --git a/app/views/sip_accounts/show.html.haml b/app/views/sip_accounts/show.html.haml index 72e10df..0a332af 100644 --- a/app/views/sip_accounts/show.html.haml +++ b/app/views/sip_accounts/show.html.haml @@ -72,6 +72,13 @@ %br = render :partial => 'shared/create_link', :locals => { :parent => @sip_account, :child_class => PhoneNumber } +- if @sip_account.call_forwards.count > 0 || can?(:create, @sip_account.call_forwards.build) + %h2= t('call_forwards.index.page_title') + - if @sip_account.call_forwards.count > 0 + = render "call_forwards/index_core", :call_forwards => @sip_account.call_forwards + %br + = render :partial => 'shared/create_link', :locals => { :parent => @sip_account, :child_class => CallForward } + - if @sip_account.softkeys.count > 0 || can?(:create, @sip_account.softkeys.build) %h2= t("softkeys.index.page_title") - if @sip_account.softkeys.count > 0 diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 0f6cc2c..8882c08 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -38,7 +38,7 @@ %br =link_to t("voicemail_messages.index.page_title"), sip_account_voicemail_messages_path(sip_account) %br - =link_to t("call_forwards.index.page_title"), phone_number_call_forwards_path(phone_number) + =link_to t("call_forwards.index.page_title"), sip_account_call_forwards_path(sip_account) %br =link_to t("voicemail_settings.index.page_title"), sip_account_voicemail_settings_path(sip_account) %br -- cgit v1.2.3 From 26e2e09b20f7f775942b415df6eb55ddb7193879 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 25 Feb 2013 11:57:28 -0500 Subject: sip_account ringtone as default --- app/views/users/show.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 8882c08..d3b1cf3 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -44,7 +44,7 @@ %br =link_to t("softkeys.index.page_title"), sip_account_softkeys_path(sip_account) %br - =link_to t("ringtones.show.page_title"), phone_number_ringtones_path(phone_number) + =link_to t("ringtones.show.page_title"), sip_account_ringtones_path(sip_account) - if @user.conferences.any? %p -- cgit v1.2.3 From c6d5308480df11e3ebc829a3fa7df8f0453c9630 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 25 Feb 2013 11:57:55 -0500 Subject: edit ringtone --- app/views/sip_accounts/show.html.haml | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'app') diff --git a/app/views/sip_accounts/show.html.haml b/app/views/sip_accounts/show.html.haml index 0a332af..bf9d692 100644 --- a/app/views/sip_accounts/show.html.haml +++ b/app/views/sip_accounts/show.html.haml @@ -65,6 +65,13 @@ = render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @sip_account.sip_accountable, :child => @sip_account } +%p + %strong= t('ringtones.name') + ':' + - if @sip_account.ringtones.count > 0 + = link_to @sip_account.ringtones.first, sip_account_ringtone_path(@sip_account, @sip_account.ringtones.first) + - else + = link_to t('ringtones.set_a_ringtone'), new_sip_account_ringtone_path(@sip_account) + - if @sip_account.phone_numbers.count > 0 || can?(:create, @sip_account.phone_numbers.build) %h2= t('phone_numbers.index.page_title') - if @sip_account.phone_numbers.count > 0 -- cgit v1.2.3 From dca264b22845b7875b9493c17cc185e809372cc1 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 25 Feb 2013 11:58:20 -0500 Subject: use dialplan ringtone as default --- app/controllers/ringtones_controller.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app') diff --git a/app/controllers/ringtones_controller.rb b/app/controllers/ringtones_controller.rb index f726650..e5a4f64 100644 --- a/app/controllers/ringtones_controller.rb +++ b/app/controllers/ringtones_controller.rb @@ -15,6 +15,7 @@ class RingtonesController < ApplicationController def new @ringtone = @parent.ringtones.build + @ringtone.bellcore_id = GsParameter.get('default_ringtone', 'dialplan', 'parameters') end def create -- cgit v1.2.3 From 04bcdeca551f21748becfbf610e6ea2001c18bc1 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 25 Feb 2013 17:12:34 -0500 Subject: icons --- app/views/groups/_index_core.html.haml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/views/groups/_index_core.html.haml b/app/views/groups/_index_core.html.haml index d99874a..3a444bf 100644 --- a/app/views/groups/_index_core.html.haml +++ b/app/views/groups/_index_core.html.haml @@ -1,13 +1,17 @@ %table.table.table-striped %tr + %th %th= t('groups.index.name') - %th= t('groups.index.active') %th= t('groups.index.comment') - for group in groups %tr + %td + -if group.active + %i.icon-ok + - else + %i.icon-ban-circle %td= group.name - %td= group.active %td= group.comment =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => group} \ No newline at end of file -- cgit v1.2.3 From 90ccb06c88c920c0a21282acf86c0ecad6b6310a Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 25 Feb 2013 17:12:49 -0500 Subject: icons --- app/views/call_forwards/_index_core.html.haml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/views/call_forwards/_index_core.html.haml b/app/views/call_forwards/_index_core.html.haml index 221baf2..3c57405 100644 --- a/app/views/call_forwards/_index_core.html.haml +++ b/app/views/call_forwards/_index_core.html.haml @@ -1,15 +1,20 @@ %table.table.table-striped %thead %tr + %th %th= t('call_forwards.index.call_forward_case') %th= t('call_forwards.index.timeout') %th= t('call_forwards.index.destination') - %th= t('call_forwards.index.source') - %th= t('call_forwards.index.active') + %th= t('call_forwards.index.source') %tbody - for call_forward in call_forwards %tr + %td + -if call_forward.active + %i.icon-ok + - else + %i.icon-ban-circle %td= t("call_forward_cases.#{call_forward.call_forward_case.value}") %td= call_forward.timeout %td @@ -20,5 +25,5 @@ - if call_forward.destinationable_id = ": #{call_forward.destinationable}" %td= call_forward.source - %td= call_forward.active - =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => call_forward.call_forwardable, :child => call_forward} \ No newline at end of file + =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => call_forward.call_forwardable, :child => call_forward} + -- cgit v1.2.3 From cf89633baaa6e9bc901c2cc630ed2c94296109f1 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 25 Feb 2013 18:02:59 -0500 Subject: callforward_rules_act_per_sip_account removed from views --- app/views/sip_accounts/_form_core.html.haml | 2 -- app/views/sip_accounts/show.html.haml | 5 ----- 2 files changed, 7 deletions(-) (limited to 'app') diff --git a/app/views/sip_accounts/_form_core.html.haml b/app/views/sip_accounts/_form_core.html.haml index 1a09912..d7c65d0 100644 --- a/app/views/sip_accounts/_form_core.html.haml +++ b/app/views/sip_accounts/_form_core.html.haml @@ -13,6 +13,4 @@ - if @sip_account.sip_accountable_type == 'User' = f.input :hotdeskable, :label => t('sip_accounts.form.hotdeskable.label'), :hint => conditional_hint('sip_accounts.form.hotdeskable.hint') = f.input :clip_no_screening, :label => t('sip_accounts.form.clip_no_screening.label'), :hint => conditional_hint('sip_accounts.form.clip_no_screening.hint') - - if CallForward.where(:call_forwardable_id => @sip_account.phone_number_ids, :call_forwardable_type => 'PhoneNumber').count == 0 || @sip_account.callforward_rules_act_per_sip_account == true - = f.input :callforward_rules_act_per_sip_account, :label => t('sip_accounts.form.callforward_rules_act_per_sip_account.label'), :hint => conditional_hint('sip_accounts.form.callforward_rules_act_per_sip_account.hint') = f.input :language_code, :collection => Language.all.collect{|l| [l.to_s, l.code]}, :label => t('sip_accounts.form.language_code.label'), :hint => conditional_hint('sip_accounts.form.language_id.hint'), :include_blank => false diff --git a/app/views/sip_accounts/show.html.haml b/app/views/sip_accounts/show.html.haml index bf9d692..ede5150 100644 --- a/app/views/sip_accounts/show.html.haml +++ b/app/views/sip_accounts/show.html.haml @@ -37,11 +37,6 @@ %strong= t('sip_accounts.show.hotdeskable') + ":" %td = @sip_account.hotdeskable == true ? t('simple_form.yes') : t('simple_form.no') - %tr - %td - %strong= t('sip_accounts.show.callforward_rules_act_per_sip_account') + ":" - %td - = @sip_account.callforward_rules_act_per_sip_account == true ? t('simple_form.yes') : t('simple_form.no') - if @sip_account.registration.try(:network_ip) && @sip_account.registration.try(:network_port) %tr -- cgit v1.2.3 From 387ce8f6694b41ab73d264190ce41dcd13484ede Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 25 Feb 2013 18:03:42 -0500 Subject: icons --- app/controllers/intruders_controller.rb | 2 +- app/views/intruders/_index_core.html.haml | 9 ++++++++- app/views/sip_accounts/_index_core.html.haml | 4 ++-- app/views/users/show.html.haml | 16 ++++++++++++---- 4 files changed, 23 insertions(+), 8 deletions(-) (limited to 'app') diff --git a/app/controllers/intruders_controller.rb b/app/controllers/intruders_controller.rb index 147e06d..99cb023 100644 --- a/app/controllers/intruders_controller.rb +++ b/app/controllers/intruders_controller.rb @@ -1,6 +1,6 @@ class IntrudersController < ApplicationController def index - @intruders = Intruder.all + @intruders = Intruder.order('list_type ASC, contact_last DESC').all spread_breadcrumbs end diff --git a/app/views/intruders/_index_core.html.haml b/app/views/intruders/_index_core.html.haml index 31bbd11..63f2253 100644 --- a/app/views/intruders/_index_core.html.haml +++ b/app/views/intruders/_index_core.html.haml @@ -16,7 +16,14 @@ - for intruder in intruders %tr - %td= intruder.list_type.chars.first + %td + - if intruder.list_type == 'whitelist' + %i.icon-ok + - elsif intruder.bans > 0 + %i.icon-fire + - elsif intruder.points > 0 + %i.icon-warning-sign + %td= intruder.contact_ip %td= intruder.contact_port %td= intruder.points diff --git a/app/views/sip_accounts/_index_core.html.haml b/app/views/sip_accounts/_index_core.html.haml index 34aac64..d98ea0a 100644 --- a/app/views/sip_accounts/_index_core.html.haml +++ b/app/views/sip_accounts/_index_core.html.haml @@ -20,13 +20,13 @@ - if sip_account.registration %i.icon-ok - else - %i.icon-thumbs-down + %i.icon-ban-circle %td = sip_account.caller_name - phone_numbers = sip_account.phone_numbers %td - if sip_account.phone_numbers.count > 0 - = render 'phone_numbers/listing', :phone_numbers => sip_account.phone_numbers.order(:number) + = render 'phone_numbers/listing', :phone_numbers => sip_account.phone_numbers.order(:position) - if sip_accounts.map{ |sip_account| sip_account.phone_sip_accounts.any? }.include?(true) %td %span.hidden-phone diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index d3b1cf3..8148005 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -29,10 +29,18 @@ = render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @tenant, :child => @user } - @user.sip_accounts.each do |sip_account| - - phone_number = sip_account.phone_numbers.order(:number).last - - if phone_number && !phone_number.number.blank? && phone_number.number[0] != '+' - %p - %strong= sip_account.phone_numbers.order(:number).last.number + - phone_numbers = sip_account.phone_numbers.order(:position) + %p + - if phone_numbers[0] + %strong= phone_numbers[0].number + - else + %strong= sip_account.to_s + - if phone_numbers[1] + %strong= phone_numbers[1].number + - if phone_numbers[2] + %strong= phone_numbers[2].number + - if phone_numbers[3] + %strong ... %p =link_to t("call_histories.index.page_title"), sip_account_call_histories_path(sip_account) %br -- cgit v1.2.3 From ad2121462a9ea9a776756a188779a9d504f078b7 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 25 Feb 2013 18:11:50 -0500 Subject: authorization added --- app/controllers/intruders_controller.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app') diff --git a/app/controllers/intruders_controller.rb b/app/controllers/intruders_controller.rb index 99cb023..d3c767e 100644 --- a/app/controllers/intruders_controller.rb +++ b/app/controllers/intruders_controller.rb @@ -1,4 +1,6 @@ class IntrudersController < ApplicationController + load_and_authorize_resource :intruder + def index @intruders = Intruder.order('list_type ASC, contact_last DESC').all spread_breadcrumbs -- 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/controllers/restore_jobs_controller.rb | 24 ++++++++++++++ app/helpers/restore_jobs_helper.rb | 2 ++ app/models/ability.rb | 1 + app/models/restore_job.rb | 13 ++++++++ app/uploaders/backup_file_uploader.rb | 6 ++-- app/views/backup_jobs/show.html.haml | 48 +++++++++++++++++----------- app/views/restore_jobs/_form.html.haml | 7 ++++ app/views/restore_jobs/_form_core.html.haml | 2 ++ app/views/restore_jobs/_index_core.html.haml | 12 +++++++ app/views/restore_jobs/index.html.haml | 6 ++++ app/views/restore_jobs/new.html.haml | 3 ++ app/views/restore_jobs/show.html.haml | 22 +++++++++++++ 12 files changed, 125 insertions(+), 21 deletions(-) create mode 100644 app/controllers/restore_jobs_controller.rb create mode 100644 app/helpers/restore_jobs_helper.rb create mode 100644 app/models/restore_job.rb create mode 100644 app/views/restore_jobs/_form.html.haml create mode 100644 app/views/restore_jobs/_form_core.html.haml create mode 100644 app/views/restore_jobs/_index_core.html.haml create mode 100644 app/views/restore_jobs/index.html.haml create mode 100644 app/views/restore_jobs/new.html.haml create mode 100644 app/views/restore_jobs/show.html.haml (limited to 'app') diff --git a/app/controllers/restore_jobs_controller.rb b/app/controllers/restore_jobs_controller.rb new file mode 100644 index 0000000..1cccdc1 --- /dev/null +++ b/app/controllers/restore_jobs_controller.rb @@ -0,0 +1,24 @@ +class RestoreJobsController < ApplicationController + skip_before_filter :start_setup_if_new_installation, :only => [:new, :create, :show, :index] + + load_and_authorize_resource :restore_job + + def index + end + + def show + end + + def new + end + + def create + @restore_job.state = 'new' + + if @restore_job.save + redirect_to @restore_job, :notice => t('restore_jobs.controller.successfuly_created') + else + render :new + end + end +end diff --git a/app/helpers/restore_jobs_helper.rb b/app/helpers/restore_jobs_helper.rb new file mode 100644 index 0000000..9a5d120 --- /dev/null +++ b/app/helpers/restore_jobs_helper.rb @@ -0,0 +1,2 @@ +module RestoreJobsHelper +end 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 diff --git a/app/uploaders/backup_file_uploader.rb b/app/uploaders/backup_file_uploader.rb index 8b126a9..0244ba5 100644 --- a/app/uploaders/backup_file_uploader.rb +++ b/app/uploaders/backup_file_uploader.rb @@ -42,9 +42,9 @@ class BackupFileUploader < CarrierWave::Uploader::Base # Add a white list of extensions which are allowed to be uploaded. # For images you might use something like this: - # def extension_white_list - # %w(jpg jpeg gif png) - # end + def extension_white_list + %w(tar.gz) + end # Override the filename of the uploaded files: # Avoid using model.id or version_name here, see uploader/store.rb for details. diff --git a/app/views/backup_jobs/show.html.haml b/app/views/backup_jobs/show.html.haml index 6fcb1dc..ddc4766 100644 --- a/app/views/backup_jobs/show.html.haml +++ b/app/views/backup_jobs/show.html.haml @@ -1,22 +1,34 @@ - content_for :title, t("backup_jobs.show.page_title") -%p - %strong= t('backup_jobs.show.started_at') + ":" - = @backup_job.started_at -%p - %strong= t('backup_jobs.show.finished_at') + ":" - = @backup_job.finished_at -%p - %strong= t('backup_jobs.show.state') + ":" - = @backup_job.state -%p - %strong= t('backup_jobs.show.directory') + ":" - = @backup_job.directory -%p - %strong= t('backup_jobs.show.size_of_the_backup') + ":" - - if @backup_job.backup_file? - %a{:href => backup_job.backup_file.url} - %i{:class => 'icon-download'} - = number_to_human_size(backup_job.backup_file.size, :precision => 2) +%table.table.table-striped + %tbody + %tr + %td + %strong= t('backup_jobs.show.started_at') + ":" + %td + = @backup_job.started_at + %tr + %td + %strong= t('backup_jobs.show.finished_at') + ":" + %td + = @backup_job.finished_at + %tr + %td + %strong= t('backup_jobs.show.state') + ":" + %td + = @backup_job.state + %tr + %td + %strong= t('backup_jobs.show.directory') + ":" + %td + = @backup_job.directory + %tr + %td + %strong= t('backup_jobs.show.size_of_the_backup') + ":" + %td + - if @backup_job.backup_file? + %a{:href => backup_job.backup_file.url} + %i{:class => 'icon-download'} + = number_to_human_size(backup_job.backup_file.size, :precision => 2) = render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @backup_job } \ No newline at end of file diff --git a/app/views/restore_jobs/_form.html.haml b/app/views/restore_jobs/_form.html.haml new file mode 100644 index 0000000..43ced9a --- /dev/null +++ b/app/views/restore_jobs/_form.html.haml @@ -0,0 +1,7 @@ += simple_form_for(@restore_job) do |f| + = f.error_notification + + = render "form_core", :f => f + + .form-actions + = f.button :submit, conditional_t('restore_jobs.form.submit') diff --git a/app/views/restore_jobs/_form_core.html.haml b/app/views/restore_jobs/_form_core.html.haml new file mode 100644 index 0000000..017c124 --- /dev/null +++ b/app/views/restore_jobs/_form_core.html.haml @@ -0,0 +1,2 @@ +.inputs + = f.input :backup_file, :label => t('restore_jobs.form.backup_file.label'), :hint => conditional_hint('restore_jobs.form.backup_file.hint') diff --git a/app/views/restore_jobs/_index_core.html.haml b/app/views/restore_jobs/_index_core.html.haml new file mode 100644 index 0000000..f6127ba --- /dev/null +++ b/app/views/restore_jobs/_index_core.html.haml @@ -0,0 +1,12 @@ +%table.table.table-striped + %tr + %th= t('restore_jobs.index.state') + %th= t('restore_jobs.index.backup_file') + %th + + + - for restore_job in restore_jobs + %tr + %td= restore_job.state + %td= restore_job.to_s + =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => restore_job} \ No newline at end of file diff --git a/app/views/restore_jobs/index.html.haml b/app/views/restore_jobs/index.html.haml new file mode 100644 index 0000000..b8aa74e --- /dev/null +++ b/app/views/restore_jobs/index.html.haml @@ -0,0 +1,6 @@ +- content_for :title, t("restore_jobs.index.page_title") + +- if @restore_jobs && @restore_jobs.count > 0 + = render "index_core", :restore_jobs => @restore_jobs + += render :partial => 'shared/create_link', :locals => {:child_class => RestoreJob} \ No newline at end of file diff --git a/app/views/restore_jobs/new.html.haml b/app/views/restore_jobs/new.html.haml new file mode 100644 index 0000000..ffae792 --- /dev/null +++ b/app/views/restore_jobs/new.html.haml @@ -0,0 +1,3 @@ +- content_for :title, t("restore_jobs.new.page_title") + += render "form" \ No newline at end of file diff --git a/app/views/restore_jobs/show.html.haml b/app/views/restore_jobs/show.html.haml new file mode 100644 index 0000000..5993872 --- /dev/null +++ b/app/views/restore_jobs/show.html.haml @@ -0,0 +1,22 @@ +- content_for :title, t("restore_jobs.show.page_title") + +%table.table.table-striped + %tbody + %tr + %td + %strong= t('restore_jobs.show.state') + ":" + %td + = @restore_job.state + %tr + %td + %strong= t('restore_jobs.show.backup_file') + ":" + %td + = @restore_job.to_s + %tr + %td + %strong= t('backup_jobs.show.size_of_the_backup') + ":" + %td + - if @restore_job.backup_file? + = number_to_human_size(@restore_job.backup_file.size, :precision => 2) + += render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @restore_job } \ No newline at end of file -- cgit v1.2.3 From 36919fb419a40688daa97e36734f579488cb56e2 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 26 Feb 2013 14:06:27 +0100 Subject: Restore and Backup fixes. --- app/controllers/restore_jobs_controller.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app') diff --git a/app/controllers/restore_jobs_controller.rb b/app/controllers/restore_jobs_controller.rb index 1cccdc1..bfecc33 100644 --- a/app/controllers/restore_jobs_controller.rb +++ b/app/controllers/restore_jobs_controller.rb @@ -16,6 +16,7 @@ class RestoreJobsController < ApplicationController @restore_job.state = 'new' if @restore_job.save + session[:user_id] = nil redirect_to @restore_job, :notice => t('restore_jobs.controller.successfuly_created') else render :new -- cgit v1.2.3 From 0a976c6b463288df4a9516bbd08f6232a37d427c Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 26 Feb 2013 09:21:34 -0500 Subject: enable tel: handling for sip_accounts --- app/controllers/sip_accounts_controller.rb | 5 +++++ app/views/sip_accounts/show.html.haml | 4 ++++ 2 files changed, 9 insertions(+) (limited to 'app') diff --git a/app/controllers/sip_accounts_controller.rb b/app/controllers/sip_accounts_controller.rb index b5c3ae4..2886c8b 100644 --- a/app/controllers/sip_accounts_controller.rb +++ b/app/controllers/sip_accounts_controller.rb @@ -10,6 +10,7 @@ class SipAccountsController < ApplicationController end def show + @register_tel_protocol = "#{request.protocol}#{request.host_with_port}/sip_accounts/#{@sip_account.try(:id)}/call?url=%s" end def new @@ -74,6 +75,10 @@ class SipAccountsController < ApplicationController redirect_to :root, :notice => t('sip_accounts.controller.successfuly_destroyed') end + def call + redirect_to(:back) + end + private def set_and_authorize_parent @parent = @user || @tenant diff --git a/app/views/sip_accounts/show.html.haml b/app/views/sip_accounts/show.html.haml index ede5150..12e54c3 100644 --- a/app/views/sip_accounts/show.html.haml +++ b/app/views/sip_accounts/show.html.haml @@ -60,6 +60,10 @@ = render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @sip_account.sip_accountable, :child => @sip_account } +%p + %strong= t('sip_accounts.show.tel_protocol') + ':' + %a{:href => '', :onclick => "navigator.registerProtocolHandler(\"tel\", \"#{@register_tel_protocol}\", \"#{@sip_account.to_s}\");" }= t('sip_accounts.show.register_tel_protocol') + %p %strong= t('ringtones.name') + ':' - if @sip_account.ringtones.count > 0 -- cgit v1.2.3 From 0399b856c75b842f43bc5380f9c19a64c6418f11 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 26 Feb 2013 10:00:36 -0500 Subject: call action added --- app/controllers/sip_accounts_controller.rb | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/controllers/sip_accounts_controller.rb b/app/controllers/sip_accounts_controller.rb index 2886c8b..022858c 100644 --- a/app/controllers/sip_accounts_controller.rb +++ b/app/controllers/sip_accounts_controller.rb @@ -1,6 +1,7 @@ class SipAccountsController < ApplicationController load_resource :user load_resource :tenant + #load_resource :sip_account load_and_authorize_resource :sip_account, :through => [:user, :tenant ] before_filter :set_and_authorize_parent @@ -76,7 +77,33 @@ class SipAccountsController < ApplicationController end def call - redirect_to(:back) + if !params[:url].blank? + protocol, separator, phone_number = params[:url].partition(':') + if ! phone_number.blank? + @sip_account.call(phone_number) + render( + :status => 200, + :layout => false, + :content_type => 'text/plain', + :text => "", + ) + return; + end + render( + :status => 404, + :layout => false, + :content_type => 'text/plain', + :text => "", + ) + return; + end + + render( + :status => 404, + :layout => false, + :content_type => 'text/plain', + :text => "", + ) end private -- cgit v1.2.3 From df0bc9db9cdbf9bfbc92a5f1f00e57fc0e7d7792 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 26 Feb 2013 16:17:06 +0100 Subject: Search box in the top navigation bar. --- app/controllers/page_controller.rb | 2 ++ app/views/layouts/_navbar.html.haml | 27 ++++++++++++++------------- app/views/layouts/application.html.haml | 2 +- app/views/phone_books/_index_core.html.haml | 7 +++++-- app/views/sessions/new.html.haml | 16 ++++++++++------ 5 files changed, 32 insertions(+), 22 deletions(-) (limited to 'app') diff --git a/app/controllers/page_controller.rb b/app/controllers/page_controller.rb index ed48e3c..10ecf2c 100644 --- a/app/controllers/page_controller.rb +++ b/app/controllers/page_controller.rb @@ -7,6 +7,8 @@ class PageController < ApplicationController def index if current_user redirect_to [current_user.current_tenant, current_user] + else + redirect_to log_in_path end end diff --git a/app/views/layouts/_navbar.html.haml b/app/views/layouts/_navbar.html.haml index 8e09859..a7f47cf 100644 --- a/app/views/layouts/_navbar.html.haml +++ b/app/views/layouts/_navbar.html.haml @@ -1,13 +1,9 @@ .navbar.navbar-inverse.navbar-fixed-top .navbar-inner .container - %a.brand{:href => (current_user.nil? ? '/' : tenant_path(current_user.current_tenant))} - Gemeinschaft 5 - - %a.btn.btn-navbar{"data-target" => ".nav-collapse", "data-toggle" => "collapse"} - %span.icon-bar - %span.icon-bar - %span.icon-bar + %span.hidden-phone + %a.brand{:href => (current_user.nil? ? '/' : tenant_path(current_user.current_tenant))} + Gemeinschaft 5 .nav-collapse.collapse %ul.nav @@ -29,13 +25,14 @@ - if current_user %ul.nav.pull-right %li.display - - if current_user.image? - = image_tag(current_user.image_url(:mini).to_s, :class => 'img-rounded') - - else - - if current_user.male? - = image_tag 'icons/user-male-16x.png', :class => 'img-rounded' + %span.hidden-phone + - if current_user.image? + = image_tag(current_user.image_url(:mini).to_s, :class => 'img-rounded') - else - = image_tag 'icons/user-female-16x.png', :class => 'img-rounded' + - if current_user.male? + = image_tag 'icons/user-male-16x.png', :class => 'img-rounded' + - else + = image_tag 'icons/user-female-16x.png', :class => 'img-rounded' - if current_page?(tenant_user_path(current_user.current_tenant, current_user)) %li.active @@ -51,3 +48,7 @@ %a.navbar-link{:href => log_out_path} %i.icon-off.icon-white + - if GuiFunction.display?('search_field_in_top_navigation_bar', current_user) + = form_tag search_path, :method => :post, :class => 'navbar-search pull-right' do + %input.text{:placeholder => 'Suchen ...', :name => 'q', :class => 'search-query span2'} + diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 33a730f..eab6096 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -3,7 +3,7 @@ %head %meta{:charset => "utf-8"}/ %title - = content_for?(:title) ? yield(:title) : "Gemeinschaft 5" + = content_for?(:title) ? yield(:title) : "Gemeinschaft 5.1" %meta{:name => 'viewport', :content => "width=device-width, initial-scale=1.0"} - if content_for?(:meta_description) %meta{:description => yield(:meta_description)}/ diff --git a/app/views/phone_books/_index_core.html.haml b/app/views/phone_books/_index_core.html.haml index 09ce3a3..290a12e 100644 --- a/app/views/phone_books/_index_core.html.haml +++ b/app/views/phone_books/_index_core.html.haml @@ -5,7 +5,9 @@ %th %span.visible-desktop = t('phone_books.index.description') - %th= t('phone_books.index.count') + %th + %span.visible-desktop + = t('phone_books.index.count') %tbody - for phone_book in phone_books @@ -16,6 +18,7 @@ %span.visible-desktop = phone_book.description %td - = number_with_delimiter( phone_book.phone_book_entries.count ) + %span.visible-desktop + = number_with_delimiter( phone_book.phone_book_entries.count ) =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => phone_book.phone_bookable, :child => phone_book} \ No newline at end of file diff --git a/app/views/sessions/new.html.haml b/app/views/sessions/new.html.haml index 75dd3de..0c5c96d 100644 --- a/app/views/sessions/new.html.haml +++ b/app/views/sessions/new.html.haml @@ -1,8 +1,12 @@ - content_for :title, t("sessions.new.page_title") -= simple_form_for :sessions, :url => sessions_path do |t| - = t.input :login_data, :label => t('sessions.form.email'), :autofocus => true - = t.input :password, :label => t('sessions.form.password'), :required => false - = t.input :reset_password, :label => t('sessions.form.reset_password'), :as => :boolean - .form-actions - = t.button :submit, :value => 'Login' +.row + .span12 + %h1=t("sessions.new.page_title") + + = simple_form_for :sessions, :url => sessions_path do |t| + = t.input :login_data, :label => t('sessions.form.email'), :autofocus => true + = t.input :password, :label => t('sessions.form.password'), :required => false + = t.input :reset_password, :label => t('sessions.form.reset_password'), :as => :boolean + .form-actions + = t.button :submit, :value => 'Login' -- cgit v1.2.3 From 16c8605ad879bf0ac0c46bc24f2e9cd5c62e3a7d Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 26 Feb 2013 16:25:05 +0100 Subject: Bugfix #204 --- app/views/backup_jobs/show.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/views/backup_jobs/show.html.haml b/app/views/backup_jobs/show.html.haml index ddc4766..8bb270f 100644 --- a/app/views/backup_jobs/show.html.haml +++ b/app/views/backup_jobs/show.html.haml @@ -27,8 +27,8 @@ %strong= t('backup_jobs.show.size_of_the_backup') + ":" %td - if @backup_job.backup_file? - %a{:href => backup_job.backup_file.url} + %a{:href => @backup_job.backup_file.url} %i{:class => 'icon-download'} - = number_to_human_size(backup_job.backup_file.size, :precision => 2) + = number_to_human_size(@backup_job.backup_file.size, :precision => 2) = render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @backup_job } \ No newline at end of file -- cgit v1.2.3 From fc535da83c53f37fbc03caf72f61c01494ba6048 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Tue, 26 Feb 2013 17:31:13 +0100 Subject: load_resource :sip_account, :only => [:call] --- app/controllers/sip_accounts_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/controllers/sip_accounts_controller.rb b/app/controllers/sip_accounts_controller.rb index 022858c..ef1aab8 100644 --- a/app/controllers/sip_accounts_controller.rb +++ b/app/controllers/sip_accounts_controller.rb @@ -1,7 +1,7 @@ class SipAccountsController < ApplicationController load_resource :user load_resource :tenant - #load_resource :sip_account + load_resource :sip_account, :only => [:call] load_and_authorize_resource :sip_account, :through => [:user, :tenant ] before_filter :set_and_authorize_parent -- 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') 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') 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') 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') 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 bc45716cb2aa3cd81ad5519edac8e09239a45984 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 26 Feb 2013 16:16:46 -0500 Subject: buttons added --- app/views/sip_accounts/show.html.haml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'app') diff --git a/app/views/sip_accounts/show.html.haml b/app/views/sip_accounts/show.html.haml index 12e54c3..fd955dd 100644 --- a/app/views/sip_accounts/show.html.haml +++ b/app/views/sip_accounts/show.html.haml @@ -62,14 +62,24 @@ %p %strong= t('sip_accounts.show.tel_protocol') + ':' - %a{:href => '', :onclick => "navigator.registerProtocolHandler(\"tel\", \"#{@register_tel_protocol}\", \"#{@sip_account.to_s}\");" }= t('sip_accounts.show.register_tel_protocol') +%p + %a.btn.btn-small.btn-default{ :href => '', :onclick => "navigator.registerProtocolHandler(\"tel\", \"#{@register_tel_protocol}\", \"#{@sip_account.to_s}\");" } + %i.icon-plus + = t('sip_accounts.show.register_tel_protocol') %p %strong= t('ringtones.name') + ':' - if @sip_account.ringtones.count > 0 - = link_to @sip_account.ringtones.first, sip_account_ringtone_path(@sip_account, @sip_account.ringtones.first) + = @sip_account.ringtones.first + %p + %a.btn.btn-small.btn-warning{:href => edit_sip_account_ringtone_path(@sip_account, @sip_account.ringtones.first) } + %i.icon-edit.icon-white + =t('ringtones.index.actions.edit') - else - = link_to t('ringtones.set_a_ringtone'), new_sip_account_ringtone_path(@sip_account) + %p + %a.btn.btn-small.btn-default{ :href => new_sip_account_ringtone_path(@sip_account) } + %i.icon-plus + = t('ringtones.set_a_ringtone') - if @sip_account.phone_numbers.count > 0 || can?(:create, @sip_account.phone_numbers.build) %h2= t('phone_numbers.index.page_title') -- cgit v1.2.3 From 22bd2d6fb05e488527beb9c0e134c1fa47673a35 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 26 Feb 2013 16:29:16 -0500 Subject: use partials for buttons --- app/views/phone_numbers/show.html.haml | 15 ++++++++------- app/views/sip_accounts/show.html.haml | 10 ++-------- 2 files changed, 10 insertions(+), 15 deletions(-) (limited to 'app') diff --git a/app/views/phone_numbers/show.html.haml b/app/views/phone_numbers/show.html.haml index de6cb1b..9fe6ea4 100644 --- a/app/views/phone_numbers/show.html.haml +++ b/app/views/phone_numbers/show.html.haml @@ -9,15 +9,16 @@ %strong= t('phone_numbers.show.number') + ":" = @phone_number.to_s += render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @phone_number.phone_numberable, :child => @phone_number } + - if @ringtoneable_classes.has_key?(@phone_number.phone_numberable.class.to_s) %p - %strong= t('ringtones.name') + ':' - - if @phone_number.ringtones.count > 0 - = link_to @phone_number.ringtones.first, phone_number_ringtone_path(@phone_number, @phone_number.ringtones.first) - - else - = link_to t('ringtones.set_a_ringtone'), new_phone_number_ringtone_path(@phone_number) - -= render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @phone_number.phone_numberable, :child => @phone_number } + %strong= t('ringtones.name') + ':' + - if @phone_number.ringtones.count > 0 + = @phone_number.ringtones.first + = render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @phone_number, :child => @phone_number.ringtones.first } + - else + = render :partial => 'shared/create_link', :locals => { :parent => @phone_number, :child_class => Ringtone } - if @forwardable_classes.has_key?(@phone_number.phone_numberable.class.to_s) %h3= t("call_forwards.index.page_title") diff --git a/app/views/sip_accounts/show.html.haml b/app/views/sip_accounts/show.html.haml index fd955dd..0aaf920 100644 --- a/app/views/sip_accounts/show.html.haml +++ b/app/views/sip_accounts/show.html.haml @@ -71,15 +71,9 @@ %strong= t('ringtones.name') + ':' - if @sip_account.ringtones.count > 0 = @sip_account.ringtones.first - %p - %a.btn.btn-small.btn-warning{:href => edit_sip_account_ringtone_path(@sip_account, @sip_account.ringtones.first) } - %i.icon-edit.icon-white - =t('ringtones.index.actions.edit') + = render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @sip_account, :child => @sip_account.ringtones.first } - else - %p - %a.btn.btn-small.btn-default{ :href => new_sip_account_ringtone_path(@sip_account) } - %i.icon-plus - = t('ringtones.set_a_ringtone') + = render :partial => 'shared/create_link', :locals => { :parent => @sip_account, :child_class => Ringtone } - if @sip_account.phone_numbers.count > 0 || can?(:create, @sip_account.phone_numbers.build) %h2= t('phone_numbers.index.page_title') -- 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') 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') 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') 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 +++++ app/views/layouts/_navbar.html.haml | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'app') 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. # diff --git a/app/views/layouts/_navbar.html.haml b/app/views/layouts/_navbar.html.haml index a7f47cf..8004c0e 100644 --- a/app/views/layouts/_navbar.html.haml +++ b/app/views/layouts/_navbar.html.haml @@ -3,10 +3,12 @@ .container %span.hidden-phone %a.brand{:href => (current_user.nil? ? '/' : tenant_path(current_user.current_tenant))} - Gemeinschaft 5 + Gemeinschaft 5.1 .nav-collapse.collapse %ul.nav + - if !GemeinschaftSetup.any? + %li=link_to t('restore_jobs.new.page_title'), new_restore_job_path - if current_user && GemeinschaftSetup.any? && current_user.admin? - if current_page?(page_help_path) %li.active -- 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') 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 41e17e9f3e184975e8b429d3fb06d822c49068bf Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Wed, 27 Feb 2013 10:43:17 +0100 Subject: load_and_authorize_resource :sip_account, :only => [:call] #213 --- app/controllers/sip_accounts_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/controllers/sip_accounts_controller.rb b/app/controllers/sip_accounts_controller.rb index ef1aab8..621bd3c 100644 --- a/app/controllers/sip_accounts_controller.rb +++ b/app/controllers/sip_accounts_controller.rb @@ -1,7 +1,7 @@ class SipAccountsController < ApplicationController load_resource :user load_resource :tenant - load_resource :sip_account, :only => [:call] + load_and_authorize_resource :sip_account, :only => [:call] load_and_authorize_resource :sip_account, :through => [:user, :tenant ] before_filter :set_and_authorize_parent -- 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/controllers/calls_controller.rb | 54 ++++++++++++++++++++++++++++++++++- app/models/call.rb | 39 +++++++++++++++++++++++-- app/models/sip_account.rb | 2 ++ app/views/calls/_form.html.haml | 7 +++++ app/views/calls/_form_core.html.haml | 2 ++ app/views/calls/_index_core.html.haml | 34 ++++++++++++++++++++-- app/views/calls/index.html.haml | 6 ++-- app/views/calls/new.html.haml | 3 ++ app/views/sip_accounts/show.html.haml | 6 +++- 9 files changed, 143 insertions(+), 10 deletions(-) create mode 100644 app/views/calls/_form.html.haml create mode 100644 app/views/calls/_form_core.html.haml create mode 100644 app/views/calls/new.html.haml (limited to 'app') diff --git a/app/controllers/calls_controller.rb b/app/controllers/calls_controller.rb index d5f3b42..5534b1b 100644 --- a/app/controllers/calls_controller.rb +++ b/app/controllers/calls_controller.rb @@ -1,6 +1,58 @@ class CallsController < ApplicationController + load_resource :sip_account + load_resource :call + before_filter :set_and_authorize_parent + def index - @calls = Call.all + if @parent + @calls = @parent.calls + else + @calls = Call.all + end + end + + def new + if !params[:url].blank? + protocol, separator, phone_number = params[:url].partition(':') + if ! phone_number.blank? + @call = @parent.calls.new() + @call.dest = phone_number + end + elsif !params[:number].blank? + @call = @parent.calls.new() + @call.dest = params[:number] + end + end + + def show + redirect_to :index + end + + def create + params[:call][:sip_account] = @sip_account + @call = Call.create(params[:call]) + + if @call && @call.call + m = method( :"#{@parent.class.name.underscore}_calls_url" ) + redirect_to m.( @parent ), :notice => t('calls.controller.successfuly_created') + else + render :new + end + end + + def destroy + @call.destroy + if @parent + m = method( :"#{@parent.class.name.underscore}_calls_url" ) + else + m = method( :"calls_url" ) + end + redirect_to m.(@parent), :notice => t('calls.controller.successfuly_destroyed') + end + + private + def set_and_authorize_parent + @parent = @sip_account end end 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 diff --git a/app/views/calls/_form.html.haml b/app/views/calls/_form.html.haml new file mode 100644 index 0000000..ccdcd72 --- /dev/null +++ b/app/views/calls/_form.html.haml @@ -0,0 +1,7 @@ += simple_form_for([ @parent, @call ]) do |f| + = f.error_notification + + = render "form_core", :f => f + + .form-actions + = f.button :submit, conditional_t('calls.form.submit') diff --git a/app/views/calls/_form_core.html.haml b/app/views/calls/_form_core.html.haml new file mode 100644 index 0000000..4cdd55e --- /dev/null +++ b/app/views/calls/_form_core.html.haml @@ -0,0 +1,2 @@ +.inputs + = f.input :dest, :as => :string, :label => t('calls.form.destination.label'), :hint => conditional_hint('calls.form.destination.hint'), :autofocus => true diff --git a/app/views/calls/_index_core.html.haml b/app/views/calls/_index_core.html.haml index 10f79f1..e5b769e 100644 --- a/app/views/calls/_index_core.html.haml +++ b/app/views/calls/_index_core.html.haml @@ -1,10 +1,38 @@ %table.table.table-striped %thead %tr - %th= t('calls.index.uuid') + %th + %th= t('calls.index.created') + %th= t('calls.index.destination') + %th= t('calls.index.caller') + %th= t('calls.index.callee') + %th= t('calls.index.callstate') + %th= t('calls.index.codecs') + %th %tbody - - for call in @calls + - for call in calls %tr %td - = call.uuid + - if call.direction == 'inbound' + %i.icon-arrow-left + - else + %i.icon-arrow-right + %td + = call.created + %td + = call.dest + %td + = "#{call.cid_name} #{call.cid_num}" + %td + = "#{call.callee_name} #{call.callee_num}" + %td + = call.callstate + %td + = "#{call.read_codec}/#{call.write_codec}" + + %td + %p + %a.btn.btn-small.btn-danger{'data-confirm' => t('calls.index.actions.confirm_destroy'), 'data-method' => 'delete', :href => method( :"#{parent.class.name.underscore}_call_path" ).(parent, call), :rel => 'nofollow'} + %i.icon-trash.icon-white + =t('calls.index.actions.destroy') diff --git a/app/views/calls/index.html.haml b/app/views/calls/index.html.haml index be678cd..a87f809 100644 --- a/app/views/calls/index.html.haml +++ b/app/views/calls/index.html.haml @@ -1,6 +1,8 @@ - content_for :title, t("calls.index.page_title") - if @calls.count > 0 - = render "index_core", :calls => @calls + = render "index_core", :calls => @calls, :parent => @parent -= render :partial => 'shared/create_link', :locals => {:parent => @parent, :child_class => Call} \ No newline at end of file +%a.btn.btn-small.btn-default{:href => method( :"new_#{@parent.class.name.underscore}_call_path" ).(@parent) } + %i.icon-plus + =t("calls.index.actions.create") diff --git a/app/views/calls/new.html.haml b/app/views/calls/new.html.haml new file mode 100644 index 0000000..44bb6ae --- /dev/null +++ b/app/views/calls/new.html.haml @@ -0,0 +1,3 @@ +- content_for :title, t("calls.new.page_title") + += render "form" diff --git a/app/views/sip_accounts/show.html.haml b/app/views/sip_accounts/show.html.haml index 0aaf920..365aea8 100644 --- a/app/views/sip_accounts/show.html.haml +++ b/app/views/sip_accounts/show.html.haml @@ -94,4 +94,8 @@ - if @sip_account.softkeys.count > 0 = render "softkeys/index_core", :softkeys => @sip_account.softkeys %br - = render :partial => 'shared/create_link', :locals => { :parent => @sip_account, :child_class => Softkey } \ No newline at end of file + = render :partial => 'shared/create_link', :locals => { :parent => @sip_account, :child_class => Softkey } + +- if @sip_account.calls.count > 0 + %h2= t("calls.index.page_title") + = render "calls/index_core", :calls => @sip_account.calls, :parent => @sip_account -- cgit v1.2.3