mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-20 18:40:37 -05:00
Limit estimate and invoice PDFs by permission; clean up
Any logged-in user could open any estimate or invoice PDF by id. Now: - estimates: View customers or Write estimates, or an estimate attached to an issue the user can see (the issue page links to it); users without the permission don't trigger a sync of uncached estimates - invoices: View customers, Write invoices, View/Receive payments or Issue refunds, or invoices attached to issues the user can see - share-link customers are unchanged (their own issue's documents) - the sidebar's estimate search only shows to those who can use it The issue PDF merges an estimate PDF with optional content, as it already did for the issue's own PDF, instead of failing. Removed dead code: the JSON branches of CustomersController#create (Redmine refuses JSON there) and the scaffold views for qbo#authenticate, #oauth_callback and #webhook, which those actions never render. An invalid customer now shows the form with a 422. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
17f24f9641
commit
b829593bc2
14 files changed
+174
-99
No files matched your search
@@ -31,6 +31,21 @@ module AuthHelper
|
||||
require_login
|
||||
end
|
||||
|
||||
# A logged-in user may open the estimate's PDF with a billing permission (RedmineQboBilling.estimate_viewer?),
|
||||
# or when it's attached to an issue they can see (the issue page links to it)
|
||||
def estimate_pdf_allowed?(estimate)
|
||||
RedmineQboBilling.estimate_viewer? || Issue.visible.where(estimate_id: estimate.id).exists?
|
||||
end
|
||||
|
||||
# The same for invoices: every one of them must be attached to an issue the user can see
|
||||
def invoice_pdfs_allowed?(invoice_ids)
|
||||
return true if RedmineQboBilling.invoice_viewer?
|
||||
|
||||
ids = Array(invoice_ids).map(&:to_s).uniq
|
||||
visible = Invoice.joins(:issues).merge(Issue.visible).where(id: ids).distinct.pluck(:id).map(&:to_s)
|
||||
ids.any? && (ids - visible).empty?
|
||||
end
|
||||
|
||||
def global_check_permission(permission)
|
||||
if !globaly_allowed_to?(permission)
|
||||
flash[:error] = t :notice_forbidden
|
||||
|
||||
Reference in new issue
Block a user