From 0d143e6eb15662368d10dadb1ed4130b74f6bfe2 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Tue, 17 Nov 2026 19:48:17 -0500 Subject: [PATCH] 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 --- app/controllers/customers_controller.rb | 96 +++++++------------ app/helpers/auth_helper.rb | 22 ----- app/models/customer_token.rb | 10 -- app/models/qbo_base_model.rb | 6 -- app/models/qbo_draft.rb | 8 -- app/services/sync_service_base.rb | 10 -- .../filter_estimates_by_customer.js.erb | 1 - assets/stylesheets/autocomplete.css | 5 - config/locales/en.yml | 28 ------ config/routes.rb | 8 +- init.rb | 5 +- 11 files changed, 38 insertions(+), 161 deletions(-) delete mode 100644 app/views/customers/filter_estimates_by_customer.js.erb diff --git a/app/controllers/customers_controller.rb b/app/controllers/customers_controller.rb index 1393ccf..0c9fe6b 100644 --- a/app/controllers/customers_controller.rb +++ b/app/controllers/customers_controller.rb @@ -33,36 +33,6 @@ class CustomersController < ApplicationController before_action :require_admin, only: :sync 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 # staff spot an existing customer before creating a duplicate. See CustomerSearchService. def autocomplete @@ -109,14 +79,6 @@ class CustomersController < ApplicationController render_404 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) SEARCH_LIMIT = 200 @@ -146,29 +108,6 @@ class CustomersController < ApplicationController @issue_counts = Issue.where(customer_id: @customers.map(&:id)).group(:customer_id).count 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 @customer = Customer.new @@ -253,8 +192,41 @@ class CustomersController < ApplicationController render_403 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 global_check_permission(:view_customers) end -end \ No newline at end of file +end diff --git a/app/helpers/auth_helper.rb b/app/helpers/auth_helper.rb index 2f0f5b5..4fedd7f 100644 --- a/app/helpers/auth_helper.rb +++ b/app/helpers/auth_helper.rb @@ -31,28 +31,6 @@ module AuthHelper require_login 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) if !globaly_allowed_to?(permission) flash[:error] = t :notice_forbidden diff --git a/app/models/customer_token.rb b/app/models/customer_token.rb index a9f4db3..74ce46a 100644 --- a/app/models/customer_token.rb +++ b/app/models/customer_token.rb @@ -21,16 +21,6 @@ class CustomerToken < ApplicationRecord 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 def self.get_token(issue) return unless issue diff --git a/app/models/qbo_base_model.rb b/app/models/qbo_base_model.rb index 931f0c2..2e47804 100644 --- a/app/models/qbo_base_model.rb +++ b/app/models/qbo_base_model.rb @@ -79,12 +79,6 @@ class QboBaseModel < ActiveRecord::Base QboSyncJob.perform_later(entity: model_name.name, id: id) 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) self.qbo_push_enabled = push end diff --git a/app/models/qbo_draft.rb b/app/models/qbo_draft.rb index 7c7de38..953c744 100644 --- a/app/models/qbo_draft.rb +++ b/app/models/qbo_draft.rb @@ -31,14 +31,6 @@ class QboDraft < ApplicationRecord 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[...]) def fields parsed = JSON.parse(data.presence || '{}') diff --git a/app/services/sync_service_base.rb b/app/services/sync_service_base.rb index f591326..7d40851 100644 --- a/app/services/sync_service_base.rb +++ b/app/services/sync_service_base.rb @@ -80,15 +80,6 @@ class SyncServiceBase false 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 # # This DSL defines how attributes from a QuickBooks Online (QBO) entity @@ -157,7 +148,6 @@ class SyncServiceBase end end - def map_attribute(local_attr, remote_attr = nil, &block) attribute_map[local_attr] = if block_given? diff --git a/app/views/customers/filter_estimates_by_customer.js.erb b/app/views/customers/filter_estimates_by_customer.js.erb deleted file mode 100644 index f6d25b8..0000000 --- a/app/views/customers/filter_estimates_by_customer.js.erb +++ /dev/null @@ -1 +0,0 @@ -$('select#issue_estimate_id').html('<%= j content_tag(:option,'',value:"")+options_from_collection_for_select(@filtered_estimates, :id, :doc_number) %>'); diff --git a/assets/stylesheets/autocomplete.css b/assets/stylesheets/autocomplete.css index 4f4fec1..cc4e745 100644 --- a/assets/stylesheets/autocomplete.css +++ b/assets/stylesheets/autocomplete.css @@ -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 many links would otherwise crowd each other */ #content .contextual.qbo-under-title { diff --git a/config/locales/en.yml b/config/locales/en.yml index 36dddf4..acfb774 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -29,14 +29,11 @@ en: field_invoice: "Invoice" field_notes: "Notes" label_account_balance: "Account Balance" - label_actions: "Actions" label_amount: "Amount" label_appointment: "Add Appointment" - label_balance_with_jobs: "Balance With Jobs" label_bill_time: "Bill Time" label_billing_address: "Billing Address" label_billing_enqueued: "Billing has been enqueued for issue" - label_billed_success: "Successfully billed " label_client_id: "Intuit QBO OAuth2 Client ID" label_client_secret: "Intuit QBO OAuth2 Client Secret" label_closed_issues: "Closed Issues" @@ -45,23 +42,17 @@ en: label_customer_link_expires: "This customer link expires in" label_customer: "Customer" label_customers: "Customers" - label_delete: "Delete" - label_deposit_into: "Deposit to Account" label_details: "Details" label_display_name: "Display Name" label_door: "Door" - label_edit: "Edit" label_edit_customer: "Edit Customer" label_email: "Email" label_error: "Error" - label_estimate_404: "Estimate not found" label_estimate: "Estimate" label_estimates: "Estimates" label_hours: "Hours" - label_invoice_404: "Invoice not found" label_invoices: "Invoices" label_last_sync: "Last Sync" - label_load_customer: "Load Customer" label_make: "Make" label_matching: "Matching" 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." label_no_estimates: "No Estimates" 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_note: "Note: You need to authenticate with QuickBooks after saving your key and secret above." label_open_issues: "Open Issues" label_primary_phone: "Primary Phone" - label_qbo_sync_success: "Successfully synced to QuickBooks" - label_redmine_qbo: "Redmine QuickBooks" label_sandbox: "Sandbox" label_search: "Search" 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_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_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_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_updated: "Estimate updated in QuickBooks" 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_updated: "Invoice updated in QuickBooks" notice_issue_not_found: "Issue not found" - warn_ru_sure: "Are you sure?" # ---- Billing: estimates, invoices, payments, items and accounts ---- label_billing_settings: "Billing" @@ -247,7 +222,6 @@ en: label_default_account: "Default Item Income Account" label_description: "Description" label_edit_item: "Edit Item" - label_item: "Item" label_item_new: "New Item" label_items: "Items" 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_default_account_info: "New products/services go in this income account; set it on the Accounts page." label_never_synced: "Never synced" - label_no: "No" label_type: "Type" - label_yes: "Yes" error_default_account_not_selected: "Select an account to make it the default." notice_default_account_updated: "Default account updated." diff --git a/config/routes.rb b/config/routes.rb index 8659294..0b81cdb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -33,11 +33,7 @@ post 'bill/:id', to: 'qbo#bill', as: :bill get 'customers/view/:token', to: 'customers#view', as: :view get 'customers/share/:id', to: 'customers#share', as: :share -#java script routes -get 'filter_estimates_by_customer' => 'customers#filter_estimates_by_customer' -get 'filter_invoices_by_customer' => 'customers#filter_invoices_by_customer' - -resources :customers do +resources :customers, except: [:destroy] do collection do get :autocomplete get :sync @@ -99,7 +95,7 @@ resources :items do end # QuickBooks income accounts -resources :accounts do +resources :accounts, only: [:index] do collection do patch :set_default get :sync diff --git a/init.rb b/init.rb index 6725697..926bf82 100644 --- a/init.rb +++ b/init.rb @@ -28,9 +28,8 @@ Redmine::Plugin.register :redmine_qbo do TimeEntry.safe_attributes :billed # Global Permissions - # autocomplete and the filter_* actions feed the customer, estimate and invoice pickers on issue forms - permission :view_customers, { customers: [:index, :show, :autocomplete, - :filter_estimates_by_customer, :filter_invoices_by_customer] }, global: true + # autocomplete feeds the customer pickers (issue forms, estimates, invoices, payments) + permission :view_customers, { customers: [:index, :show, :autocomplete] }, global: true permission :add_customers, { customers: [:new, :create] }, global: true permission :edit_customers, { customers: [:edit, :update] }, global: true permission :share_issues_with_customers, { customers: [:share] }, global: true