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 +- 2 files changed, 41 insertions(+), 21 deletions(-) (limited to 'app/controllers') 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 -- cgit v1.2.3