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:
rickyandClaude Opus 5.5 committed 2026-11-20 17:36:20 -05:00
1 parent 17f24f9641
commit b829593bc2
14 files changed
+174 -99

No files matched your search

+17 -3
View File
@@ -100,8 +100,7 @@ class CustomersControllerTest < Redmine::IntegrationTest
assert_equal 'new@example.com', @fake.created.last.email_address.address
end
# The controller doesn't accept API keys (no accept_api_auth) and Redmine ignores the session on JSON
# requests, so customers can't be created as JSON: the format.json branches of #create aren't reachable
# Customers are created from the page only; JSON requests are refused
def test_json_create_is_refused
Role.find(1).add_permission!(:view_customers)
Role.find(1).add_permission!(:add_customers)
@@ -109,10 +108,25 @@ class CustomersControllerTest < Redmine::IntegrationTest
post '/customers.json', params: { customer: { name: 'Json Person' } },
headers: { 'X-Redmine-API-Key' => User.find(2).api_key }
end
assert_includes [401, 403], response.status
assert_includes [401, 403, 406], response.status
assert_not Customer.exists?(name: 'Json Person')
end
def test_invalid_customer_shows_the_form_again
grant(:view_customers, :add_customers)
post '/customers', params: { customer: { name: '' } }
assert_response :unprocessable_entity
assert_select '#errorExplanation'
end
def test_quickbooks_error_on_create_is_shown
grant(:view_customers, :add_customers)
@fake.define_singleton_method(:create) { |_doc| raise Quickbooks::IntuitRequestException, 'Duplicate Name Exists' }
post '/customers', params: { customer: { name: 'Jane Customer' } }
assert_redirected_to '/customers/new'
assert_match 'Duplicate Name Exists', flash[:error]
end
def test_update_needs_edit_customers
grant(:view_customers)
Role.find(1).remove_permission!(:edit_customers)