[#6441] Hide and disable unassignable deliverables from the issue
* Hide - Closed deliverables * Hide - Closed contract deliverables * Disable - Locked deliverables * Disable - Locked contract deliverables
This commit is contained in:
@@ -24,6 +24,21 @@ module ContractsHelper
|
||||
end
|
||||
end
|
||||
|
||||
def grouped_deliverable_options_for_select(project, selected_key=nil)
|
||||
project.contracts.with_status(["open","locked"]).inject([]) do |html, contract|
|
||||
options = contract.deliverables.with_status(["open","locked"]).collect do |deliverable|
|
||||
option_attributes = {}
|
||||
option_attributes[:value] = h(deliverable.id)
|
||||
option_attributes[:selected] = "selected" if selected_key.to_i == deliverable.id
|
||||
option_attributes[:disabled] = "disabled" if deliverable.locked? || contract.locked?
|
||||
|
||||
content_tag(:option, h(deliverable.title), option_attributes)
|
||||
end
|
||||
|
||||
html << content_tag(:optgroup, options.join("\n"), :label => h(contract.name))
|
||||
end.join('\n')
|
||||
end
|
||||
|
||||
def deliverable_options_for_contract(contract)
|
||||
contract.deliverables.collect {|d| [d.title, d.id]}
|
||||
end
|
||||
|
||||
@@ -38,7 +38,12 @@ class Contract < ActiveRecord::Base
|
||||
attr_accessible :status
|
||||
|
||||
named_scope :by_name, {:order => "#{Contract.table_name}.name ASC"}
|
||||
|
||||
named_scope :with_status, lambda {|statuses|
|
||||
{
|
||||
:conditions => ["#{Contract.table_name}.status IN (?)", statuses]
|
||||
}
|
||||
}
|
||||
|
||||
[:contract_type,
|
||||
:discount_spent, :discount_budget
|
||||
].each do |mthd|
|
||||
@@ -304,7 +309,7 @@ class Contract < ActiveRecord::Base
|
||||
end
|
||||
|
||||
if Rails.env.test?
|
||||
generator_for :name, :method => :next_name
|
||||
generator_for :name, :start => "Contract 0000"
|
||||
generator_for :executed => true
|
||||
generator_for(:start_date) { Date.yesterday }
|
||||
generator_for(:end_date) { Date.tomorrow }
|
||||
@@ -314,11 +319,7 @@ class Contract < ActiveRecord::Base
|
||||
generator_for :client_point_of_contact, ''
|
||||
generator_for :client_ap_contact_information, ''
|
||||
generator_for :po_number, ''
|
||||
|
||||
def self.next_name
|
||||
@last_name ||= 'Contract 0000'
|
||||
@last_name.succ!
|
||||
end
|
||||
generator_for :status, 'open'
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -46,6 +46,11 @@ class Deliverable < ActiveRecord::Base
|
||||
end
|
||||
|
||||
named_scope :by_title, {:order => "#{Deliverable.table_name}.title ASC"}
|
||||
named_scope :with_status, lambda {|statuses|
|
||||
{
|
||||
:conditions => ["#{Deliverable.table_name}.status IN (?)", statuses]
|
||||
}
|
||||
}
|
||||
|
||||
def short_type
|
||||
''
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
<% if project.module_enabled?(:contracts) && User.current.allowed_to?(:assign_deliverable_to_issue, project) %>
|
||||
<p>
|
||||
<%= label_tag(:deliverable_id, l(:field_deliverable)) %>
|
||||
<% options = project.contracts.inject([]) {|data, contract|
|
||||
data << [contract.name, contract.deliverables.collect {|d| [d.title, d.id]} ]
|
||||
} %>
|
||||
|
||||
<%= select_tag('deliverable_id',
|
||||
content_tag('option', l(:label_no_change_option), :value => '') +
|
||||
content_tag('option', l(:label_none), :value => 'none') +
|
||||
grouped_options_for_select(options)) %>
|
||||
grouped_deliverable_options_for_select(project)) %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<% if project.module_enabled?(:contracts) && User.current.allowed_to?(:assign_deliverable_to_issue, project) %>
|
||||
<p>
|
||||
<%= form.select(:deliverable_id, grouped_options_for_select(deliverable_options(project), issue.deliverable_id), {:include_blank => true}) %>
|
||||
<%= form.select(:deliverable_id, grouped_deliverable_options_for_select(project, issue.deliverable_id), {:include_blank => true}) %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ module RedmineContracts
|
||||
end
|
||||
|
||||
def validate_contract_status
|
||||
if deliverable.present? && changes["deliverable_id"].present?
|
||||
if deliverable.present? && changes["deliverable_id"].present? && contract.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
|
||||
|
||||
+36
@@ -11,12 +11,19 @@ class RedmineContracts::Hooks::ViewIssuesBulkEditDetailsBottomHookTest < ActionC
|
||||
@issue3 = Issue.generate_for_project!(@project)
|
||||
@contract1 = Contract.generate!(:project => @project)
|
||||
@contract2 = Contract.generate!(:project => @project)
|
||||
@locked_contract = Contract.generate!(:project => @project, :status => 'locked')
|
||||
@closed_contract = Contract.generate!(:project => @project, :status => 'closed')
|
||||
|
||||
@manager = User.generate!(:login => 'manager', :password => 'existing', :password_confirmation => 'existing')
|
||||
@role = Role.generate!(:permissions => [:view_issues, :edit_issues])
|
||||
User.add_to_project(@manager, @project, @role)
|
||||
@deliverable1 = FixedDeliverable.generate!(:contract => @contract1, :manager => @manager, :title => 'The Title')
|
||||
@deliverable2 = FixedDeliverable.generate!(:contract => @contract2, :manager => @manager, :title => 'The Title')
|
||||
@locked_deliverable = FixedDeliverable.generate!(:contract => @contract1, :manager => @manager, :title => 'Locked Deliverable', :status => 'locked')
|
||||
@closed_deliverable = FixedDeliverable.generate!(:contract => @contract1, :manager => @manager, :title => 'Closed Deliverable', :status => 'closed')
|
||||
@deliverable1_on_locked_contract = FixedDeliverable.generate!(:contract => @locked_contract, :manager => @manager, :title => 'Deliverable 1 on locked contract')
|
||||
@deliverable2_on_locked_contract = FixedDeliverable.generate!(:contract => @locked_contract, :manager => @manager, :title => 'Deliverable 2 on locked contract')
|
||||
@deliverable_on_closed_contract = FixedDeliverable.generate!(:contract => @closed_contract, :manager => @manager, :title => 'Deliverable on closed contract')
|
||||
@issue.deliverable = @deliverable1
|
||||
|
||||
login_as('manager', 'existing')
|
||||
@@ -42,6 +49,35 @@ class RedmineContracts::Hooks::ViewIssuesBulkEditDetailsBottomHookTest < ActionC
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should "disable all locked deliverables" do
|
||||
assert_select "select#deliverable_id" do
|
||||
assert_select "option[disabled=disabled]", :text => /#{@locked_deliverable.title}/
|
||||
end
|
||||
end
|
||||
|
||||
should "disable all deliverables on locked contracts" do
|
||||
assert_select "select#deliverable_id" do
|
||||
assert_select "optgroup[label=?]", @locked_contract.name do
|
||||
assert_select "option[disabled=disabled]", :text => /#{@deliverable1_on_locked_contract.title}/
|
||||
assert_select "option[disabled=disabled]", :text => /#{@deliverable2_on_locked_contract.title}/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should "not show closed deliverables" do
|
||||
assert_select "select#deliverable_id" do
|
||||
assert_select "option", :text => /#{@closed_deliverable.title}/, :count => 0
|
||||
end
|
||||
end
|
||||
|
||||
should "not show deliverables on closed contracts" do
|
||||
assert_select "select#deliverable_id" do
|
||||
assert_select "optgroup[label=?]", @closed_contract.name, :count => 0
|
||||
assert_select "option", :text => /#{@deliverable_on_closed_contract.title}/, :count => 0
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "with no permission to Assign Deliverable" do
|
||||
|
||||
@@ -9,12 +9,19 @@ class RedmineContracts::Hooks::ViewIssuesFormDetailsBottomTest < ActionControlle
|
||||
@issue = Issue.generate_for_project!(@project)
|
||||
@contract1 = Contract.generate!(:project => @project)
|
||||
@contract2 = Contract.generate!(:project => @project)
|
||||
@locked_contract = Contract.generate!(:project => @project, :status => 'locked')
|
||||
@closed_contract = Contract.generate!(:project => @project, :status => 'closed')
|
||||
|
||||
@manager = User.generate!(:login => 'manager', :password => 'existing', :password_confirmation => 'existing')
|
||||
@role = Role.generate!(:permissions => [:view_issues, :edit_issues])
|
||||
User.add_to_project(@manager, @project, @role)
|
||||
@deliverable1 = FixedDeliverable.generate!(:contract => @contract1, :manager => @manager, :title => 'The Title')
|
||||
@deliverable2 = FixedDeliverable.generate!(:contract => @contract2, :manager => @manager, :title => 'The Title')
|
||||
@locked_deliverable = FixedDeliverable.generate!(:contract => @contract1, :manager => @manager, :title => 'Locked Deliverable', :status => 'locked')
|
||||
@closed_deliverable = FixedDeliverable.generate!(:contract => @contract1, :manager => @manager, :title => 'Closed Deliverable', :status => 'closed')
|
||||
@deliverable1_on_locked_contract = FixedDeliverable.generate!(:contract => @locked_contract, :manager => @manager, :title => 'Deliverable 1 on locked contract')
|
||||
@deliverable2_on_locked_contract = FixedDeliverable.generate!(:contract => @locked_contract, :manager => @manager, :title => 'Deliverable 2 on locked contract')
|
||||
@deliverable_on_closed_contract = FixedDeliverable.generate!(:contract => @closed_contract, :manager => @manager, :title => 'Deliverable on closed contract')
|
||||
@issue.deliverable = @deliverable1
|
||||
|
||||
login_as('manager', 'existing')
|
||||
@@ -39,6 +46,35 @@ class RedmineContracts::Hooks::ViewIssuesFormDetailsBottomTest < ActionControlle
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should "disable all locked deliverables" do
|
||||
assert_select "select#issue_deliverable_id" do
|
||||
assert_select "option[disabled=disabled]", :text => /#{@locked_deliverable.title}/
|
||||
end
|
||||
end
|
||||
|
||||
should "disable all deliverables on locked contracts" do
|
||||
assert_select "select#issue_deliverable_id" do
|
||||
assert_select "optgroup[label=?]", @locked_contract.name do
|
||||
assert_select "option[disabled=disabled]", :text => /#{@deliverable1_on_locked_contract.title}/
|
||||
assert_select "option[disabled=disabled]", :text => /#{@deliverable2_on_locked_contract.title}/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should "not show closed deliverables" do
|
||||
assert_select "select#issue_deliverable_id" do
|
||||
assert_select "option", :text => /#{@closed_deliverable.title}/, :count => 0
|
||||
end
|
||||
end
|
||||
|
||||
should "not show deliverables on closed contracts" do
|
||||
assert_select "select#issue_deliverable_id" do
|
||||
assert_select "optgroup[label=?]", @closed_contract.name, :count => 0
|
||||
assert_select "option", :text => /#{@deliverable_on_closed_contract.title}/, :count => 0
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "with no permission to Assign Deliverable" do
|
||||
|
||||
Reference in New Issue
Block a user