| WIP: Fixing bug with viewing calls from a scan - warvox - VoIP based wardialing… | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| commit ea169591d3a6898656c184c761dcc5a5ee9ba1a0 | |
| parent 9bec858678949e4169f78911c1062767d4cdcd7d | |
| Author: Jay Scott <[email protected]> | |
| Date: Fri, 26 Aug 2016 10:15:45 +0000 | |
| WIP: Fixing bug with viewing calls from a scan | |
| Scans -> View Call Connections (the eye icon) | |
| PG::SyntaxError: ERROR: syntax error at or near "{" LINE 1: | |
| SELECT COUNT({:conditions=>{:answered=>false}}) FROM "calls" | |
| ... ^ : SELECT COUNT({:conditions=>{:answered=>false}}) FROM | |
| "calls" WHERE "calls"."job_id" = $1 | |
| line 37: app/controllers/jobs_controller.rb | |
| @call_results = { | |
| Timeout: @job.calls.count(conditions: { answered: false }), | |
| Busy: @job.calls.count(conditions: { busy: true }), | |
| Answered: @job.calls.count(conditions: { answered: true }) | |
| } | |
| Diffstat: | |
| M README.md | 20 +------------------- | |
| M app/controllers/calls_controller.rb | 70 +++++++++++++++--------------… | |
| M app/controllers/jobs_controller.rb | 222 ++++++++++++++---------------… | |
| 3 files changed, 138 insertions(+), 174 deletions(-) | |
| --- | |
| diff --git a/README.md b/README.md | |
| @@ -7,13 +7,11 @@ The latest version of this software is available from http://… | |
| Questions and suggestions can be sent to: | |
| x(at)hdm(dot)io | |
| -#table of contents | |
| - [Installing](#installing) | |
| - - [Development](#development) | |
| ##installing | |
| -WarVOX requires a Linux operating system, preferably Ubuntu or Debian, but Kal… | |
| +WarVOX requires a Linux operating system, preferably Ubuntu or Debian. | |
| WarVOX requires PostgreSQL 9.1 or newer with the "contrib" package installed f… | |
| @@ -88,19 +86,3 @@ Access the web interface at http://127.0.0.1:7777/ | |
| At this point you can configure a new IAX2 provider, create a project, and sta… | |
| -##development | |
| - | |
| -Using the Dockerfile | |
| - | |
| -Run a postgres container | |
| - | |
| - docker pull postgres | |
| - docker run -d --name=postgres postgres | |
| - | |
| -Build the image | |
| - | |
| - docker build -t warvox/test . | |
| - | |
| -Run the image | |
| - | |
| - docker run -p 7777:7777 -ti --link postgres:db warvox/test | |
| diff --git a/app/controllers/calls_controller.rb b/app/controllers/calls_contro… | |
| @@ -1,40 +1,40 @@ | |
| class CallsController < ApplicationController | |
| - | |
| # GET /calls | |
| # GET /calls.xml | |
| def index | |
| @jobs = @project.jobs.order('id DESC').where('task = ? AND completed_at IS… | |
| - :page => params[:page], | |
| - :per_page => 30 | |
| - ) | |
| + page: params[:page], | |
| + per_page: 30 | |
| + ) | |
| respond_to do |format| | |
| format.html # index.html.erb | |
| - format.xml { render :xml => @calls } | |
| + format.xml { render xml: @calls } | |
| end | |
| end | |
| # GET /calls/1/view | |
| # GET /calls/1/view.xml | |
| def view | |
| - @calls = Call.order('id DESC').where(:job_id => params[:id]).paginate( | |
| - :page => params[:page], | |
| - :per_page => 30 | |
| - ) | |
| - | |
| - unless @calls and @calls.length > 0 | |
| - redirect_to :action => :index | |
| - return | |
| - end | |
| - @call_results = { | |
| - :Timeout => Call.count(:conditions =>['job_id = ? and answered = ?', para… | |
| - :Busy => Call.count(:conditions =>['job_id = ? and busy = ?', params[:… | |
| - :Answered => Call.count(:conditions =>['job_id = ? and answered = ?', para… | |
| - } | |
| + @calls = Call.order('id DESC').where(job_id: params[:id]).paginate( | |
| + page: params[:page], | |
| + per_page: 30 | |
| + ) | |
| + | |
| + unless @calls && [email protected]? | |
| + redirect_to action: :index | |
| + return | |
| + end | |
| - respond_to do |format| | |
| + @call_results = { | |
| + Timeout: Call.count(conditions: ['job_id = ? and answered = ?', params[:… | |
| + Busy: Call.count(conditions: ['job_id = ? and busy = ?', params[:id], tr… | |
| + Answered: Call.count(conditions: ['job_id = ? and answered = ?', params[… | |
| + } | |
| + | |
| + respond_to do |format| | |
| format.html # index.html.erb | |
| - format.xml { render :xml => @calls } | |
| + format.xml { render xml: @calls } | |
| end | |
| end | |
| @@ -43,14 +43,14 @@ class CallsController < ApplicationController | |
| def show | |
| @call = Call.find(params[:id]) | |
| - unless @call | |
| - redirect_to :action => :index | |
| - return | |
| - end | |
| + unless @call | |
| + redirect_to action: :index | |
| + return | |
| + end | |
| respond_to do |format| | |
| format.html # show.html.erb | |
| - format.xml { render :xml => @call } | |
| + format.xml { render xml: @call } | |
| end | |
| end | |
| @@ -61,7 +61,7 @@ class CallsController < ApplicationController | |
| respond_to do |format| | |
| format.html # new.html.erb | |
| - format.xml { render :xml => @call } | |
| + format.xml { render xml: @call } | |
| end | |
| end | |
| @@ -79,10 +79,10 @@ class CallsController < ApplicationController | |
| if @call.save | |
| flash[:notice] = 'Call was successfully created.' | |
| format.html { redirect_to(@call) } | |
| - format.xml { render :xml => @call, :status => :created, :location => … | |
| + format.xml { render xml: @call, status: :created, location: @call } | |
| else | |
| - format.html { render :action => "new" } | |
| - format.xml { render :xml => @call.errors, :status => :unprocessable_e… | |
| + format.html { render action: 'new' } | |
| + format.xml { render xml: @call.errors, status: :unprocessable_entity } | |
| end | |
| end | |
| end | |
| @@ -98,8 +98,8 @@ class CallsController < ApplicationController | |
| format.html { redirect_to(@call) } | |
| format.xml { head :ok } | |
| else | |
| - format.html { render :action => "edit" } | |
| - format.xml { render :xml => @call.errors, :status => :unprocessable_e… | |
| + format.html { render action: 'edit' } | |
| + format.xml { render xml: @call.errors, status: :unprocessable_entity } | |
| end | |
| end | |
| end | |
| @@ -107,14 +107,12 @@ class CallsController < ApplicationController | |
| # DELETE /calls/1 | |
| # DELETE /calls/1.xml | |
| def destroy | |
| - | |
| @job = Job.find(params[:id]) | |
| - @job.destroy | |
| + @job.destroy | |
| respond_to do |format| | |
| - format.html { redirect_to :action => 'index' } | |
| + format.html { redirect_to action: 'index' } | |
| format.xml { head :ok } | |
| end | |
| end | |
| - | |
| end | |
| diff --git a/app/controllers/jobs_controller.rb b/app/controllers/jobs_controll… | |
| @@ -1,24 +1,19 @@ | |
| class JobsController < ApplicationController | |
| - | |
| require 'shellwords' | |
| def index | |
| - @reload_interval = 20000 | |
| + @reload_interval = 20_000 | |
| - @submitted_jobs = Job.where(:status => ['submitted', 'scheduled'], :comple… | |
| - @active_jobs = Job.where(:status => 'running', :completed_at => nil) | |
| - @inactive_jobs = Job.order('id DESC').where('status NOT IN (?)', ['submit… | |
| - :page => params[:page], | |
| - :per_page => 30 | |
| + @submitted_jobs = Job.where(status: %w(submitted scheduled), completed_at:… | |
| + @active_jobs = Job.where(status: 'running', completed_at: nil) | |
| + @inactive_jobs = Job.order('id DESC').where('status NOT IN (?)', %w(submi… | |
| + page: params[:page], | |
| + per_page: 30 | |
| ) | |
| - if @active_jobs.length > 0 | |
| - @reload_interval = 5000 | |
| - end | |
| + @reload_interval = 5000 unless @active_jobs.empty? | |
| - if @submitted_jobs.length > 0 | |
| - @reload_interval = 3000 | |
| - end | |
| + @reload_interval = 3000 unless @submitted_jobs.empty? | |
| respond_to do |format| | |
| format.html | |
| @@ -27,8 +22,8 @@ class JobsController < ApplicationController | |
| def results | |
| @jobs = @project.jobs.order('id DESC').where('(task = ? OR task = ?) AND c… | |
| - :page => params[:page], | |
| - :per_page => 30 | |
| + page: params[:page], | |
| + per_page: 30 | |
| ) | |
| respond_to do |format| | |
| @@ -40,16 +35,17 @@ class JobsController < ApplicationController | |
| @job = Job.find(params[:id]) | |
| @call_results = { | |
| - :Timeout => @job.calls.count(:conditions => { :answered => false }), | |
| - :Busy => @job.calls.count(:conditions => { :busy => true }), | |
| - :Answered => @job.calls.count(:conditions => { :answered => true }), | |
| + Timeout: @job.calls.count(conditions: { answered: false }), | |
| + Busy: @job.calls.count(conditions: { busy: true }), | |
| + Answered: @job.calls.count(conditions: { answered: true }) | |
| } | |
| - sort_by = params[:sort_by] || 'number' | |
| + | |
| + sort_by = params[:sort_by] || 'number' | |
| sort_dir = params[:sort_dir] || 'asc' | |
| @results = [] | |
| - @results_total_count = @job.calls.count() | |
| + @results_total_count = @job.calls.count | |
| if request.format.json? | |
| if params[:iDisplayLength] == '-1' | |
| @@ -61,14 +57,14 @@ class JobsController < ApplicationController | |
| calls_search | |
| @results = @job.calls.includes(:provider).where(@search_conditions).limi… | |
| - @results_total_display_count = @job.calls.includes(:provider).where(@sea… | |
| + @results_total_display_count = @job.calls.includes(:provider).where(@sea… | |
| end | |
| respond_to do |format| | |
| format.html | |
| - format.json { | |
| - render :content_type => 'application/json', :json => render_to_string(… | |
| - } | |
| + format.json do | |
| + render content_type: 'application/json', json: render_to_string(partia… | |
| + end | |
| end | |
| end | |
| @@ -77,20 +73,20 @@ class JobsController < ApplicationController | |
| # Returns the SQL String. | |
| def calls_sort_option | |
| column = case params[:iSortCol_0].to_s | |
| - when '1' | |
| - 'number' | |
| - when '2' | |
| - 'caller_id' | |
| - when '3' | |
| - 'providers.name' | |
| - when '4' | |
| - 'answered' | |
| - when '5' | |
| - 'busy' | |
| - when '6' | |
| - 'audio_length' | |
| - when '7' | |
| - 'ring_length' | |
| + when '1' | |
| + 'number' | |
| + when '2' | |
| + 'caller_id' | |
| + when '3' | |
| + 'providers.name' | |
| + when '4' | |
| + 'answered' | |
| + when '5' | |
| + 'busy' | |
| + when '6' | |
| + 'audio_length' | |
| + when '7' | |
| + 'ring_length' | |
| end | |
| column + ' ' + (params[:sSortDir_0] =~ /^A/i ? 'asc' : 'desc') if column | |
| end | |
| @@ -98,41 +94,45 @@ class JobsController < ApplicationController | |
| def calls_search | |
| @search_conditions = [] | |
| terms = params[:sSearch].to_s | |
| - terms = Shellword.shellwords(terms) rescue terms.split(/\s+/) | |
| - where = "" | |
| + terms = begin | |
| + Shellword.shellwords(terms) | |
| + rescue | |
| + terms.split(/\s+/) | |
| + end | |
| + where = '' | |
| param = [] | |
| - glue = "" | |
| + glue = '' | |
| terms.each do |w| | |
| - next if w.downcase == 'undefined' | |
| + next if w.casecmp('undefined').zero? | |
| where << glue | |
| case w | |
| - when 'answered' | |
| - where << "answered = ? " | |
| - param << true | |
| - when 'busy' | |
| - where << "busy = ? " | |
| - param << true | |
| - else | |
| - where << "( number ILIKE ? OR caller_id ILIKE ? ) " | |
| - param << "%#{w}%" | |
| - param << "%#{w}%" | |
| + when 'answered' | |
| + where << 'answered = ? ' | |
| + param << true | |
| + when 'busy' | |
| + where << 'busy = ? ' | |
| + param << true | |
| + else | |
| + where << '( number ILIKE ? OR caller_id ILIKE ? ) ' | |
| + param << "%#{w}%" | |
| + param << "%#{w}%" | |
| end | |
| - glue = "AND " if glue.empty? | |
| - @search_conditions = [ where, *param ] | |
| + glue = 'AND ' if glue.empty? | |
| + @search_conditions = [where, *param] | |
| end | |
| end | |
| def new_dialer | |
| @job = Job.new | |
| - if @project | |
| - @job.project = @project | |
| - else | |
| - @job.project = Project.last | |
| - end | |
| + @job.project = if @project | |
| + @project | |
| + else | |
| + Project.last | |
| + end | |
| if params[:result_ids] | |
| - nums = "" | |
| - Call.find_each(:conditions => { :id => params[:result_ids] }) do |call| | |
| + nums = '' | |
| + Call.find_each(conditions: { id: params[:result_ids] }) do |call| | |
| nums << call.number + "\n" | |
| end | |
| @job.range = nums | |
| @@ -140,12 +140,12 @@ class JobsController < ApplicationController | |
| respond_to do |format| | |
| format.html | |
| - end | |
| + end | |
| end | |
| def purge_calls | |
| - Call.delete_all(:id => params[:result_ids]) | |
| - CallMedium.delete_all(:call_id => params[:result_ids]) | |
| + Call.delete_all(id: params[:result_ids]) | |
| + CallMedium.delete_all(call_id: params[:result_ids]) | |
| flash[:notice] = "Purged #{params[:result_ids].length} calls" | |
| if params[:id] | |
| @job = Job.find(params[:id]) | |
| @@ -160,33 +160,33 @@ class JobsController < ApplicationController | |
| @job.created_by = @current_user.login | |
| @job.task = 'dialer' | |
| @job.range.to_s.gsub!(/[^0-9X:,\n]/, '') | |
| - @job.cid_mask.to_s.gsub!(/[^0-9X]/, '') if @job.cid_mask != "SELF" | |
| + @job.cid_mask.to_s.gsub!(/[^0-9X]/, '') if @job.cid_mask != 'SELF' | |
| - if @job.range_file.to_s != "" | |
| + if @job.range_file.to_s != '' | |
| @job.range = @job.range_file.read.gsub(/[^0-9X:,\n]/, '') | |
| end | |
| respond_to do |format| | |
| if @job.schedule | |
| flash[:notice] = 'Job was successfully created.' | |
| - format.html { redirect_to :action => :index } | |
| + format.html { redirect_to action: :index } | |
| else | |
| - format.html { render :action => "new_dialer" } | |
| + format.html { render action: 'new_dialer' } | |
| end | |
| end | |
| end | |
| def new_analyze | |
| @job = Job.new | |
| - if @project | |
| - @job.project = @project | |
| - else | |
| - @job.project = Project.last | |
| - end | |
| + @job.project = if @project | |
| + @project | |
| + else | |
| + Project.last | |
| + end | |
| if params[:result_ids] | |
| - nums = "" | |
| - Call.find_each(:conditions => { :id => params[:result_ids] }) do |call| | |
| + nums = '' | |
| + Call.find_each(conditions: { id: params[:result_ids] }) do |call| | |
| nums << call.number + "\n" | |
| end | |
| @job.range = nums | |
| @@ -194,20 +194,20 @@ class JobsController < ApplicationController | |
| respond_to do |format| | |
| format.html | |
| - end | |
| + end | |
| end | |
| def new_identify | |
| @job = Job.new | |
| - if @project | |
| - @job.project = @project | |
| - else | |
| - @job.project = Project.last | |
| - end | |
| + @job.project = if @project | |
| + @project | |
| + else | |
| + Project.last | |
| + end | |
| if params[:result_ids] | |
| - nums = "" | |
| - Call.find_each(:conditions => { :id => params[:result_ids] }) do |call| | |
| + nums = '' | |
| + Call.find_each(conditions: { id: params[:result_ids] }) do |call| | |
| nums << call.number + "\n" | |
| end | |
| @job.range = nums | |
| @@ -215,15 +215,13 @@ class JobsController < ApplicationController | |
| respond_to do |format| | |
| format.html | |
| - end | |
| + end | |
| end | |
| def reanalyze_job | |
| @job = Job.find(params[:id]) | |
| - @new = Job.new({ | |
| - :task => 'analysis', :scope => 'job', :target_id => @job.id, :force => t… | |
| - :project_id => @project.id, :status => 'submitted' | |
| - }) | |
| + @new = Job.new(task: 'analysis', scope: 'job', target_id: @job.id, force: … | |
| + project_id: @project.id, status: 'submitted') | |
| @new.created_by = @current_user.login | |
| respond_to do |format| | |
| if @new.schedule | |
| @@ -241,16 +239,12 @@ class JobsController < ApplicationController | |
| # Handle analysis of specific call IDs via checkbox submission | |
| if params[:result_ids] | |
| - @new = Job.new({ | |
| - :task => 'analysis', :scope => 'calls', :target_ids => params[:result_… | |
| - :project_id => @project.id, :status => 'submitted' | |
| - }) | |
| + @new = Job.new(task: 'analysis', scope: 'calls', target_ids: params[:res… | |
| + project_id: @project.id, status: 'submitted') | |
| else | |
| - # Otherwise analyze the entire Job | |
| - @new = Job.new({ | |
| - :task => 'analysis', :scope => 'job', :target_id => @job.id, | |
| - :project_id => @project.id, :status => 'submitted' | |
| - }) | |
| + # Otherwise analyze the entire Job | |
| + @new = Job.new(task: 'analysis', scope: 'job', target_id: @job.id, | |
| + project_id: @project.id, status: 'submitted') | |
| end | |
| @new.created_by = @current_user.login | |
| @@ -266,21 +260,15 @@ class JobsController < ApplicationController | |
| end | |
| end | |
| - | |
| def analyze_project | |
| - | |
| # Handle analysis of specific call IDs via checkbox submission | |
| if params[:result_ids] | |
| - @new = Job.new({ | |
| - :task => 'analysis', :scope => 'calls', :target_ids => params[:result_… | |
| - :project_id => @project.id, :status => 'submitted' | |
| - }) | |
| + @new = Job.new(task: 'analysis', scope: 'calls', target_ids: params[:res… | |
| + project_id: @project.id, status: 'submitted') | |
| else | |
| - # Otherwise analyze the entire Project | |
| - @new = Job.new({ | |
| - :task => 'analysis', :scope => 'project', :target_id => @project.id, | |
| - :project_id => @project.id, :status => 'submitted' | |
| - }) | |
| + # Otherwise analyze the entire Project | |
| + @new = Job.new(task: 'analysis', scope: 'project', target_id: @project.i… | |
| + project_id: @project.id, status: 'submitted') | |
| end | |
| @new.created_by = @current_user.login | |
| @@ -301,16 +289,12 @@ class JobsController < ApplicationController | |
| # Handle identification of specific lines via checkbox submission | |
| if params[:result_ids] | |
| - @new = Job.new({ | |
| - :task => 'identify', :scope => 'calls', :target_ids => params[:result_… | |
| - :project_id => @project.id, :status => 'submitted' | |
| - }) | |
| + @new = Job.new(task: 'identify', scope: 'calls', target_ids: params[:res… | |
| + project_id: @project.id, status: 'submitted') | |
| else | |
| - # Otherwise analyze the entire Job | |
| - @new = Job.new({ | |
| - :task => 'identify', :scope => 'job', :target_id => @job.id, | |
| - :project_id => @project.id, :status => 'submitted' | |
| - }) | |
| + # Otherwise analyze the entire Job | |
| + @new = Job.new(task: 'identify', scope: 'job', target_id: @job.id, | |
| + project_id: @project.id, status: 'submitted') | |
| end | |
| @new.created_by = @current_user.login | |
| @@ -329,8 +313,8 @@ class JobsController < ApplicationController | |
| def stop | |
| @job = Job.find(params[:id]) | |
| @job.stop | |
| - flash[:notice] = "Job has been cancelled" | |
| - redirect_to :action => 'index' | |
| + flash[:notice] = 'Job has been cancelled' | |
| + redirect_to action: 'index' | |
| end | |
| def destroy |