mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-20 18:40:37 -05:00
Allow unlocking estimates linked to issues
An estimate attached to an issue was read-only, so changing it after a customer asked for tweaks meant taking it off the work order first. A new global permission, "Edit estimates linked to issues" (on top of Write estimates), shows an "Unlock to edit" button on a linked estimate. After a confirmation the estimate opens for editing, and the issues stay linked when it's saved. EstimateWriter.save still refuses a linked estimate unless it was unlocked by a user with the permission. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
22af08cee7
commit
48f92f241f
9 files changed
+118
-4
No files matched your search
@@ -0,0 +1,56 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 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.
|
||||
|
||||
require File.expand_path('../test_helper', __dir__)
|
||||
|
||||
# Estimates linked to an issue are read-only unless unlocked by a user with "Edit estimates linked to issues"
|
||||
class LinkedEstimateUnlockTest < ActiveSupport::TestCase
|
||||
Writer = RedmineQboBilling::EstimateWriter
|
||||
|
||||
def user(*permissions)
|
||||
user = User.new
|
||||
user.stubs(:allowed_to?).returns(false)
|
||||
permissions.each { |p| user.stubs(:allowed_to?).with(p, nil, global: true).returns(true) }
|
||||
user
|
||||
end
|
||||
|
||||
def form(linked:)
|
||||
Writer.stubs(:linked_issues).with('701').returns(stub(exists?: linked))
|
||||
RedmineQboBilling::EstimateForm.new.tap { |f| f.id = '701' }
|
||||
end
|
||||
|
||||
def test_editor_needs_write_estimates_and_edit_linked_estimates
|
||||
assert RedmineQboBilling.linked_estimate_editor?(user(:write_estimates, :edit_linked_estimates))
|
||||
assert_not RedmineQboBilling.linked_estimate_editor?(user(:write_estimates))
|
||||
assert_not RedmineQboBilling.linked_estimate_editor?(user(:edit_linked_estimates))
|
||||
end
|
||||
|
||||
def test_unlinked_estimate_saves_without_unlocking
|
||||
assert_nothing_raised { Writer.check_linked(form(linked: false), false, user(:write_estimates)) }
|
||||
end
|
||||
|
||||
def test_linked_estimate_is_locked_without_unlock
|
||||
error = assert_raises(Writer::Error) do
|
||||
Writer.check_linked(form(linked: true), false, user(:write_estimates, :edit_linked_estimates))
|
||||
end
|
||||
assert_equal I18n.t(:error_estimate_linked_to_issues), error.message
|
||||
end
|
||||
|
||||
def test_unlock_needs_the_permission
|
||||
error = assert_raises(Writer::Error) { Writer.check_linked(form(linked: true), true, user(:write_estimates)) }
|
||||
assert_equal I18n.t(:error_estimate_linked_not_allowed), error.message
|
||||
end
|
||||
|
||||
def test_unlocked_by_an_editor_saves
|
||||
assert_nothing_raised do
|
||||
Writer.check_linked(form(linked: true), true, user(:write_estimates, :edit_linked_estimates))
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user