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

@@ -14,7 +14,7 @@ module RedmineQbo
def self.apply
AttachmentsController.class_eval do
# 1. PREPEND: Must run before ANY of Redmine's ApplicationController filters
prepend_before_action :set_customer_token_thread
prepend_before_action :load_customer_token
# 2. Skip global login redirects if the user holds a valid token for this file
skip_before_action :check_if_login_required, if: :valid_customer_token?
@@ -25,14 +25,14 @@ module RedmineQbo
private
def set_customer_token_thread
if session[:token].present?
Thread.current[:customer_token] = CustomerToken.active.find_by(token: session[:token])
end
# Kept on the controller instance (one per request) rather than Thread.current, which is reused
# across requests by the web server and could carry one customer's token into another request.
def load_customer_token
@customer_token = session[:token].present? ? CustomerToken.active.find_by(token: session[:token]) : nil
end
def valid_customer_token?
token = Thread.current[:customer_token]
token = @customer_token
return false unless token
# Handle "Download All" zip requests (object_type=issues, object_id=ID)
+5 -4
View File
@@ -32,12 +32,13 @@ module RedmineQbo
BillIssueTimeJob.perform_later(id)
end
# Titlize the subject for consistent formatting in billing descriptions
# Capitalize each word of the subject for consistent billing descriptions, without lowercasing
# the rest of the word (keeps LED, JL, 4x4 as typed). Only runs when the subject changes.
def titlize_subject
return unless subject.present? && will_save_change_to_subject?
log "Titlizing subject for issue ##{id}"
self.subject = subject.split(/\s+/).map do |word|
(word =~ /[A-Z]/ && word =~ /[0-9]/) ? word : word.capitalize
end.join(' ')
self.subject = RedmineQbo::TitleCase.call(subject)
end
# Generate a shareable token linking this issue to the customer for QuickBooks
@@ -16,11 +16,16 @@ module RedmineQbo
def watcher_link(issue, user)
links = ''
# Admin users can bill time
links << link_to(I18n.t(:label_bill_time), bill_path(issue.id), method: :get, class: 'icon icon-email-add') if user.admin?
# Users with the "Bill issues" permission can bill time (POST, so it can't be triggered by a plain link)
if user.allowed_to?(:bill_issues, issue.project)
links << link_to(I18n.t(:label_bill_time), bill_path(issue.id), method: :post,
data: { confirm: I18n.t(:text_are_you_sure) }, class: 'icon icon-email-add')
end
# Logged-in users can share the issue
links << link_to(I18n.t(:label_share), share_path(issue.id), method: :get, target: :_blank, class: 'icon icon-shared') if user.logged?
# Users with the "Share issues with customers" permission can create a customer link
if user.allowed_to?(:share_issues_with_customers, nil, global: true)
links << link_to(I18n.t(:label_share), share_path(issue.id), method: :get, target: :_blank, class: 'icon icon-shared')
end
# Append to the original watcher links
(links.html_safe + super).html_safe
+27
View File
@@ -0,0 +1,27 @@
#The MIT License (MIT)
#
#Copyright (c) 2016 - 2026 rick barrette
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
module RedmineQbo
# Capitalizes the first letter of every word and leaves the rest of each word exactly as typed,
# so acronyms and model names survive: "led light bar for JL" -> "Led Light Bar For JL",
# "LED" stays "LED", "4x4" stays "4x4", "(front)" -> "(Front)". Runs of whitespace become one space.
# (Rails' titleize lowercases the rest of each word, turning "LED" into "Led" and "JL" into "Jl".)
module TitleCase
module_function
def call(text)
return text if text.nil?
text.to_s.split(/\s+/).reject(&:empty?).map do |word|
word.sub(/\A([^\p{L}\p{N}]*)(\p{Ll})/) { "#{Regexp.last_match(1)}#{Regexp.last_match(2).upcase}" }
end.join(' ')
end
end
end