[#6441] Block assigning issues to deliverable on a locked or closed contract
This commit is contained in:
@@ -5,6 +5,8 @@ en:
|
||||
cant_create_time_on_object: "Can't create a time entry on a %{reason} %{thing}"
|
||||
cant_assign_to_closed_deliverable: "Can't assign issue to a closed deliverable"
|
||||
cant_assign_to_locked_deliverable: "Can't assign issue to a locked deliverable"
|
||||
cant_assign_to_closed_contract: "Can't assign issue to a closed contract"
|
||||
cant_assign_to_locked_contract: "Can't assign issue to a locked contract"
|
||||
cant_update_locked_deliverable: "Can't update a locked deliverable"
|
||||
cant_update_closed_deliverable: "Can't update a closed deliverable"
|
||||
cant_update_locked_contract: "Can't update a locked contract"
|
||||
|
||||
@@ -17,6 +17,7 @@ module RedmineContracts
|
||||
end
|
||||
|
||||
validate :validate_deliverable_status
|
||||
validate :validate_contract_status
|
||||
|
||||
def validate_deliverable_status
|
||||
if deliverable.present? && changes["deliverable_id"].present?
|
||||
@@ -25,6 +26,13 @@ module RedmineContracts
|
||||
end
|
||||
end
|
||||
|
||||
def validate_contract_status
|
||||
if deliverable.present? && changes["deliverable_id"].present?
|
||||
errors.add_to_base(:cant_assign_to_closed_contract) if contract.closed?
|
||||
errors.add_to_base(:cant_assign_to_locked_contract) if contract.locked?
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -70,6 +70,38 @@ class RedmineContracts::Hooks::ControllerIssuesEditBeforeSaveTest < ActionContro
|
||||
|
||||
end
|
||||
|
||||
should "not allow setting a Deliverable on a locked Contract" do
|
||||
assert @contract2.lock!
|
||||
click_link "New issue"
|
||||
|
||||
fill_in "Subject", :with => 'Hook test'
|
||||
select @deliverable2.title, :from => "Deliverable"
|
||||
assert_no_difference("Issue.count") do
|
||||
click_button "Create"
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
assert_equal nil, Issue.last.deliverable
|
||||
|
||||
end
|
||||
|
||||
should "not allow setting a Deliverable on a closed Contract" do
|
||||
assert @contract2.close!
|
||||
click_link "New issue"
|
||||
|
||||
fill_in "Subject", :with => 'Hook test'
|
||||
select @deliverable2.title, :from => "Deliverable"
|
||||
assert_no_difference("Issue.count") do
|
||||
click_button "Create"
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
assert_equal nil, Issue.last.deliverable
|
||||
|
||||
end
|
||||
|
||||
context "with no permission to Assign Deliverable" do
|
||||
should "not allow setting the Deliverable (force HTTP request)" do
|
||||
@role.permissions.delete(:assign_deliverable_to_issue)
|
||||
@@ -125,6 +157,30 @@ class RedmineContracts::Hooks::ControllerIssuesEditBeforeSaveTest < ActionContro
|
||||
|
||||
end
|
||||
|
||||
should "not allow updating to a deliverable on a locked contract" do
|
||||
assert @contract2.lock!
|
||||
select @deliverable2.title, :from => "Deliverable"
|
||||
click_button "Submit"
|
||||
|
||||
assert_response :success
|
||||
|
||||
@issue.reload
|
||||
assert_equal nil, @issue.deliverable
|
||||
|
||||
end
|
||||
|
||||
should "not allow updating to a deliverable on a closed contract" do
|
||||
assert @contract2.close!
|
||||
select @deliverable2.title, :from => "Deliverable"
|
||||
click_button "Submit"
|
||||
|
||||
assert_response :success
|
||||
|
||||
@issue.reload
|
||||
assert_equal nil, @issue.deliverable
|
||||
|
||||
end
|
||||
|
||||
should "allow updating an issue, even if the deliverable is locked as long as the deliverable isn't changed" do
|
||||
select @deliverable2.title, :from => "Deliverable"
|
||||
click_button "Submit"
|
||||
|
||||
Reference in New Issue
Block a user