Updated

app/controllers/admin / signatures_controller.rb

D
143 lines of codes
18 methods
7.9 complexity/method
15 churn
142.25 complexity
165 duplications
class Admin::SignaturesController < Admin::AdminController
  1. Admin::SignaturesController assumes too much for instance variable '@petition'
  2. Admin::SignaturesController assumes too much for instance variable '@signature'
  3. Admin::SignaturesController has no descriptive comment
  4. Admin::SignaturesController has at least 18 methods
include BulkVerification before_action :fetch_petition, if: :petition_scope? before_action :fetch_signature, except: [:index, :bulk_validate, :bulk_invalidate, :bulk_subscribe, :bulk_unsubscribe, :bulk_destroy] before_action :fetch_signatures, only: [:index] helper_method :search_params def index respond_to do |format| format.html end end def bulk_validate begin scope.validate!(selected_ids, force: true) redirect_to index_url(search_params), notice: :signatures_validated
  1. Admin::SignaturesController#bulk_validate calls 'index_url(search_params)' 2 times Locations: 0 1
rescue StandardError => e
  1. Admin::SignaturesController#bulk_validate has the variable name 'e'
Appsignal.send_exception e redirect_to index_url(search_params), alert: :signatures_not_validated
  1. Admin::SignaturesController#bulk_validate calls 'index_url(search_params)' 2 times Locations: 0 1
end end def validate begin @signature.validate!(force: true) redirect_to index_url(search_params), notice: :signature_validated
  1. Admin::SignaturesController#validate calls 'index_url(search_params)' 2 times Locations: 0 1
rescue StandardError => e
  1. Admin::SignaturesController#validate has the variable name 'e'
Appsignal.send_exception e redirect_to index_url(search_params), alert: :signature_not_validated
  1. Admin::SignaturesController#validate calls 'index_url(search_params)' 2 times Locations: 0 1
end end def bulk_invalidate
  1. Similar code found in 4 nodes Locations: 0 1 2 3
begin scope.invalidate!(selected_ids) redirect_to index_url(search_params), notice: :signatures_invalidated
  1. Admin::SignaturesController#bulk_invalidate calls 'index_url(search_params)' 2 times Locations: 0 1
rescue StandardError => e
  1. Admin::SignaturesController#bulk_invalidate has the variable name 'e'
Appsignal.send_exception e redirect_to index_url(search_params), alert: :signatures_not_invalidated
  1. Admin::SignaturesController#bulk_invalidate calls 'index_url(search_params)' 2 times Locations: 0 1
end end def invalidate begin @signature.invalidate! redirect_to index_url(search_params), notice: :signature_invalidated rescue StandardError => e
  1. Admin::SignaturesController#invalidate has the variable name 'e'
Appsignal.send_exception e redirect_to index_url(q: @signature.email), alert: :signature_not_invalidated end end def bulk_destroy
  1. Similar code found in 4 nodes Locations: 0 1 2 3
begin scope.destroy!(selected_ids) redirect_to index_url(search_params), notice: :signatures_deleted
  1. Admin::SignaturesController#bulk_destroy calls 'index_url(search_params)' 2 times Locations: 0 1
rescue StandardError => e
  1. Admin::SignaturesController#bulk_destroy has the variable name 'e'
Appsignal.send_exception e redirect_to index_url(search_params), alert: :signatures_not_deleted
  1. Admin::SignaturesController#bulk_destroy calls 'index_url(search_params)' 2 times Locations: 0 1
end end def destroy
  1. Similar code found in 2 nodes Locations: 0 1
if @signature.destroy redirect_to index_url(search_params), notice: :signature_deleted
  1. Admin::SignaturesController#destroy calls 'index_url(search_params)' 2 times Locations: 0 1
else redirect_to index_url(search_params), alert: :signature_not_deleted
  1. Admin::SignaturesController#destroy calls 'index_url(search_params)' 2 times Locations: 0 1
end end def bulk_subscribe
  1. Similar code found in 4 nodes Locations: 0 1 2 3
begin scope.subscribe!(selected_ids) redirect_to index_url(search_params), notice: :signatures_subscribed
  1. Admin::SignaturesController#bulk_subscribe calls 'index_url(search_params)' 2 times Locations: 0 1
rescue StandardError => e
  1. Admin::SignaturesController#bulk_subscribe has the variable name 'e'
Appsignal.send_exception e redirect_to index_url(search_params), alert: :signatures_not_subscribed
  1. Admin::SignaturesController#bulk_subscribe calls 'index_url(search_params)' 2 times Locations: 0 1
end end def subscribe
  1. Similar code found in 2 nodes Locations: 0 1
if @signature.update(notify_by_email: true) redirect_to admin_signatures_url(search_params), notice: :signature_subscribed
  1. Admin::SignaturesController#subscribe calls 'admin_signatures_url(search_params)' 2 times Locations: 0 1
else redirect_to admin_signatures_url(search_params), alert: :signature_not_subscribed
  1. Admin::SignaturesController#subscribe calls 'admin_signatures_url(search_params)' 2 times Locations: 0 1
end end def bulk_unsubscribe
  1. Similar code found in 4 nodes Locations: 0 1 2 3
begin scope.unsubscribe!(selected_ids) redirect_to index_url(search_params), notice: :signatures_unsubscribed
  1. Admin::SignaturesController#bulk_unsubscribe calls 'index_url(search_params)' 2 times Locations: 0 1
rescue StandardError => e
  1. Admin::SignaturesController#bulk_unsubscribe has the variable name 'e'
Appsignal.send_exception e redirect_to index_url(search_params), alert: :signatures_not_unsubscribed
  1. Admin::SignaturesController#bulk_unsubscribe calls 'index_url(search_params)' 2 times Locations: 0 1
end end def unsubscribe
  1. Similar code found in 2 nodes Locations: 0 1
if @signature.update(notify_by_email: false) redirect_to index_url(search_params), notice: :signature_unsubscribed
  1. Admin::SignaturesController#unsubscribe calls 'index_url(search_params)' 2 times Locations: 0 1
else redirect_to index_url(search_params), alert: :signature_not_unsubscribed
  1. Admin::SignaturesController#unsubscribe calls 'index_url(search_params)' 2 times Locations: 0 1
end end private def petition_scope? params.key?(:petition_id) end def fetch_petition @petition = Petition.find(params[:petition_id]) end def scope params.key?(:petition_id) ? @petition.signatures : Signature end def fetch_signatures @signatures = scope.search(params[:q], search_params) end def fetch_signature @signature = scope.find(params[:id]) end def search_params params.slice(:q, :page, :state, :window) end def index_url(*args) if petition_scope? admin_petition_signatures_url(*args) else admin_signatures_url(*args) end end end