summaryrefslogtreecommitdiff
path: root/app/controllers/call_forwards_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/call_forwards_controller.rb')
-rw-r--r--app/controllers/call_forwards_controller.rb60
1 files changed, 41 insertions, 19 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