Remove orphaned code

* customers#filter_estimates_by_customer and #filter_invoices_by_customer,
  their routes, permission entries and template: they filled an estimate
  dropdown on the old issue form, which is gone.
* Routes with no action: accounts new/create/show/edit/update/destroy
  (only index, Set default and Sync exist) and customers#destroy.
* Unused methods: AuthHelper#require_user, #allowed_to?, #check_permission;
  CustomersController#address_to_s; CustomerToken#expired? and
  .remove_expired_tokens; QboBaseModel#skip_qbo_push?;
  QboDraft.writable_document?; SyncServiceBase#extract_value.
* CustomersController's before_action helpers are private.
* The unused .autocomplete-meta style and 28 unused translation keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-17 19:48:17 -05:00
1 parent 92f9eb1bc7
commit 0d143e6eb1
11 files changed
+38 -161

No files matched your search

+34 -62
View File
@@ -33,36 +33,6 @@ class CustomersController < ApplicationController
before_action :require_admin, only: :sync before_action :require_admin, only: :sync
skip_before_action :verify_authenticity_token, :check_if_login_required, only: [:view] skip_before_action :verify_authenticity_token, :check_if_login_required, only: [:view]
def address_to_s(address)
return if address.nil?
lines = [
address.line1,
address.line2,
address.line3,
address.line4,
address.line5
].compact_blank
city_line = [
address.city,
address.country_sub_division_code,
address.postal_code
].compact_blank.join(" ")
lines << city_line unless city_line.blank?
lines.join("\n")
end
def add_customer
global_check_permission(:add_customers)
end
def allowed_params
params.require(:customer).permit(:name, :email, :primary_phone, :mobile_phone, :phone_number, :notes)
end
# Used for autocomplete forms. Fuzzy matching (nicknames, typos, word order, phone digits) helps # Used for autocomplete forms. Fuzzy matching (nicknames, typos, word order, phone digits) helps
# staff spot an existing customer before creating a duplicate. See CustomerSearchService. # staff spot an existing customer before creating a duplicate. See CustomerSearchService.
def autocomplete def autocomplete
@@ -109,14 +79,6 @@ class CustomersController < ApplicationController
render_404 render_404
end end
def filter_estimates_by_customer
@filtered_estimates = Estimate.all.where(customer_id: params[:selected_customer])
end
def filter_invoices_by_customer
@filtered_invoices = Invoice.all.where(customer_id: params[:selected_customer])
end
# Most matches a search lists (best first) # Most matches a search lists (best first)
SEARCH_LIMIT = 200 SEARCH_LIMIT = 200
@@ -146,29 +108,6 @@ class CustomersController < ApplicationController
@issue_counts = Issue.where(customer_id: @customers.map(&:id)).group(:customer_id).count @issue_counts = Issue.where(customer_id: @customers.map(&:id)).group(:customer_id).count
end end
def load_issue_data
@journals = @issue.journals.preload(:details).preload(user: :email_address).reorder(:created_on, :id).to_a
@journals.each_with_index { |j, i| j.indice = i + 1 }
@journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
Journal.preload_journals_details_custom_fields(@journals)
@journals.select! { |journal| journal.notes? || journal.visible_details.any? }
@journals.reverse! if User.current.wants_comments_in_reverse_order?
@changesets = @issue.changesets.visible.preload(:repository, :user).to_a
@changesets.reverse! if User.current.wants_comments_in_reverse_order?
@relations = @issue.relations.select { |r| r.other_issue(@issue)&.visible? }
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
@priorities = IssuePriority.active
@time_entry = TimeEntry.new(issue: @issue, project: @issue.project)
@relation = IssueRelation.new
end
def log(msg)
Rails.logger.info "[CustomersController] #{msg}"
end
def new def new
@customer = Customer.new @customer = Customer.new
@@ -253,8 +192,41 @@ class CustomersController < ApplicationController
render_403 render_403
end end
private
def add_customer
global_check_permission(:add_customers)
end
def allowed_params
params.require(:customer).permit(:name, :email, :primary_phone, :mobile_phone, :phone_number, :notes)
end
def load_issue_data
@journals = @issue.journals.preload(:details).preload(user: :email_address).reorder(:created_on, :id).to_a
@journals.each_with_index { |j, i| j.indice = i + 1 }
@journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
Journal.preload_journals_details_custom_fields(@journals)
@journals.select! { |journal| journal.notes? || journal.visible_details.any? }
@journals.reverse! if User.current.wants_comments_in_reverse_order?
@changesets = @issue.changesets.visible.preload(:repository, :user).to_a
@changesets.reverse! if User.current.wants_comments_in_reverse_order?
@relations = @issue.relations.select { |r| r.other_issue(@issue)&.visible? }
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
@priorities = IssuePriority.active
@time_entry = TimeEntry.new(issue: @issue, project: @issue.project)
@relation = IssueRelation.new
end
def log(msg)
Rails.logger.info "[CustomersController] #{msg}"
end
def view_customer def view_customer
global_check_permission(:view_customers) global_check_permission(:view_customers)
end end
end end
-22
View File
@@ -31,28 +31,6 @@ module AuthHelper
require_login require_login
end end
# Kept for plugins that still call it (e.g. redmine_qbo_vehicles): requires a logged-in user.
# The old version effectively never ran; share-link customers use require_login_or_customer_token.
def require_user
return true if User.current.logged?
require_login
end
def allowed_to?(action)
return false if User.current.nil?
project = Project.find_by(id: params[:project_id])
return false if project.nil?
User.current.allowed_to?(action, project)
end
def check_permission(permission)
if !allowed_to?(permission)
flash[:error] = t :notice_forbidden
render_403
end
end
def global_check_permission(permission) def global_check_permission(permission)
if !globaly_allowed_to?(permission) if !globaly_allowed_to?(permission)
flash[:error] = t :notice_forbidden flash[:error] = t :notice_forbidden
-10
View File
@@ -21,16 +21,6 @@ class CustomerToken < ApplicationRecord
TOKEN_EXPIRATION = 1.month TOKEN_EXPIRATION = 1.month
# Check if the token has expired
def expired?
expires_at.present? && expires_at <= Time.current
end
# Remove expired tokens from the database
def self.remove_expired_tokens
where("expires_at <= ?", Time.current).delete_all
end
# Get or create a token for the given issue # Get or create a token for the given issue
def self.get_token(issue) def self.get_token(issue)
return unless issue return unless issue
-6
View File
@@ -79,12 +79,6 @@ class QboBaseModel < ActiveRecord::Base
QboSyncJob.perform_later(entity: model_name.name, id: id) QboSyncJob.perform_later(entity: model_name.name, id: id)
end end
# Flag used to update local without pushing to QBO.
# This is used to prevent loops with the webhook
def skip_qbo_push?
!!skip_qbo_push
end
def self.qbo_sync(push: true) def self.qbo_sync(push: true)
self.qbo_push_enabled = push self.qbo_push_enabled = push
end end
-8
View File
@@ -31,14 +31,6 @@ class QboDraft < ApplicationRecord
where(document: documents) where(document: documents)
} }
def self.writable_document?(document, user = User.current)
case document.to_s
when 'estimate' then RedmineQboBilling.writer?(user)
when 'invoice' then RedmineQboBilling.invoice_writer?(user)
else false
end
end
# The editor's fields as posted (estimate[...]) # The editor's fields as posted (estimate[...])
def fields def fields
parsed = JSON.parse(data.presence || '{}') parsed = JSON.parse(data.presence || '{}')
-10
View File
@@ -80,15 +80,6 @@ class SyncServiceBase
false false
end end
def extract_value(remote, remote_attr)
case remote_attr
when Proc
remote_attr.call(remote)
else
remote.public_send(remote_attr)
end
end
# Attribute Mapping DSL # Attribute Mapping DSL
# #
# This DSL defines how attributes from a QuickBooks Online (QBO) entity # This DSL defines how attributes from a QuickBooks Online (QBO) entity
@@ -157,7 +148,6 @@ class SyncServiceBase
end end
end end
def map_attribute(local_attr, remote_attr = nil, &block) def map_attribute(local_attr, remote_attr = nil, &block)
attribute_map[local_attr] = attribute_map[local_attr] =
if block_given? if block_given?
@@ -1 +0,0 @@
$('select#issue_estimate_id').html('<%= j content_tag(:option,'',value:"")+options_from_collection_for_select(@filtered_estimates, :id, :doc_number) %>');
-5
View File
@@ -1,8 +1,3 @@
/* Keep Redmine default look, just enhance metadata */
.ui-autocomplete .autocomplete-meta {
color: #888;
font-size: 0.9em;
}
/* Contextual links on their own line under the page title (customer and vehicle pages), where a long title and /* Contextual links on their own line under the page title (customer and vehicle pages), where a long title and
many links would otherwise crowd each other */ many links would otherwise crowd each other */
#content .contextual.qbo-under-title { #content .contextual.qbo-under-title {
-28
View File
@@ -29,14 +29,11 @@ en:
field_invoice: "Invoice" field_invoice: "Invoice"
field_notes: "Notes" field_notes: "Notes"
label_account_balance: "Account Balance" label_account_balance: "Account Balance"
label_actions: "Actions"
label_amount: "Amount" label_amount: "Amount"
label_appointment: "Add Appointment" label_appointment: "Add Appointment"
label_balance_with_jobs: "Balance With Jobs"
label_bill_time: "Bill Time" label_bill_time: "Bill Time"
label_billing_address: "Billing Address" label_billing_address: "Billing Address"
label_billing_enqueued: "Billing has been enqueued for issue" label_billing_enqueued: "Billing has been enqueued for issue"
label_billed_success: "Successfully billed "
label_client_id: "Intuit QBO OAuth2 Client ID" label_client_id: "Intuit QBO OAuth2 Client ID"
label_client_secret: "Intuit QBO OAuth2 Client Secret" label_client_secret: "Intuit QBO OAuth2 Client Secret"
label_closed_issues: "Closed Issues" label_closed_issues: "Closed Issues"
@@ -45,23 +42,17 @@ en:
label_customer_link_expires: "This customer link expires in" label_customer_link_expires: "This customer link expires in"
label_customer: "Customer" label_customer: "Customer"
label_customers: "Customers" label_customers: "Customers"
label_delete: "Delete"
label_deposit_into: "Deposit to Account"
label_details: "Details" label_details: "Details"
label_display_name: "Display Name" label_display_name: "Display Name"
label_door: "Door" label_door: "Door"
label_edit: "Edit"
label_edit_customer: "Edit Customer" label_edit_customer: "Edit Customer"
label_email: "Email" label_email: "Email"
label_error: "Error" label_error: "Error"
label_estimate_404: "Estimate not found"
label_estimate: "Estimate" label_estimate: "Estimate"
label_estimates: "Estimates" label_estimates: "Estimates"
label_hours: "Hours" label_hours: "Hours"
label_invoice_404: "Invoice not found"
label_invoices: "Invoices" label_invoices: "Invoices"
label_last_sync: "Last Sync" label_last_sync: "Last Sync"
label_load_customer: "Load Customer"
label_make: "Make" label_make: "Make"
label_matching: "Matching" label_matching: "Matching"
label_mobile_phone: "Mobile Phone" label_mobile_phone: "Mobile Phone"
@@ -74,13 +65,9 @@ en:
text_customers_best_match: "%{count} best matches, closest first. Click a column to sort them by it instead." text_customers_best_match: "%{count} best matches, closest first. Click a column to sort them by it instead."
label_no_estimates: "No Estimates" label_no_estimates: "No Estimates"
label_no_invoices: "No Invoices" label_no_invoices: "No Invoices"
label_oauth2_refresh_token_expires_at: "Refresh Token Expires At"
label_oauth_expires: "OAuth2 Access Token Expires At" label_oauth_expires: "OAuth2 Access Token Expires At"
label_oauth_note: "Note: You need to authenticate with QuickBooks after saving your key and secret above."
label_open_issues: "Open Issues" label_open_issues: "Open Issues"
label_primary_phone: "Primary Phone" label_primary_phone: "Primary Phone"
label_qbo_sync_success: "Successfully synced to QuickBooks"
label_redmine_qbo: "Redmine QuickBooks"
label_sandbox: "Sandbox" label_sandbox: "Sandbox"
label_search: "Search" label_search: "Search"
label_search_customers: "Search Customers" label_search_customers: "Search Customers"
@@ -97,23 +84,11 @@ en:
notice_billing_error_no_customer: "Cannot bill without an assigned customer." notice_billing_error_no_customer: "Cannot bill without an assigned customer."
notice_billing_error_no_employee: "Cannot bill without an assigned employee." notice_billing_error_no_employee: "Cannot bill without an assigned employee."
notice_billing_error_no_qbo: "Cannot bill without a QuickBooks connection. Please connect to QuickBooks and try again." notice_billing_error_no_qbo: "Cannot bill without a QuickBooks connection. Please connect to QuickBooks and try again."
notice_customer_created: "Customer created in QuickBooks"
notice_customer_deleted: "Customer deleted in QuickBooks"
notice_customer_not_deleted: "Customer could not be deleted in QuickBooks"
notice_customer_not_found: "Customer not found in QuickBooks"
notice_customer_updated: "Customer updated in QuickBooks" notice_customer_updated: "Customer updated in QuickBooks"
notice_error_issue_not_found: "The issue could not be found. Please check the issue and try again."
notice_error_project_nil: "The issue's project is nil. Set project to:"
notice_error_tracker_nil: "The issue's tracker is nil. Set tracker to:"
notice_estimate_created: "Estimate created in QuickBooks"
notice_estimate_not_found: "Estimate not found, we are syncing with QuickBooks to find it. Please check back shortly." notice_estimate_not_found: "Estimate not found, we are syncing with QuickBooks to find it. Please check back shortly."
notice_estimate_updated: "Estimate updated in QuickBooks"
notice_forbidden: "You do not have permission to access this resource." notice_forbidden: "You do not have permission to access this resource."
notice_invoice_created: "Invoice created in QuickBooks"
notice_invoice_not_found: "Invoice not found" notice_invoice_not_found: "Invoice not found"
notice_invoice_updated: "Invoice updated in QuickBooks"
notice_issue_not_found: "Issue not found" notice_issue_not_found: "Issue not found"
warn_ru_sure: "Are you sure?"
# ---- Billing: estimates, invoices, payments, items and accounts ---- # ---- Billing: estimates, invoices, payments, items and accounts ----
label_billing_settings: "Billing" label_billing_settings: "Billing"
@@ -247,7 +222,6 @@ en:
label_default_account: "Default Item Income Account" label_default_account: "Default Item Income Account"
label_description: "Description" label_description: "Description"
label_edit_item: "Edit Item" label_edit_item: "Edit Item"
label_item: "Item"
label_item_new: "New Item" label_item_new: "New Item"
label_items: "Items" label_items: "Items"
label_management_and_sync: "Synchronization" label_management_and_sync: "Synchronization"
@@ -261,9 +235,7 @@ en:
text_qbo_sync_info: "Sync changes reads what changed in QuickBooks since the last sync; Full sync and each type's Sync re-read every record (e.g. after changing the labor products/services, sync estimates and invoices). Webhooks keep things current in between." text_qbo_sync_info: "Sync changes reads what changed in QuickBooks since the last sync; Full sync and each type's Sync re-read every record (e.g. after changing the labor products/services, sync estimates and invoices). Webhooks keep things current in between."
text_default_account_info: "New products/services go in this income account; set it on the Accounts page." text_default_account_info: "New products/services go in this income account; set it on the Accounts page."
label_never_synced: "Never synced" label_never_synced: "Never synced"
label_no: "No"
label_type: "Type" label_type: "Type"
label_yes: "Yes"
error_default_account_not_selected: "Select an account to make it the default." error_default_account_not_selected: "Select an account to make it the default."
notice_default_account_updated: "Default account updated." notice_default_account_updated: "Default account updated."
+2 -6
View File
@@ -33,11 +33,7 @@ post 'bill/:id', to: 'qbo#bill', as: :bill
get 'customers/view/:token', to: 'customers#view', as: :view get 'customers/view/:token', to: 'customers#view', as: :view
get 'customers/share/:id', to: 'customers#share', as: :share get 'customers/share/:id', to: 'customers#share', as: :share
#java script routes resources :customers, except: [:destroy] do
get 'filter_estimates_by_customer' => 'customers#filter_estimates_by_customer'
get 'filter_invoices_by_customer' => 'customers#filter_invoices_by_customer'
resources :customers do
collection do collection do
get :autocomplete get :autocomplete
get :sync get :sync
@@ -99,7 +95,7 @@ resources :items do
end end
# QuickBooks income accounts # QuickBooks income accounts
resources :accounts do resources :accounts, only: [:index] do
collection do collection do
patch :set_default patch :set_default
get :sync get :sync
+2 -3
View File
@@ -28,9 +28,8 @@ Redmine::Plugin.register :redmine_qbo do
TimeEntry.safe_attributes :billed TimeEntry.safe_attributes :billed
# Global Permissions # Global Permissions
# autocomplete and the filter_* actions feed the customer, estimate and invoice pickers on issue forms # autocomplete feeds the customer pickers (issue forms, estimates, invoices, payments)
permission :view_customers, { customers: [:index, :show, :autocomplete, permission :view_customers, { customers: [:index, :show, :autocomplete] }, global: true
:filter_estimates_by_customer, :filter_invoices_by_customer] }, global: true
permission :add_customers, { customers: [:new, :create] }, global: true permission :add_customers, { customers: [:new, :create] }, global: true
permission :edit_customers, { customers: [:edit, :update] }, global: true permission :edit_customers, { customers: [:edit, :update] }, global: true
permission :share_issues_with_customers, { customers: [:share] }, global: true permission :share_issues_with_customers, { customers: [:share] }, global: true