mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-17 18:20:36 -05:00
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:
18 files changed
+412
-111
No files matched your search
+29
-23
@@ -10,47 +10,53 @@
|
||||
|
||||
module AuthHelper
|
||||
|
||||
def require_user
|
||||
return unless session[:token].nil?
|
||||
if !User.current.logged?
|
||||
flash[:error] = t :notice_forbidden
|
||||
render_403
|
||||
end
|
||||
# The active customer share token stored in the session by customers#view, if any.
|
||||
def customer_token
|
||||
return @customer_token if defined?(@customer_token)
|
||||
|
||||
@customer_token = session[:token].present? ? CustomerToken.active.find_by(token: session[:token]) : nil
|
||||
end
|
||||
|
||||
|
||||
# True when the visitor is a customer using a share link rather than a logged-in user.
|
||||
def customer_token_only?
|
||||
!User.current.logged? && customer_token.present?
|
||||
end
|
||||
|
||||
# Logged-in users pass. Customers with an active share link pass too (each controller then limits them
|
||||
# to their own issue's documents). Everyone else is sent to the login page.
|
||||
def require_login_or_customer_token
|
||||
return true if User.current.logged?
|
||||
return true if customer_token
|
||||
|
||||
require_login
|
||||
end
|
||||
|
||||
def allowed_to?(action)
|
||||
return false if User.current.nil?
|
||||
project = Project.find(params[:project_id])
|
||||
project = Project.find_by(id: params[:project_id])
|
||||
return false if project.nil?
|
||||
return true if User.current.allowed_to?(action, project)
|
||||
false
|
||||
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
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
||||
def globaly_allowed_to?( action)
|
||||
|
||||
# True if the user has the permission through any of their roles (or is an admin)
|
||||
def globaly_allowed_to?(action)
|
||||
return false if User.current.nil?
|
||||
|
||||
projects = Project.all
|
||||
projects.each { |p|
|
||||
if User.current.allowed_to?(action, p)
|
||||
return true
|
||||
end
|
||||
}
|
||||
false
|
||||
User.current.allowed_to?(action, nil, global: true)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
Reference in new issue
Block a user