diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/call_forwards_controller.rb | 60 | ||||
-rw-r--r-- | app/controllers/calls_controller.rb | 54 | ||||
-rw-r--r-- | app/controllers/config_siemens_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/config_snom_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/fax_documents_controller.rb | 18 | ||||
-rw-r--r-- | app/controllers/group_memberships_controller.rb | 53 | ||||
-rw-r--r-- | app/controllers/group_permissions_controller.rb | 51 | ||||
-rw-r--r-- | app/controllers/groups_controller.rb | 52 | ||||
-rw-r--r-- | app/controllers/intruders_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/page_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/restore_jobs_controller.rb | 25 | ||||
-rw-r--r-- | app/controllers/ringtones_controller.rb | 12 | ||||
-rw-r--r-- | app/controllers/sip_accounts_controller.rb | 32 | ||||
-rw-r--r-- | app/controllers/trigger_controller.rb | 36 |
14 files changed, 349 insertions, 56 deletions
diff --git a/app/controllers/call_forwards_controller.rb b/app/controllers/call_forwards_controller.rb index b1ced87..34fb77a 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_forwards_url" ) + redirect_to m.( @parent ), :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_forwards_url" ) + redirect_to m.( @parent ), :notice => t('call_forwards.controller.successfuly_updated') else @call_forwarding_destinations = call_forwarding_destination_types() render :edit @@ -70,30 +74,48 @@ class CallForwardsController < ApplicationController def destroy @call_forward.destroy - redirect_to phone_number_call_forwards_path( @phone_number ), :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 + 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) + + 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? - 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/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/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/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 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 => "<!-- Raw image not found -->", + ) + end + } end end diff --git a/app/controllers/group_memberships_controller.rb b/app/controllers/group_memberships_controller.rb new file mode 100644 index 0000000..e0f897b --- /dev/null +++ b/app/controllers/group_memberships_controller.rb @@ -0,0 +1,53 @@ +class GroupMembershipsController < ApplicationController + load_and_authorize_resource :group + load_and_authorize_resource :group_membership, :through => [:group] + + before_filter :spread_breadcrumbs + + 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..b6517b1 --- /dev/null +++ b/app/controllers/group_permissions_controller.rb @@ -0,0 +1,51 @@ +class GroupPermissionsController < ApplicationController + load_and_authorize_resource :group + load_and_authorize_resource :group_permission, :through => [:group] + + before_filter :spread_breadcrumbs + + def index + end + + def show + end + + def new + @group_permission.target_group_id = @group_permission.group_id + 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..74ad7c8 --- /dev/null +++ b/app/controllers/groups_controller.rb @@ -0,0 +1,52 @@ +class GroupsController < ApplicationController + load_and_authorize_resource :group + before_filter :spread_breadcrumbs + + 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/controllers/intruders_controller.rb b/app/controllers/intruders_controller.rb index 147e06d..d3c767e 100644 --- a/app/controllers/intruders_controller.rb +++ b/app/controllers/intruders_controller.rb @@ -1,6 +1,8 @@ class IntrudersController < ApplicationController + load_and_authorize_resource :intruder + def index - @intruders = Intruder.all + @intruders = Intruder.order('list_type ASC, contact_last DESC').all spread_breadcrumbs end 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/controllers/restore_jobs_controller.rb b/app/controllers/restore_jobs_controller.rb new file mode 100644 index 0000000..bfecc33 --- /dev/null +++ b/app/controllers/restore_jobs_controller.rb @@ -0,0 +1,25 @@ +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 + session[:user_id] = nil + redirect_to @restore_job, :notice => t('restore_jobs.controller.successfuly_created') + else + render :new + end + end +end diff --git a/app/controllers/ringtones_controller.rb b/app/controllers/ringtones_controller.rb index 7ffe30e..e5a4f64 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 @@ -14,12 +15,13 @@ class RingtonesController < ApplicationController def new @ringtone = @parent.ringtones.build + @ringtone.bellcore_id = GsParameter.get('default_ringtone', 'dialplan', 'parameters') end 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 +32,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 +40,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/controllers/sip_accounts_controller.rb b/app/controllers/sip_accounts_controller.rb index b5c3ae4..621bd3c 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_and_authorize_resource :sip_account, :only => [:call] load_and_authorize_resource :sip_account, :through => [:user, :tenant ] before_filter :set_and_authorize_parent @@ -10,6 +11,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 +76,36 @@ class SipAccountsController < ApplicationController redirect_to :root, :notice => t('sip_accounts.controller.successfuly_destroyed') end + def call + 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 => "<!-- CALL -->", + ) + return; + end + render( + :status => 404, + :layout => false, + :content_type => 'text/plain', + :text => "<!-- Number not found -->", + ) + return; + end + + render( + :status => 404, + :layout => false, + :content_type => 'text/plain', + :text => "<!-- Call URL not found -->", + ) + end + private def set_and_authorize_parent @parent = @user || @tenant diff --git a/app/controllers/trigger_controller.rb b/app/controllers/trigger_controller.rb index 2b491be..64a5f91 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 = "/tmp/" def voicemail if !params[:sip_account_id].blank? @@ -68,44 +65,29 @@ 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 = fax_document.tiff_to_pdf - if !File.exists?( "#{TMP_DIR}#{tiff_file}" ) + if !pdf_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 ) - fax_document.state = 'unsuccessful' - fax_document.save - next + 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("#{TMP_DIR}#{tiff_file}"); - rescue => e - logger.error "Raw fax file could not be deleted: #{TMP_DIR}#{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 |