Security, permission and search fixes

Security
- Connecting to QuickBooks (authenticate/oauth_callback) and all syncs
  are admin-only; the OAuth state is stored and verified on callback
- New "Bill issue time to QuickBooks" project permission; billing is now
  a POST and checks the permission and issue visibility
- Estimate/invoice PDFs require a logged-in user, or a customer share
  link limited to the estimate and invoices attached to that issue
  (the old require_user check never ran)
- Attachments patch keeps the share token per request instead of in
  Thread.current, so it can't leak into other requests

Permissions and share links
- customers#autocomplete and the filter_* actions are part of View
  customers, so non-admins can pick customers on forms
- customers#view no longer goes through authorize_global; share needs
  the new "Share issues with customers" permission and a visible issue
- Removed a check in customers#view that compared a value to itself

Bugs
- Subjects and customer names capitalize each word without lowercasing
  the rest (LED, JL, 4x4 stay as typed); subjects only when changed
- Settings page shows Invoice/Estimate sync times (Item/Account models
  no longer exist)
- customers#update shows validation errors instead of reporting success
- Billing marks each activity billed once sent to QBO, so retries and
  token refreshes don't create duplicate TimeActivities

Search
- New CustomerSearchService for autocomplete and the customer search
  page: nicknames (Bill/William), typos, word order, partial words,
  accents, and phone digits in any format; ranked, with the candidate
  list cached until a customer changes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
Claude committed 2026-10-28 22:08:36 -04:00
1 parent aacc2d645d
commit 0523e8dd24
18 files changed
+412 -111

No files matched your search

+20 -3
View File
@@ -10,14 +10,19 @@
class InvoicesController < ApplicationController
include AuthHelper
before_action :require_user, unless: -> { session[:token].nil? }
skip_before_action :verify_authenticity_token, :check_if_login_required, unless: -> { session[:token].nil? }
# PDFs: logged-in users, or a customer with a share link (limited to their issue's invoices).
# Redmine's own login check is replaced by require_login_or_customer_token for this action.
skip_before_action :check_if_login_required, only: :show
before_action :require_login_or_customer_token, only: :show
before_action :authorize_customer_invoices, only: :show
# Syncing is admin-only
before_action :require_admin, only: :sync
# Displays the invoice PDF in the browser or redirects with an error if not found.
def show
log "Processing request for #{request.original_url}"
invoice_ids = Array(params[:invoice_ids] || params[:id])
pdf, ref = PdfService.new(entity: Invoice).fetch_pdf(doc_ids: invoice_ids)
send_data pdf, filename: "invoice #{ref}.pdf", disposition: :inline, type: "application/pdf"
@@ -34,6 +39,18 @@ class InvoicesController < ApplicationController
private
def invoice_ids
@invoice_ids ||= Array(params[:invoice_ids] || params[:id]).map(&:to_s).reject(&:blank?)
end
# Share-link customers may only open invoices attached to their issue
def authorize_customer_invoices
return true unless customer_token_only?
allowed = customer_token.issue&.invoice_ids.to_a.map(&:to_s)
render_403 if invoice_ids.empty? || (invoice_ids - allowed).any?
end
# Logs messages with a consistent prefix for easier debugging.
def log(msg)
Rails.logger.info "[InvoiceController] #{msg}"