diff options
Diffstat (limited to 'app/controllers')
25 files changed, 873 insertions, 140 deletions
diff --git a/app/controllers/api/v1/pager_groups_controller.rb b/app/controllers/api/v1/pager_groups_controller.rb new file mode 100644 index 0000000..753e938 --- /dev/null +++ b/app/controllers/api/v1/pager_groups_controller.rb @@ -0,0 +1,39 @@ +module Api + module V1 + class PagerGroupsController < ApplicationController + skip_before_filter :verify_authenticity_token + respond_to :json + + def index + @pager_groups = PagerGroup.all + respond_with @pager_groups + end + + def show + @pager_group = PagerGroup.find(params[:id]) + respond_with @pager_group + end + + def new + if params[:sip_account_id] && SipAccount.find(params[:sip_account_id]) + @pager_group = SipAccount.find(params[:sip_account_id]).pager_groups.new + @pager_group.callback_url = params[:callback_url] + @pager_group.pager_group_destination_ids = params[:pager_group_destination_ids] + if @pager_group.save + respond_with @pager_group + end + end + + end + + def destroy + @pager_group = PagerGroup.find(params[:id]) + if @pager_group + @pager_group.destroy + respond_with @pager_group + end + end + + end + end +end diff --git a/app/controllers/api/v1/phone_numbers_controller.rb b/app/controllers/api/v1/phone_numbers_controller.rb new file mode 100644 index 0000000..ff58fd3 --- /dev/null +++ b/app/controllers/api/v1/phone_numbers_controller.rb @@ -0,0 +1,23 @@ +module Api + module V1 + class PhoneNumbersController < ApplicationController + respond_to :json + + def index + if params[:ids] + @phone_numbers = PhoneNumber.where(:id => params[:ids]) + else + @phone_numbers = PhoneNumber.all + end + + respond_with @phone_numbers + end + + def show + @phone_number = PhoneNumber.find(params[:id]) + + respond_with @phone_number + end + end + end +end diff --git a/app/controllers/api/v1/sip_accounts_controller.rb b/app/controllers/api/v1/sip_accounts_controller.rb new file mode 100644 index 0000000..6f305a4 --- /dev/null +++ b/app/controllers/api/v1/sip_accounts_controller.rb @@ -0,0 +1,23 @@ +module Api + module V1 + class SipAccountsController < ApplicationController + respond_to :json + + def index + if params[:ids] + @sip_accounts = SipAccount.where(:id => params[:ids]) + else + @sip_accounts = SipAccount.all + end + + respond_with @sip_accounts + end + + def show + @sip_account = SipAccount.find(params[:id]) + + respond_with @sip_account + end + end + end +end diff --git a/app/controllers/api/v1/switchboard_entries_controller.rb b/app/controllers/api/v1/switchboard_entries_controller.rb new file mode 100644 index 0000000..688f108 --- /dev/null +++ b/app/controllers/api/v1/switchboard_entries_controller.rb @@ -0,0 +1,23 @@ +module Api + module V1 + class SwitchboardEntriesController < ApplicationController + respond_to :json + + def index + if params[:ids] + @switchboard_entries = SwitchboardEntry.where(:id => params[:ids]) + else + @switchboard_entries = SwitchboardEntry.all + end + + respond_with @switchboard_entries + end + + def show + @switchboard_entry = SwitchboardEntry.find(params[:id]) + + respond_with @switchboard_entry + end + end + end +end
\ No newline at end of file diff --git a/app/controllers/api/v1/switchboards_controller.rb b/app/controllers/api/v1/switchboards_controller.rb new file mode 100644 index 0000000..e6996ca --- /dev/null +++ b/app/controllers/api/v1/switchboards_controller.rb @@ -0,0 +1,21 @@ +module Api + module V1 + class SwitchboardsController < ApplicationController + respond_to :json + + def index + @user = current_user + @switchboards = @user.switchboards + + respond_with @switchboards + end + + def show + @user = current_user + @switchboard = @user.switchboards.find(params[:id]) + + respond_with @switchboard + end + end + end +end diff --git a/app/controllers/call_forwards_controller.rb b/app/controllers/call_forwards_controller.rb index b30ee9e..1721aa3 100644 --- a/app/controllers/call_forwards_controller.rb +++ b/app/controllers/call_forwards_controller.rb @@ -30,6 +30,7 @@ class CallForwardsController < ApplicationController @call_forward.active = true @call_forwarding_destinations = call_forwarding_destination_types() @call_forward.destination = GsParameter.get('CALLFORWARD_DESTINATION_DEFAULT').to_s if defined?(GsParameter.get('CALLFORWARD_DESTINATION_DEFAULT')) + @destination_phone_number = @call_forward.destination @available_call_forward_cases = [] CallForwardCase.all.each do |available_call_forward_case| @@ -45,6 +46,8 @@ class CallForwardsController < ApplicationController @call_forward.call_forward_case_id = CallForwardCase.find_by_value('noanswer').id @call_forward.timeout = 45 end + + @available_greetings = available_greetings() end def create @@ -62,6 +65,8 @@ class CallForwardsController < ApplicationController def edit @available_call_forward_cases = CallForwardCase.all @call_forwarding_destinations = call_forwarding_destination_types() + @available_greetings = available_greetings() + @destination_phone_number = @call_forward.destination if @call_forward.call_forwarding_destination == ':PhoneNumber' end def update @@ -82,7 +87,6 @@ class CallForwardsController < ApplicationController end private - private def set_and_authorize_parent @parent = @phone_number || @sip_account || @automatic_call_distributor || @hunt_group authorize! :read, @parent @@ -92,6 +96,14 @@ class CallForwardsController < ApplicationController if @parent if @parent.class == PhoneNumber && @parent.phone_numberable_type == 'SipAccount' @sip_account = @parent.phone_numberable + elsif @parent.class == PhoneNumber && @parent.phone_numberable_type == 'HuntGroup' + add_breadcrumb t("hunt_groups.index.page_title"), tenant_hunt_groups_path(@parent.phone_numberable.tenant) + add_breadcrumb @parent.phone_numberable, tenant_hunt_group_path(@parent.phone_numberable.tenant, @parent.phone_numberable) + add_breadcrumb t("phone_numbers.index.page_title"), hunt_group_phone_numbers_path(@parent.phone_numberable) + add_breadcrumb @parent, hunt_group_phone_number_path(@parent.phone_numberable, @parent) + elsif @parent.class == HuntGroup + add_breadcrumb t("hunt_groups.index.page_title"), tenant_hunt_groups_path(@parent.tenant) + add_breadcrumb @parent, tenant_hunt_group_path(@parent.tenant, @parent) end if @sip_account @@ -127,29 +139,101 @@ class CallForwardsController < ApplicationController end def call_forwarding_destination_types - + destinations_hash = {} phone_number_destination = CallForwardingDestination.new() phone_number_destination.id = ':PhoneNumber' phone_number_destination.label = 'Phone Number' - voice_mail_destination = CallForwardingDestination.new() - voice_mail_destination.id = ':Voicemail' - voice_mail_destination.label = 'Voice Mail' call_forwarding_destinations = [ phone_number_destination, - voice_mail_destination, ] + if @parent.class == SipAccount || @parent.class == User || @parent.class == Tenant + @parent.voicemail_accounts.each do |voicemail_account| + call_forwards_destination = CallForwardingDestination.new() + call_forwards_destination.id = "#{voicemail_account.id}:VoicemailAccount" + call_forwards_destination.label = "VoicemailAccount: #{voicemail_account.to_s}" + if !destinations_hash[call_forwards_destination.id] + destinations_hash[call_forwards_destination.id] = true + call_forwarding_destinations << call_forwards_destination + end + end + end + + if @parent.class == SipAccount + sip_account = @parent + group_ids = Group.target_group_ids_by_permission(:forward_to, sip_account.groups) + + if sip_account.sip_accountable.class == User || sip_account.sip_accountable.class == Tenant + group_ids = group_ids + Group.target_group_ids_by_permission(:forward_to, sip_account.sip_accountable.groups) + sip_account.sip_accountable.voicemail_accounts.each do |voicemail_account| + call_forwards_destination = CallForwardingDestination.new() + call_forwards_destination.id = "#{voicemail_account.id}:VoicemailAccount" + call_forwards_destination.label = "VoicemailAccount: #{voicemail_account.to_s}" + if !destinations_hash[call_forwards_destination.id] + destinations_hash[call_forwards_destination.id] = true + call_forwarding_destinations << call_forwards_destination + end + end + end + + GroupMembership.where(:group_id => group_ids, :item_type => 'VoicemailAccount').each do |group_member| + call_forwards_destination = CallForwardingDestination.new() + call_forwards_destination.id = "#{group_member.item.id}:VoicemailAccount" + call_forwards_destination.label = "VoicemailAccount: #{group_member.item.to_s}" + if !destinations_hash[call_forwards_destination.id] + destinations_hash[call_forwards_destination.id] = true + call_forwarding_destinations << call_forwards_destination + end + end + end + + if @parent.class == PhoneNumber + if @parent.phone_numberable.class == SipAccount + sip_account = @parent.phone_numberable + if sip_account.sip_accountable.class == User || sip_account.sip_accountable.class == Tenant + sip_account.sip_accountable.voicemail_accounts.each do |voicemail_account| + call_forwards_destination = CallForwardingDestination.new() + call_forwards_destination.id = "#{voicemail_account.id}:VoicemailAccount" + call_forwards_destination.label = "VoicemailAccount: #{voicemail_account.to_s}" + if !destinations_hash[call_forwards_destination.id] + destinations_hash[call_forwards_destination.id] = true + call_forwarding_destinations << call_forwards_destination + end + end + end + end + end + if GuiFunction.display?('huntgroup_in_destination_field_in_call_forward_form', current_user) HuntGroup.all.each do |hunt_group| - hunt_group_destination = CallForwardingDestination.new() - hunt_group_destination.id = "#{hunt_group.id}:HuntGroup" - hunt_group_destination.label = "HuntGroup: #{hunt_group.to_s}" - call_forwarding_destinations.push(hunt_group_destination) + call_forwards_destination = CallForwardingDestination.new() + call_forwards_destination.id = "#{hunt_group.id}:HuntGroup" + call_forwards_destination.label = "HuntGroup: #{hunt_group.to_s}" + if !destinations_hash[call_forwards_destination.id] + destinations_hash[call_forwards_destination.id] = true + call_forwarding_destinations << call_forwards_destination + end end end return call_forwarding_destinations end + def available_greetings + if @parent.class == PhoneNumber + owner = @parent.phone_numberable + else + owner = @parent + end + + if owner.class == SipAccount + owner = owner.sip_accountable + elsif owner.class == FaxAccount + owner = owner.fax_accountable + end + + return GenericFile.where(:category => 'greeting', :owner_type => owner.class.to_s, :owner_id => owner.id).map {|x| [x.to_s, x.name] } + end + end diff --git a/app/controllers/call_histories_controller.rb b/app/controllers/call_histories_controller.rb index 2bfd4e3..a4d0c21 100644 --- a/app/controllers/call_histories_controller.rb +++ b/app/controllers/call_histories_controller.rb @@ -1,5 +1,8 @@ class CallHistoriesController < ApplicationController - + MAX_CALL_HISTORY_ENTRIES = 10000; + + helper_method :sort_column, :sort_descending + load_resource :sip_account before_filter :set_and_authorize_parent @@ -18,12 +21,7 @@ class CallHistoriesController < ApplicationController def index hunt_group_member_ids = PhoneNumber.where(:phone_numberable_type => 'HuntGroupMember', :number => @sip_account.phone_numbers.map {|a| a.number}).map {|a| a.phone_numberable_id} hunt_group_ids = HuntGroupMember.where(:id => hunt_group_member_ids, :active => true).map {|a| a.hunt_group_id} - calls = CallHistory.where('(call_historyable_type = "SipAccount" AND call_historyable_id = ?) OR (call_historyable_type = "HuntGroup" AND call_historyable_id IN (?))', @sip_account.id, hunt_group_ids).order('start_stamp DESC') - - @call_histories = calls.paginate( - :page => @pagination_page_number, - :per_page => GsParameter.get('DEFAULT_PAGINATION_ENTRIES_PER_PAGE') - ) + calls = CallHistory.where('(call_historyable_type = "SipAccount" AND call_historyable_id = ?) OR (call_historyable_type = "HuntGroup" AND call_historyable_id IN (?))', @sip_account.id, hunt_group_ids).order(sort_column + ' ' + (sort_descending ? 'DESC' : 'ASC')) @calls_count = calls.count @calls_received_count = calls.where(:entry_type => 'received').count @@ -32,10 +30,15 @@ class CallHistoriesController < ApplicationController @calls_forwarded_count = calls.where(:entry_type => 'forwarded').count if ! @type.blank? - @call_histories = @call_histories.where(:entry_type => @type) + @call_histories = calls.where(:entry_type => @type).limit(MAX_CALL_HISTORY_ENTRIES) + else + @call_histories = calls.limit(MAX_CALL_HISTORY_ENTRIES) end - @call_histories = @call_histories.order(:created_at).reverse_order.limit(1000) + @call_histories = @call_histories.paginate( + :page => @pagination_page_number, + :per_page => GsParameter.get('DEFAULT_PAGINATION_ENTRIES_PER_PAGE') + ) end @@ -102,4 +105,16 @@ class CallHistoriesController < ApplicationController end end + def sort_descending + if sort_column == 'start_stamp' && params[:desc].to_s.blank? + return true + end + + params[:desc].to_s == 'true' + end + + def sort_column + CallHistory.column_names.include?(params[:sort]) ? params[:sort] : 'start_stamp' + end + end diff --git a/app/controllers/call_routes_controller.rb b/app/controllers/call_routes_controller.rb index e5cf56a..dc0d175 100644 --- a/app/controllers/call_routes_controller.rb +++ b/app/controllers/call_routes_controller.rb @@ -92,6 +92,8 @@ class CallRoutesController < ApplicationController account = SipAccount.where(:id => params[:sip_account_id]).first elsif !params[:hunt_group_id].blank? account = HuntGroup.where(:id => params[:hunt_group_id]).first + elsif !params[:fax_account_id].blank? + account = FaxAccount.where(:id => params[:fax_account_id]).first end if account @@ -111,7 +113,7 @@ class CallRoutesController < ApplicationController private def call_route_parameter_params - params.require(:call_route).permit(:routing_table, :name, :endpoint_type, :endpoint_id, :position) + params.require(:call_route).permit(:routing_table, :name, :endpoint_type, :endpoint_id, :position, :xml) end def spread_breadcrumbs diff --git a/app/controllers/config_siemens_controller.rb b/app/controllers/config_siemens_controller.rb index 7d5eb3f..3fe3aaa 100644 --- a/app/controllers/config_siemens_controller.rb +++ b/app/controllers/config_siemens_controller.rb @@ -194,6 +194,18 @@ class ConfigSiemensController < ApplicationController #logger.debug(@phone_items) @my_nonce = params[:WorkpointMessage][:Message][:nonce] @new_settings = Array.new + + phone_parameters = GsParameter.get_list('phones', 'siemens') + phone_parameters.each do |name, value| + value = value.gsub!(/\{([a-z0-9_\.]+)\}/) { |v| + source = @sip_account + $1.split('.').each do |method| + source = source.send(method) if source.respond_to?(method) + end + source.to_s + } + @new_settings << [name, nil, value] + end @new_settings << ['dhcp', nil, 'true'] @new_settings << ['hostname', nil, mac_address.gsub(':', '') ] @@ -479,7 +491,6 @@ class ConfigSiemensController < ApplicationController @new_settings << ['feature-availability', 33, 'true'] # line overview @new_settings << ['feature-availability', 33, 'false'] # phone lock - @soft_keys = Array.new # Fill softkeys with keys dependent on limit of phone @sip_account.softkeys.order(:position).each do |sk| diff --git a/app/controllers/config_snom_controller.rb b/app/controllers/config_snom_controller.rb index 8db1d57..4b9489b 100644 --- a/app/controllers/config_snom_controller.rb +++ b/app/controllers/config_snom_controller.rb @@ -242,6 +242,7 @@ class ConfigSnomController < ApplicationController phone_sip_accounts = Array.new() if send_sensitve + phone_parameters = GsParameter.get_list('phones', 'snom') if @phone.sip_accounts && @phone.sip_accounts.count > 0 phone_sip_accounts = @phone.sip_accounts elsif @phone.fallback_sip_account @@ -250,6 +251,7 @@ class ConfigSnomController < ApplicationController expiry_seconds = GsParameter.get('SIP_EXPIRY_SECONDS') phone_sip_accounts.each do |sip_account| if (sip_account.sip_accountable_type == @phone.phoneable_type) and (sip_account.sip_accountable_id == @phone.phoneable_id) + snom_sip_account = { :id => sip_account.id, :active => 'on', @@ -259,10 +261,24 @@ class ConfigSnomController < ApplicationController :outbound => sip_account.host, :name => sip_account.auth_name, :realname => 'Call', - :idle_text => sip_account.caller_name, - :mailbox => "<sip:#{sip_account.auth_name}@#{sip_account.host}>", + :user_idle_text => sip_account.caller_name, :expiry => expiry_seconds, } + + if sip_account.voicemail_account + snom_sip_account[:mailbox] = "<sip:#{sip_account.voicemail_account.name}@#{sip_account.host}>" + end + + phone_parameters.each do |name, value| + snom_sip_account[name.to_sym] = value.gsub!(/\{([a-z0-9_\.]+)\}/) { |v| + source = sip_account + $1.split('.').each do |method| + source = source.send(method) if source.respond_to?(method) + end + source.to_s + } + end + @sip_accounts.push(snom_sip_account) sip_account_index = @sip_accounts.length sip_account.softkeys.order(:position).each do |softkey| @@ -786,7 +802,7 @@ AAAA' @phone_xml_object = { :name => 'snom_phone_directory', - :title => "$(lang:menu100_phone_book) #{@dialpad_keys}".strip, + :title => "#{t('config_snom.phone_book.title')} #{@dialpad_keys}".strip, :entries => [], :softkeys => [], } @@ -849,7 +865,6 @@ AAAA' end def call_history - if ! @sip_account render( :status => 404, @@ -860,10 +875,10 @@ AAAA' return end - if ['dialed', 'missed', 'received'].include? @type + if ['dialed', 'missed', 'received', 'forwarded'].include? @type @phone_xml_object = { :name => "snom_phone_directory", - :title => "$(lang:menu100_call_lists) - #{@type.to_s.camelize}", + :title => "#{t('config_snom.call_history.title')} - #{@type.to_s.camelize}", :entries => [] } @@ -893,11 +908,81 @@ AAAA' base_url = "#{request.protocol}#{request.host_with_port}#{request.fullpath.split("?")[0]}" @phone_xml_object = { :name => 'snom_phone_menu', - :title => '$(lang:menu100_call_lists)', + :title => t('config_snom.call_history.title'), + :entries => [ + {:text => t('config_snom.call_history.missed'), :url => "#{base_url}?&type=missed", :selected => false}, + {:text => t('config_snom.call_history.received'), :url => "#{base_url}?&type=received", :selected => false}, + {:text => t('config_snom.call_history.dialed'), :url => "#{base_url}?&type=dialed", :selected => false}, + ] + } + end + + respond_to { |format| + format.any { + self.formats = [ :xml ] + render :action => "_#{@phone_xml_object[:name]}" + } + } + + end + + def voicemail + if ! @sip_account + render( + :status => 404, + :layout => false, + :content_type => 'text/plain', + :text => "<!-- SipAccount not found -->", + ) + return + end + + if !@sip_account.voicemail_account + render( + :status => 404, + :layout => false, + :content_type => 'text/plain', + :text => "<!-- VoicemailAccount not found -->", + ) + return + end + + account = @sip_account.voicemail_account + + if ['read', 'unread'].include? @type + if @type == 'unread' + messages = account.voicemail_messages.where('read_epoch IS NULL OR read_epoch = 0') + elsif @type == 'read' + messages = account.voicemail_messages.where('read_epoch > 0') + end + @phone_xml_object = { + :name => "snom_phone_directory", + :title => t("config_snom.voicemail.#{@type}_count", :count => messages.count), + :entries => [] + } + messages.each do |message| + @phone_xml_object[:entries].push({ + :selected => false, + :number => "f-vmplay-#{message.uuid}", + :text => "#{call_date_compact(Time.at(message.created_epoch).to_datetime)} #{message.cid_name} #{message.cid_number}", + }) + end + elsif @type == 'settings' + base_url = "#{request.protocol}#{request.host_with_port}#{request.fullpath.split("?")[0]}" + @phone_xml_object = { + :name => 'snom_phone_menu', + :title => t('config_snom.voicemail_settings.title'), + :entries => [] + } + else + base_url = "#{request.protocol}#{request.host_with_port}#{request.fullpath.split("?")[0]}" + @phone_xml_object = { + :name => 'snom_phone_menu', + :title => account, :entries => [ - {:text => '$(lang:list_missed)', :url => "#{base_url}?&type=missed", :selected => false}, - {:text => '$(lang:list_taken)', :url => "#{base_url}?&type=received", :selected => false}, - {:text => '$(lang:list_dialed)', :url => "#{base_url}?&type=dialed", :selected => false}, + {:text => t('config_snom.voicemail.unread_count', :count => account.voicemail_messages.where('read_epoch IS NULL OR read_epoch = 0').count), :url => "#{base_url}?&type=unread", :selected => false}, + {:text => t('config_snom.voicemail.read_count', :count => account.voicemail_messages.where('read_epoch > 0').count), :url => "#{base_url}?&type=read", :selected => false}, + {:text => t('config_snom.voicemail.settings'), :url => "#{base_url}?&type=settings", :selected => false}, ] } end diff --git a/app/controllers/fax_accounts_controller.rb b/app/controllers/fax_accounts_controller.rb index 031080e..804cdb9 100644 --- a/app/controllers/fax_accounts_controller.rb +++ b/app/controllers/fax_accounts_controller.rb @@ -1,7 +1,8 @@ class FaxAccountsController < ApplicationController load_resource :user + load_resource :tenant load_resource :user_group - load_and_authorize_resource :fax_account, :through => [:user, :user_group] + load_and_authorize_resource :fax_account, :through => [:user, :user_group, :tenant] before_filter :set_and_authorize_parent before_filter :spread_breadcrumbs @@ -54,7 +55,7 @@ class FaxAccountsController < ApplicationController private def set_and_authorize_parent - @parent = @user || @user_group + @parent = @user || @user_group || @tenant authorize! :read, @parent end diff --git a/app/controllers/gateway_parameters_controller.rb b/app/controllers/gateway_parameters_controller.rb index d5ade9e..693a484 100644 --- a/app/controllers/gateway_parameters_controller.rb +++ b/app/controllers/gateway_parameters_controller.rb @@ -2,6 +2,8 @@ class GatewayParametersController < ApplicationController load_and_authorize_resource :gateway load_and_authorize_resource :gateway_parameter, :through => [:gateway] + before_filter :spread_breadcrumbs + def index @gateway_parameters = @gateway.gateway_parameters end @@ -41,4 +43,15 @@ class GatewayParametersController < ApplicationController @gateway_parameter.destroy redirect_to gateway_path(@gateway), :notice => t('gateway_parameters.controller.successfuly_destroyed') end + + private + def spread_breadcrumbs + add_breadcrumb t("gateways.index.page_title"), gateways_path + add_breadcrumb @gateway, @gateway + add_breadcrumb t("gateway_parameters.index.page_title"), gateway_gateway_parameters_url(@gateway) + + if @gateway_parameter && !@gateway_parameter.new_record? + add_breadcrumb @gateway_parameter + end + end end diff --git a/app/controllers/gateway_settings_controller.rb b/app/controllers/gateway_settings_controller.rb index 0304411..0fecdaf 100644 --- a/app/controllers/gateway_settings_controller.rb +++ b/app/controllers/gateway_settings_controller.rb @@ -2,6 +2,8 @@ class GatewaySettingsController < ApplicationController load_and_authorize_resource :gateway load_and_authorize_resource :gateway_setting, :through => [:gateway] + before_filter :spread_breadcrumbs + def index @gateway_settings = @gateway.gateway_settings end @@ -41,4 +43,15 @@ class GatewaySettingsController < ApplicationController @gateway_setting.destroy redirect_to gateway_path(@gateway), :notice => t('gateway_settings.controller.successfuly_destroyed') end + + private + def spread_breadcrumbs + add_breadcrumb t("gateways.index.page_title"), gateways_path + add_breadcrumb @gateway, @gateway + add_breadcrumb t("gateway_settings.index.page_title"), gateway_gateway_settings_url(@gateway) + + if @gateway_setting && !@gateway_setting.new_record? + add_breadcrumb @gateway_setting + end + end end diff --git a/app/controllers/gemeinschaft_setups_controller.rb b/app/controllers/gemeinschaft_setups_controller.rb index 4949fa7..96b1dcb 100644 --- a/app/controllers/gemeinschaft_setups_controller.rb +++ b/app/controllers/gemeinschaft_setups_controller.rb @@ -99,6 +99,22 @@ class GemeinschaftSetupsController < ApplicationController # Auto-Login: session[:user_id] = user.id + # Perimeter settings + if !@gemeinschaft_setup.detect_attacks + detect_attacks = GsParameter.where(:entity => 'events', :section => 'modules', :name => 'perimeter_defense').first + if detect_attacks + detect_attacks.update_attributes(:value => '0', :class_type => 'Integer') + end + end + + if !@gemeinschaft_setup.report_attacks + GsParameter.create(:entity => 'perimeter', :section => 'general', :name => 'report_url', :value => '', :class_type => 'String', :description => '') + report_url = GsParameter.where(:entity => 'perimeter', :section => 'general', :name => 'report_url').first + if report_url + report_url.update_attributes(:value => '', :class_type => 'String') + end + end + # Redirect to the user redirect_to page_help_path, :notice => t('gemeinschaft_setups.initial_setup.successful_setup') else diff --git a/app/controllers/generic_files_controller.rb b/app/controllers/generic_files_controller.rb new file mode 100644 index 0000000..69e00e1 --- /dev/null +++ b/app/controllers/generic_files_controller.rb @@ -0,0 +1,87 @@ +class GenericFilesController < ApplicationController + + load_resource :sip_account + load_resource :conference + load_resource :hunt_group + load_resource :automatic_call_distributor + load_resource :user + load_resource :tenant + load_resource :generic_file + + load_and_authorize_resource :generic_file, :through => [:sip_account, :conference, :hunt_group, :automatic_call_distributor, :user, :tenant] + + before_filter :set_and_authorize_parent + before_filter :spread_breadcrumbs + + def index + @generic_files = @parent.generic_files + end + + def show + respond_to do |format| + format.html + format.xml {render :xml => @generic_file} + format.all { + if request.format == @generic_file.file_type + send_file @generic_file.file.path, :type => @generic_file.file_type, :filename => "#{@generic_file.name}.#{request.parameters[:format].to_s}" + end + } + end + end + + def new + @generic_file = @parent.generic_files.build() + end + + def create + @generic_file = @parent.generic_files.new(params[:generic_file]) + if @generic_file.save + m = method( :"#{@parent.class.name.underscore}_generic_files_url" ) + redirect_to m.( @parent ), :notice => t('generic_files.controller.successfuly_created') + else + render :new + end + end + + def edit + @generic_file = GenericFile.find(params[:id]) + end + + def update + @generic_file = GenericFile.find(params[:id]) + if @generic_file.update_attributes(params[:generic_file]) + m = method( :"#{@parent.class.name.underscore}_generic_files_url" ) + redirect_to m.( @parent ), :notice => t('generic_files.controller.successfuly_updated') + else + render :edit + end + end + + def destroy + @generic_file = GenericFile.find(params[:id]) + @generic_file.destroy + m = method( :"#{@parent.class.name.underscore}_generic_files_url" ) + redirect_to m.( @parent ), :notice => t('generic_files.controller.successfuly_destroyed') + end + + private + def set_and_authorize_parent + @parent = @sip_account || @conference || @hunt_group || @automatic_call_distributor || @user || @tenant + + authorize! :read, @parent + end + + def spread_breadcrumbs + if @parent.class == User + add_breadcrumb t("users.index.page_title"), tenant_users_path(@parent.current_tenant) + add_breadcrumb @parent, tenant_user_path(@parent.current_tenant, @parent) + end + + add_breadcrumb t("generic_files.index.page_title"), method( :"#{@parent.class.name.underscore}_generic_files_url" ).(@parent) + + if !@generic_file.to_s.blank? + add_breadcrumb @generic_file + end + + end +end diff --git a/app/controllers/pager_group_destinations_controller.rb b/app/controllers/pager_group_destinations_controller.rb new file mode 100644 index 0000000..655054a --- /dev/null +++ b/app/controllers/pager_group_destinations_controller.rb @@ -0,0 +1,41 @@ +class PagerGroupDestinationsController < ApplicationController + def index + @pager_group_destinations = PagerGroupDestination.all + end + + def show + @pager_group_destination = PagerGroupDestination.find(params[:id]) + end + + def new + @pager_group_destination = PagerGroupDestination.new + end + + def create + @pager_group_destination = PagerGroupDestination.new(params[:pager_group_destination]) + if @pager_group_destination.save + redirect_to @pager_group_destination, :notice => t('pager_group_destinations.controller.successfuly_created') + else + render :new + end + end + + def edit + @pager_group_destination = PagerGroupDestination.find(params[:id]) + end + + def update + @pager_group_destination = PagerGroupDestination.find(params[:id]) + if @pager_group_destination.update_attributes(params[:pager_group_destination]) + redirect_to @pager_group_destination, :notice => t('pager_group_destinations.controller.successfuly_updated') + else + render :edit + end + end + + def destroy + @pager_group_destination = PagerGroupDestination.find(params[:id]) + @pager_group_destination.destroy + redirect_to pager_group_destinations_url, :notice => t('pager_group_destinations.controller.successfuly_destroyed') + end +end diff --git a/app/controllers/pager_groups_controller.rb b/app/controllers/pager_groups_controller.rb new file mode 100644 index 0000000..3b145b1 --- /dev/null +++ b/app/controllers/pager_groups_controller.rb @@ -0,0 +1,43 @@ +class PagerGroupsController < ApplicationController + load_resource :sip_account + load_resource :pager_group, :through => :sip_account + + def index + end + + def show + @pager_group = PagerGroup.find(params[:id]) + end + + def new + @pager_group = PagerGroup.new + end + + def create + @pager_group = PagerGroup.new(params[:pager_group]) + if @pager_group.save + redirect_to @pager_group, :notice => t('pager_groups.controller.successfuly_created') + else + render :new + end + end + + def edit + @pager_group = PagerGroup.find(params[:id]) + end + + def update + @pager_group = PagerGroup.find(params[:id]) + if @pager_group.update_attributes(params[:pager_group]) + redirect_to @pager_group, :notice => t('pager_groups.controller.successfuly_updated') + else + render :edit + end + end + + def destroy + @pager_group = PagerGroup.find(params[:id]) + @pager_group.destroy + redirect_to pager_groups_url, :notice => t('pager_groups.controller.successfuly_destroyed') + end +end diff --git a/app/controllers/phones_controller.rb b/app/controllers/phones_controller.rb index 3672390..77e7b5e 100644 --- a/app/controllers/phones_controller.rb +++ b/app/controllers/phones_controller.rb @@ -6,7 +6,20 @@ class PhonesController < ApplicationController before_filter :set_and_authorize_parent before_filter :spread_breadcrumbs + helper_method :sort_column, :sort_descending + def index + if @parent.class == Tenant + @phones = @parent.tenant_user_phones.order(sort_column + ' ' + (sort_descending ? 'DESC' : 'ASC')).paginate( + :page => params[:page], + :per_page => GsParameter.get('DEFAULT_PAGINATION_ENTRIES_PER_PAGE') + ) + else + @phones = @parent.phones.order(sort_column + ' ' + (sort_descending ? 'DESC' : 'ASC')).paginate( + :page => params[:page], + :per_page => GsParameter.get('DEFAULT_PAGINATION_ENTRIES_PER_PAGE') + ) + end end def show @@ -85,5 +98,13 @@ class PhonesController < ApplicationController end @fallback_sip_accounts = SipAccount.where(:sip_accountable_type => 'Tenant') - SipAccount.where(:id => used_sip_account_ids) end + + def sort_descending + params[:desc].to_s == 'true' + end + + def sort_column + Phone.column_names.include?(params[:sort]) ? params[:sort] : 'id' + end end diff --git a/app/controllers/sip_accounts_controller.rb b/app/controllers/sip_accounts_controller.rb index 0d34109..cd34953 100644 --- a/app/controllers/sip_accounts_controller.rb +++ b/app/controllers/sip_accounts_controller.rb @@ -6,7 +6,20 @@ class SipAccountsController < ApplicationController before_filter :set_and_authorize_parent before_filter :spread_breadcrumbs + helper_method :sort_column, :sort_descending + def index + if @parent.class == Tenant + @sip_accounts = @parent.tenant_user_sip_accounts.order(sort_column + ' ' + (sort_descending ? 'DESC' : 'ASC')).paginate( + :page => params[:page], + :per_page => GsParameter.get('DEFAULT_PAGINATION_ENTRIES_PER_PAGE') + ) + else + @sip_accounts = @parent.sip_accounts.order(sort_column + ' ' + (sort_descending ? 'DESC' : 'ASC')).paginate( + :page => params[:page], + :per_page => GsParameter.get('DEFAULT_PAGINATION_ENTRIES_PER_PAGE') + ) + end end def show @@ -22,7 +35,6 @@ class SipAccountsController < ApplicationController @sip_account.call_waiting = GsParameter.get('CALL_WAITING') @sip_account.clir = GsParameter.get('DEFAULT_CLIR_SETTING') @sip_account.clip = GsParameter.get('DEFAULT_CLIP_SETTING') - @sip_account.voicemail_pin = random_pin @sip_account.callforward_rules_act_per_sip_account = GsParameter.get('CALLFORWARD_RULES_ACT_PER_SIP_ACCOUNT_DEFAULT') if @parent.class == User @sip_account.hotdeskable = true @@ -36,6 +48,10 @@ class SipAccountsController < ApplicationController break unless SipAccount.exists?(:auth_name => @sip_account.auth_name) end @sip_account.password = SecureRandom.hex(GsParameter.get('DEFAULT_LENGTH_SIP_PASSWORD')) + + @sip_account.voicemail_account = VoicemailAccount.where(:voicemail_accountable_type => @parent.class.name, :voicemail_accountable_id => @parent.id).first + @sip_account.language_code = @parent.language.try(:code) + possible_voicemail_accounts end def create @@ -61,6 +77,7 @@ class SipAccountsController < ApplicationController end def edit + possible_voicemail_accounts end def update @@ -101,4 +118,17 @@ class SipAccountsController < ApplicationController end end + def possible_voicemail_accounts + @possible_voicemail_accounts = @sip_account.voicemail_accounts + @possible_voicemail_accounts = @possible_voicemail_accounts + @sip_account.sip_accountable.voicemail_accounts + end + + def sort_descending + params[:desc].to_s == 'true' + end + + def sort_column + SipAccount.column_names.include?(params[:sort]) ? params[:sort] : 'id' + end + end diff --git a/app/controllers/switchboards_controller.rb b/app/controllers/switchboards_controller.rb index 98008c1..3e2f8d6 100644 --- a/app/controllers/switchboards_controller.rb +++ b/app/controllers/switchboards_controller.rb @@ -15,6 +15,10 @@ class SwitchboardsController < ApplicationController def new @switchboard = @user.switchboards.build + @switchboard.show_avatars = true + @switchboard.entry_width = 2 + @switchboard.reload_interval = 2000 + @switchboard.amount_of_displayed_phone_numbers = 1 spread_breadcrumbs end @@ -52,7 +56,7 @@ class SwitchboardsController < ApplicationController private def switchboard_params - params.require(:switchboard).permit(:name) + params.require(:switchboard).permit(:name, :reload_interval, :show_avatars, :entry_width, :amount_of_displayed_phone_numbers) end def spread_breadcrumbs diff --git a/app/controllers/trigger_controller.rb b/app/controllers/trigger_controller.rb index 6b58d6a..3dbb2a5 100644 --- a/app/controllers/trigger_controller.rb +++ b/app/controllers/trigger_controller.rb @@ -1,49 +1,44 @@ class TriggerController < ApplicationController def voicemail - if !params[:sip_account_id].blank? - sip_account = SipAccount.where(:id => params[:sip_account_id].to_i).first - if sip_account - sip_account.voicemail_messages.where(:notification => nil).each do |message| - message.notification = false - message.save - if !File.exists?( message.file_path ) - next + if !params[:voicemail_account_id].blank? + voicemail_account = VoicemailAccount.where(:id => params[:voicemail_account_id].to_i).first + if voicemail_account + voicemail_messages = voicemail_account.voicemail_messages.where(:notification => nil) + if voicemail_messages.count > 0 + if voicemail_account.voicemail_accountable.class == User + user = voicemail_account.voicemail_accountable + elsif voicemail_account.voicemail_accountable.class == SipAccount && voicemail_account.voicemail_accountable.sip_accountable.class == User + user = voicemail_account.voicemail_accountable = voicemail_account.voicemail_accountable.sip_accountable end - user = sip_account.sip_accountable - if user.class != User - next + if user + PrivatePub.publish_to("/users/#{user.id}/messages/new", "$('#new_voicemail_or_fax_indicator').hide('fast').show('slow');") + PrivatePub.publish_to("/users/#{user.id}/messages/new", "document.title = '* ' + document.title.replace( '* ' , '');") end + end - # Indicate a new voicemail in the navigation bar. - # - PrivatePub.publish_to("/users/#{user.id}/messages/new", "$('#new_voicemail_or_fax_indicator').hide('fast').show('slow');") - PrivatePub.publish_to("/users/#{user.id}/messages/new", "document.title = '* ' + document.title.replace( '* ' , '');") + email = voicemail_account.notify_to - if user.email.blank? - next - end - - voicemail_settings = sip_account.voicemail_setting - if !voicemail_settings - voicemail_settings = VoicemailSetting.new(:notify => user.send_voicemail_as_email_attachment, :attachment => user.send_voicemail_as_email_attachment, :mark_read => user.send_voicemail_as_email_attachment) - end + if !email.blank? + voicemail_messages.each do |message| + message.notification = false + message.save + if !File.exists?( message.file_path ) + next + end + message.notification = true - message.notification = voicemail_settings.notify - if voicemail_settings.notify - if Notifications.new_voicemail(message, voicemail_settings.attachment).deliver - if voicemail_settings.purge + if Notifications.new_voicemail(message, voicemail_account, email, voicemail_account.notification_setting('attachment')).deliver + if voicemail_account.notification_setting('purge') message.delete next end message.save - if voicemail_settings.mark_read + if voicemail_account.notification_setting('mark_read') message.mark_read end end - else - message.save end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 584d08c..b4ef180 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -5,8 +5,14 @@ class UsersController < ApplicationController before_filter :set_and_authorize_parent before_filter :spread_breadcrumbs + + helper_method :sort_column, :sort_descending def index + @users = @parent.users.order(sort_column + ' ' + (sort_descending ? 'DESC' : 'ASC')).paginate( + :page => params[:page], + :per_page => GsParameter.get('DEFAULT_PAGINATION_ENTRIES_PER_PAGE') + ) end def show @@ -22,6 +28,12 @@ class UsersController < ApplicationController def create @user = @parent.users.build(params[:user]) if @user.save + if VoicemailAccount.where(:name => "user_#{@user.user_name}").count == 0 + @user.voicemail_accounts.create(:name => "user_#{@user.user_name}", :active => true ) + else + @user.voicemail_accounts.create(:active => true) + end + if @parent.class == Tenant @parent.tenant_memberships.create(:user => @user) if @parent.user_groups.exists?(:name => 'Users') @@ -82,4 +94,12 @@ class UsersController < ApplicationController end end + def sort_descending + params[:desc].to_s == 'true' + end + + def sort_column + User.column_names.include?(params[:sort]) ? params[:sort] : 'id' + end + end diff --git a/app/controllers/voicemail_accounts_controller.rb b/app/controllers/voicemail_accounts_controller.rb new file mode 100644 index 0000000..6e840fb --- /dev/null +++ b/app/controllers/voicemail_accounts_controller.rb @@ -0,0 +1,100 @@ +class VoicemailAccountsController < ApplicationController + load_resource :sip_account + load_resource :conference + load_resource :hunt_group + load_resource :automatic_call_distributor + load_resource :user + load_resource :tenant + load_resource :voicemail_account + + load_and_authorize_resource :phone_number, :through => [:sip_account, :conference, :hunt_group, :automatic_call_distributor, :user, :tenant] + + before_filter :set_and_authorize_parent + before_filter :spread_breadcrumbs + + def index + @voicemail_accounts = @parent.voicemail_accounts + end + + def show + + end + + def new + @voicemail_account = @parent.voicemail_accounts.build(:active => true) + if @parent.class == SipAccount && VoicemailAccount.where(:name => @parent.auth_name).count == 0 + @voicemail_account.name = @parent.auth_name + else + @voicemail_account.name = SecureRandom.hex(GsParameter.get('DEFAULT_LENGTH_SIP_AUTH_NAME')) + end + end + + def create + @voicemail_account = @parent.voicemail_accounts.new(params[:voicemail_account]) + if @voicemail_account.save + if @parent.class == User + @email = @parent.email + end + @voicemail_account.voicemail_settings.create(:name => 'pin', :value => ("%06d" % SecureRandom.random_number(999999)), :class_type => 'String') + @voicemail_account.voicemail_settings.create(:name => 'notify', :value => 'true', :class_type => 'Boolean') + @voicemail_account.voicemail_settings.create(:name => 'attachment', :value => 'true', :class_type => 'Boolean') + @voicemail_account.voicemail_settings.create(:name => 'mark_read', :value => 'true', :class_type => 'Boolean') + @voicemail_account.voicemail_settings.create(:name => 'purge', :value => 'false', :class_type => 'Boolean') + @voicemail_account.voicemail_settings.create(:name => 'email', :value => @email, :class_type => 'String') + m = method( :"#{@parent.class.name.underscore}_voicemail_accounts_url" ) + redirect_to m.( @parent ), :notice => t('voicemail_accounts.controller.successfuly_created') + else + render :new + end + end + + def edit + @voicemail_account = VoicemailAccount.find(params[:id]) + end + + def update + @voicemail_account = VoicemailAccount.find(params[:id]) + if @voicemail_account.update_attributes(params[:voicemail_account]) + m = method( :"#{@parent.class.name.underscore}_voicemail_accounts_url" ) + redirect_to m.( @parent ), :notice => t('voicemail_accounts.controller.successfuly_updated') + else + render :edit + end + end + + def destroy + @voicemail_account = VoicemailAccount.find(params[:id]) + @voicemail_account.destroy + m = method( :"#{@parent.class.name.underscore}_voicemail_accounts_url" ) + redirect_to m.( @parent ), :notice => t('voicemail_accounts.controller.successfuly_destroyed') + end + + private + def set_and_authorize_parent + @parent = @sip_account || @conference || @hunt_group || @automatic_call_distributor || @user || @tenant + + authorize! :read, @parent + end + + def spread_breadcrumbs + if @parent.class == User + add_breadcrumb t("users.index.page_title"), tenant_users_path(@parent.current_tenant) + add_breadcrumb @parent, tenant_user_path(@parent.current_tenant, @parent) + elsif @parent.class == SipAccount + if @parent.sip_accountable.class == User + add_breadcrumb t("users.index.page_title"), tenant_users_path(@parent.sip_accountable.current_tenant) + add_breadcrumb @parent.sip_accountable, tenant_user_path(@parent.sip_accountable.current_tenant, @parent.sip_accountable) + end + + add_breadcrumb t("sip_accounts.index.page_title"), method( :"#{@parent.sip_accountable.class.name.underscore}_sip_accounts_url" ).(@parent.sip_accountable) + add_breadcrumb @parent, method( :"#{@parent.sip_accountable.class.name.underscore}_sip_account_path" ).(@parent.sip_accountable, @parent) + end + + add_breadcrumb t("voicemail_accounts.index.page_title"), method( :"#{@parent.class.name.underscore}_voicemail_accounts_url" ).(@parent) + + if !@voicemail_account.to_s.blank? + add_breadcrumb @voicemail_account.name + end + end + +end diff --git a/app/controllers/voicemail_messages_controller.rb b/app/controllers/voicemail_messages_controller.rb index dfe0ae4..7511385 100644 --- a/app/controllers/voicemail_messages_controller.rb +++ b/app/controllers/voicemail_messages_controller.rb @@ -1,10 +1,12 @@ class VoicemailMessagesController < ApplicationController - load_resource :sip_account - load_and_authorize_resource :voicemail_message, :through => [:sip_account] + load_resource :voicemail_account + load_and_authorize_resource :voicemail_message, :through => [:voicemail_account] before_filter :set_and_authorize_parent before_filter :spread_breadcrumbs + + helper_method :sort_column, :sort_descending before_filter { |controller| if ! params[:type].blank? then @@ -17,26 +19,28 @@ class VoicemailMessagesController < ApplicationController } def index - @messages_count = @sip_account.voicemail_messages.count - @messages_unread_count = @sip_account.voicemail_messages.where(:read_epoch => 0).count + @messages_count = @voicemail_account.voicemail_messages.count + @messages_unread_count = @voicemail_account.voicemail_messages.where(:read_epoch => 0).count @messages_read_count = @messages_count - @messages_unread_count if @type == 'read' - @voicemail_messages = @sip_account.voicemail_messages.where('read_epoch > 0').order('created_epoch DESC').paginate( + @voicemail_messages = @voicemail_account.voicemail_messages.where('read_epoch > 0').order(sort_column + ' ' + (sort_descending ? 'DESC' : 'ASC')).paginate( :page => @pagination_page_number, :per_page => GsParameter.get('DEFAULT_PAGINATION_ENTRIES_PER_PAGE') ) elsif @type == 'unread' - @voicemail_messages = @sip_account.voicemail_messages.where(:read_epoch => 0).order('created_epoch DESC').paginate( + @voicemail_messages = @voicemail_account.voicemail_messages.where(:read_epoch => 0).order(sort_column + ' ' + (sort_descending ? 'DESC' : 'ASC')).paginate( :page => @pagination_page_number, :per_page => GsParameter.get('DEFAULT_PAGINATION_ENTRIES_PER_PAGE') ) else - @voicemail_messages = @sip_account.voicemail_messages.order('created_epoch DESC').paginate( + @voicemail_messages = @voicemail_account.voicemail_messages.order(sort_column + ' ' + (sort_descending ? 'DESC' : 'ASC')).paginate( :page => @pagination_page_number, :per_page => GsParameter.get('DEFAULT_PAGINATION_ENTRIES_PER_PAGE') ) end + + @available_sip_account = available_sip_account() end def show @@ -78,7 +82,7 @@ class VoicemailMessagesController < ApplicationController def destroy_multiple result = false if ! params[:selected_uuids].blank? then - voicemail_messages = @sip_account.voicemail_messages.where(:uuid => params[:selected_uuids]) + voicemail_messages = @voicemail_account.voicemail_messages.where(:uuid => params[:selected_uuids]) voicemail_messages.each do |voicemail_message| result = voicemail_message.destroy end @@ -92,10 +96,20 @@ class VoicemailMessagesController < ApplicationController end end + def available_sip_account + voicemail_accountable = @voicemail_account.voicemail_accountable + if voicemail_accountable.class == SipAccount + return voicemail_accountable + elsif voicemail_accountable.class == User + return voicemail_accountable.sip_accounts.first + end + end + def call phone_number = @voicemail_message.cid_number - if ! phone_number.blank? && @sip_account.registration - @sip_account.call(phone_number) + sip_account = self.available_sip_account + if ! phone_number.blank? && sip_account && sip_account.registration + sip_account.call(phone_number) end redirect_to(:back) end @@ -112,7 +126,7 @@ class VoicemailMessagesController < ApplicationController private def set_and_authorize_parent - @parent = @sip_account + @parent = @voicemail_account authorize! :read, @parent @@ -123,18 +137,37 @@ class VoicemailMessagesController < ApplicationController end def spread_breadcrumbs - if @parent.class == SipAccount - if @sip_account.sip_accountable.class == User - add_breadcrumb t("#{@sip_account.sip_accountable.class.name.underscore.pluralize}.index.page_title"), method( :"tenant_#{@sip_account.sip_accountable.class.name.underscore.pluralize}_path" ).(@sip_account.tenant) - add_breadcrumb @sip_account.sip_accountable, method( :"tenant_#{@sip_account.sip_accountable.class.name.underscore}_path" ).(@sip_account.tenant, @sip_account.sip_accountable) - end - add_breadcrumb t("sip_accounts.index.page_title"), method( :"#{@sip_account.sip_accountable.class.name.underscore}_sip_accounts_path" ).(@sip_account.sip_accountable) - add_breadcrumb @sip_account, method( :"#{@sip_account.sip_accountable.class.name.underscore}_sip_account_path" ).(@sip_account.sip_accountable, @sip_account) - add_breadcrumb t("voicemail_messages.index.page_title"), sip_account_voicemail_messages_path(@sip_account) - if @voicemail_message && !@voicemail_message.new_record? - add_breadcrumb @voicemail_message, sip_account_voicemail_message_path(@sip_account, @voicemail_message) - end + parent = @voicemail_account.voicemail_accountable + + if parent.class == User + add_breadcrumb t("users.index.page_title"), tenant_users_path(parent.current_tenant) + add_breadcrumb parent, tenant_user_path(parent.current_tenant, parent) + elsif parent.class == SipAccount + if parent.sip_accountable.class == User + add_breadcrumb t("users.index.page_title"), tenant_users_path(parent.sip_accountable.current_tenant) + add_breadcrumb parent.sip_accountable, tenant_user_path(parent.sip_accountable.current_tenant, parent.sip_accountable) + end + + add_breadcrumb t("sip_accounts.index.page_title"), method( :"#{parent.sip_accountable.class.name.underscore}_sip_accounts_url" ).(parent.sip_accountable) + add_breadcrumb parent, method( :"#{parent.sip_accountable.class.name.underscore}_sip_account_path" ).(parent.sip_accountable, parent) end + + add_breadcrumb t("voicemail_accounts.index.page_title"), method( :"#{parent.class.name.underscore}_voicemail_accounts_url" ).(parent) + add_breadcrumb @voicemail_account.name, method( :"#{parent.class.name.underscore}_voicemail_account_path" ).(parent, @voicemail_account) + + add_breadcrumb t("voicemail_messages.index.page_title") + end + + def sort_descending + if sort_column == 'created_epoch' && params[:desc].to_s.blank? + return true + end + + params[:desc].to_s == 'true' + end + + def sort_column + VoicemailMessage.column_names.include?(params[:sort]) ? params[:sort] : 'created_epoch' end end diff --git a/app/controllers/voicemail_settings_controller.rb b/app/controllers/voicemail_settings_controller.rb index 5de0c35..f270c3d 100644 --- a/app/controllers/voicemail_settings_controller.rb +++ b/app/controllers/voicemail_settings_controller.rb @@ -1,92 +1,82 @@ class VoicemailSettingsController < ApplicationController - load_resource :sip_account - load_and_authorize_resource :voicemail_setting, :through => :sip_account, :singleton => true + load_and_authorize_resource :voicemail_account + load_and_authorize_resource :voicemail_setting, :through => [:voicemail_account] - before_filter :set_and_authorize_parent before_filter :spread_breadcrumbs - before_filter :voicemail_defaults, :only => [:index, :show, :new, :create, :edit] def index - render :edit + @voicemail_settings = @voicemail_account.voicemail_settings end def show - render :edit end def new - render :edit + @names_possible = [] + VoicemailSetting::VOICEMAIL_SETTINGS.keys.each do |name| + if @voicemail_account.voicemail_settings.where(:name => name).first + next + end + + label = t("voicemail_settings.settings.#{name}") + if label =~ /^translation missing/ + label = name.to_s.gsub('_', ' ').capitalize; + end + + @names_possible << [label, name] + end end def create - @sip_account = SipAccount.where(:id => params[:sip_account_id]).first - params[:voicemail_setting][:username] = @sip_account.auth_name - params[:voicemail_setting][:domain] = @sip_account.sip_domain.try(:host) - @voicemail_setting = VoicemailSetting.new(params[:voicemail_setting]) + @voicemail_setting = @voicemail_account.voicemail_settings.build(params[:voicemail_setting]) + @voicemail_setting.class_type = VoicemailSetting::VOICEMAIL_SETTINGS[@voicemail_setting.name] if @voicemail_setting.save - redirect_to sip_account_voicemail_settings_path(@sip_account), :notice => t('voicemail_settings.controller.successfuly_created') + m = method( :"#{@voicemail_account.voicemail_accountable.class.name.underscore}_voicemail_account_path" ) + redirect_to m.( @voicemail_account.voicemail_accountable, @voicemail_account ), :notice => t('voicemail_settings.controller.successfuly_created') else - render :action => 'edit' + render :new end end def edit - + @voicemail_setting = @voicemail_account.voicemail_settings.find(params[:id]) + @input_type = VoicemailSetting::VOICEMAIL_SETTINGS.fetch(@voicemail_setting.name,{}).fetch(:input, 'String') + @input_html = VoicemailSetting::VOICEMAIL_SETTINGS.fetch(@voicemail_setting.name,{}).fetch(:html, {}) end def update + @voicemail_setting = @voicemail_account.voicemail_settings.find(params[:id]) if @voicemail_setting.update_attributes(params[:voicemail_setting]) - redirect_to sip_account_voicemail_settings_path(@sip_account), :notice => t('voicemail_settings.controller.successfuly_updated') + m = method( :"#{@voicemail_account.voicemail_accountable.class.name.underscore}_voicemail_account_path" ) + redirect_to m.( @voicemail_account.voicemail_accountable, @voicemail_account ), :notice => t('voicemail_settings.controller.successfuly_updated') else + @input_type = VoicemailSetting::VOICEMAIL_SETTINGS.fetch(@voicemail_setting.name,{}).fetch(:input, 'String') + @input_html = VoicemailSetting::VOICEMAIL_SETTINGS.fetch(@voicemail_setting.name,{}).fetch(:html, {}) render :edit end end def destroy - + @voicemail_setting = @voicemail_account.voicemail_settings.find(params[:id]) + @voicemail_setting.destroy + m = method( :"#{@voicemail_account.voicemail_accountable.class.name.underscore}_voicemail_account_path" ) + redirect_to m.( @voicemail_account.voicemail_accountable, @voicemail_account ), :notice => t('voicemail_settings.controller.successfuly_destroyed') end private - def set_and_authorize_parent - @parent = @sip_account - - authorize! :read, @parent - - @show_path_method = method( :"#{@parent.class.name.underscore}_voicemail_setting_path" ) - @index_path_method = method( :"#{@parent.class.name.underscore}_voicemail_settings_path" ) - @new_path_method = method( :"new_#{@parent.class.name.underscore}_voicemail_setting_path" ) - @edit_path_method = method( :"edit_#{@parent.class.name.underscore}_voicemail_setting_path" ) - end - def spread_breadcrumbs - if @parent.class == SipAccount - if @sip_account.sip_accountable.class == User - add_breadcrumb t("#{@sip_account.sip_accountable.class.name.underscore.pluralize}.index.page_title"), method( :"tenant_#{@sip_account.sip_accountable.class.name.underscore.pluralize}_path" ).(@sip_account.tenant) - add_breadcrumb @sip_account.sip_accountable, method( :"tenant_#{@sip_account.sip_accountable.class.name.underscore}_path" ).(@sip_account.tenant, @sip_account.sip_accountable) - end - add_breadcrumb t("sip_accounts.index.page_title"), method( :"#{@sip_account.sip_accountable.class.name.underscore}_sip_accounts_path" ).(@sip_account.sip_accountable) - add_breadcrumb @sip_account, method( :"#{@sip_account.sip_accountable.class.name.underscore}_sip_account_path" ).(@sip_account.sip_accountable, @sip_account) - add_breadcrumb t("voicemail_settings.index.page_title"), sip_account_voicemail_settings_path(@sip_account) + voicemail_accountable = @voicemail_account.voicemail_accountable + if voicemail_accountable.class == User + add_breadcrumb t("users.index.page_title"), tenant_users_path(voicemail_accountable.current_tenant) + add_breadcrumb voicemail_accountable, tenant_user_path(voicemail_accountable.current_tenant, voicemail_accountable) end - end - - def voicemail_defaults - storage_dir = GsParameter.where(:entity => 'voicemail', :section => 'parameters', :name => 'storage-dir').first.try(:value) - path = "#{storage_dir}/#{@sip_account.sip_domain.host}/#{@sip_account.auth_name}/" - @greeting_files = Dir.glob("#{path}*greeting*.wav").collect {|r| [ File.basename(r), File.expand_path(r) ] } - @name_files = Dir.glob("#{path}*name*.wav").collect {|r| [ File.basename(r), File.expand_path(r) ] } + + add_breadcrumb t("voicemail_accounts.index.page_title"), method( :"#{voicemail_accountable.class.name.underscore}_voicemail_accounts_url" ).(voicemail_accountable) + add_breadcrumb @voicemail_account.name, method( :"#{voicemail_accountable.class.name.underscore}_voicemail_account_path" ).(voicemail_accountable, @voicemail_account) + add_breadcrumb t("voicemail_settings.index.page_title"), voicemail_account_voicemail_settings_url(@voicemail_account) - if @voicemail_setting.blank? then - @voicemail_setting = @sip_account.voicemail_setting - end - - if @voicemail_setting.blank? - @voicemail_setting = VoicemailSetting.new - @voicemail_setting.notify = true - @voicemail_setting.attachment = true - @voicemail_setting.mark_read = true - @voicemail_setting.purge = false + if !@voicemail_setting.to_s.blank? + add_breadcrumb @voicemail_setting end end - end |