From f65970427582e6a265e2c86b4d167e7f12bbbcfc Mon Sep 17 00:00:00 2001 From: Christian Rijke Date: Thu, 31 Oct 2013 16:53:30 +0100 Subject: [PATCH 1/5] Fix context menu link. --- .../costs/_view_work_packages_context_menu_end.html.erb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/hooks/costs/_view_work_packages_context_menu_end.html.erb b/app/views/hooks/costs/_view_work_packages_context_menu_end.html.erb index ceafe57217..4119bf167d 100644 --- a/app/views/hooks/costs/_view_work_packages_context_menu_end.html.erb +++ b/app/views/hooks/costs/_view_work_packages_context_menu_end.html.erb @@ -12,8 +12,9 @@ <% unless possible_cost_objects.empty? -%> <% possible_cost_objects.each do |co| -%>
  • - <%= context_menu_link co.subject, {:controller => '/issues', :action => 'bulk_edit', :ids => issues.collect(&:id), 'cost_object_id' => co, :back_url => back}, :method => :post, - :selected => (issue && co == issue.cost_object), :disabled => !can[:edit] %> + <%= context_menu_link(co.subject, work_packages_bulk_path(ids: issues.collect(&:id), + work_package: { "cost_object_id" => co}, back_url: back), method: :put, + selected: (@work_package && co == @work_package.cost_object), disabled: !can[:edit]) %>
  • <% end -%> <% else -%> From 8694b8f6b6ed582f8f5d7b05a2eefaaee78cc587 Mon Sep 17 00:00:00 2001 From: Till Breuer Date: Mon, 11 Nov 2013 20:49:48 +0100 Subject: [PATCH 2/5] Use context menu entry helper method to build 'Budget' context menu entry --- app/models/cost_object.rb | 4 +++ ...ew_work_packages_context_menu_end.html.erb | 32 ++++++++++--------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/app/models/cost_object.rb b/app/models/cost_object.rb index a1d2f97c01..64e4eb05bf 100644 --- a/app/models/cost_object.rb +++ b/app/models/cost_object.rb @@ -119,4 +119,8 @@ class CostObject < ActiveRecord::Base self.update_all ['author_id = ?', substitute.id], ['author_id = ?', user.id] end + + def to_s + subject + end end diff --git a/app/views/hooks/costs/_view_work_packages_context_menu_end.html.erb b/app/views/hooks/costs/_view_work_packages_context_menu_end.html.erb index 4119bf167d..16a5aaa160 100644 --- a/app/views/hooks/costs/_view_work_packages_context_menu_end.html.erb +++ b/app/views/hooks/costs/_view_work_packages_context_menu_end.html.erb @@ -1,25 +1,27 @@ <% if @project && @project.module_enabled?(:costs_module) %> <% - cost_objects_any = false - possible_cost_objects = issues.inject(issues.first.project.cost_objects) do |intersect, work_package| + cost_objects_any = false + possible_cost_objects = issues.inject(issues.first.project.cost_objects) do |intersect, work_package| cost_objects_any |= work_package.project.cost_objects.any? work_package.project.cost_objects & intersect end %> -
  • - <%= l(:label_cost_object) %> -
      + <% unless possible_cost_objects.empty? -%> - <% possible_cost_objects.each do |co| -%> -
    • - <%= context_menu_link(co.subject, work_packages_bulk_path(ids: issues.collect(&:id), - work_package: { "cost_object_id" => co}, back_url: back), method: :put, - selected: (@work_package && co == @work_package.cost_object), disabled: !can[:edit]) %> -
    • - <% end -%> + <%= context_menu_entry title: l(:label_cost_object), + back_url: back, + updated_object_ids: issues.collect(&:id), + collection: possible_cost_objects, + attribute: 'cost_object', + selected: lambda { |cost_object| @work_package && cost_object == @work_package.cost_object }, + disabled: lambda { |cost_object| !can[:edit] } %> + <% else -%> -
    • <%= l(cost_objects_any ? :notice_cost_object_conflict : :notice_no_cost_objects_available)%>
    • +
    • + <%= l(:label_cost_object) %> +
        +
      • <%= l(cost_objects_any ? :notice_cost_object_conflict : :notice_no_cost_objects_available)%>
      • +
      +
    • <% end -%> -
    -
  • <% end %> From c6b80df6a75eed8e8dc7d2cb43e3958a6eab8526 Mon Sep 17 00:00:00 2001 From: Till Breuer Date: Tue, 12 Nov 2013 11:51:19 +0100 Subject: [PATCH 3/5] Use active support concern for work packages controller spec --- .../patches/work_packages_controller_patch.rb | 47 +++++++++---------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/lib/open_project/costs/patches/work_packages_controller_patch.rb b/lib/open_project/costs/patches/work_packages_controller_patch.rb index 58a3c5adee..6d7b93055a 100644 --- a/lib/open_project/costs/patches/work_packages_controller_patch.rb +++ b/lib/open_project/costs/patches/work_packages_controller_patch.rb @@ -1,36 +1,31 @@ require_dependency 'work_packages_controller' module OpenProject::Costs::Patches::WorkPackagesControllerPatch - def self.included(base) # :nodoc: - base.send(:include, InstanceMethods) - - base.class_eval do - alias_method_chain :show, :entries - end + extend ActiveSupport::Concern + included do + alias_method_chain :show, :entries end - module InstanceMethods - # Authorize the user for the requested action - def show_with_entries - @cost_entries = work_package.cost_entries.visible(User.current, work_package.project) - cost_entries_with_rate = @cost_entries.select{|c| c.costs_visible_by?(User.current)} - @material_costs = cost_entries_with_rate.blank? ? nil : cost_entries_with_rate.collect(&:real_costs).sum - - @time_entries = work_package.time_entries.visible(User.current, work_package.project) - time_entries_with_rate = @time_entries.select{|c| c.costs_visible_by?(User.current)} - @labor_costs = time_entries_with_rate.blank? ? nil : time_entries_with_rate.collect(&:real_costs).sum - - unless @material_costs.nil? && @labor_costs.nil? - @overall_costs = 0 - @overall_costs += @material_costs unless @material_costs.nil? - @overall_costs += @labor_costs unless @labor_costs.nil? - else - @overall_costs = nil - end - - show_without_entries + # Authorize the user for the requested action + def show_with_entries + @cost_entries = work_package.cost_entries.visible(User.current, work_package.project) + cost_entries_with_rate = @cost_entries.select{|c| c.costs_visible_by?(User.current)} + @material_costs = cost_entries_with_rate.blank? ? nil : cost_entries_with_rate.collect(&:real_costs).sum + + @time_entries = work_package.time_entries.visible(User.current, work_package.project) + time_entries_with_rate = @time_entries.select{|c| c.costs_visible_by?(User.current)} + @labor_costs = time_entries_with_rate.blank? ? nil : time_entries_with_rate.collect(&:real_costs).sum + + unless @material_costs.nil? && @labor_costs.nil? + @overall_costs = 0 + @overall_costs += @material_costs unless @material_costs.nil? + @overall_costs += @labor_costs unless @labor_costs.nil? + else + @overall_costs = nil end + + show_without_entries end end From 2a27acc18711fb940ab5a00e835638a4ec759a66 Mon Sep 17 00:00:00 2001 From: Till Breuer Date: Tue, 12 Nov 2013 11:51:48 +0100 Subject: [PATCH 4/5] Add controller spec for cost object updates via context menu --- .../work_packages_bulk_controller_spec.rb | 24 +++++++++++++++++++ spec/models/work_package_spec.rb | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 spec/controllers/work_packages_bulk_controller_spec.rb diff --git a/spec/controllers/work_packages_bulk_controller_spec.rb b/spec/controllers/work_packages_bulk_controller_spec.rb new file mode 100644 index 0000000000..0019ad7483 --- /dev/null +++ b/spec/controllers/work_packages_bulk_controller_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe WorkPackages::BulkController do + let(:project) { FactoryGirl.create(:project_with_types) } + let(:controller_role) { FactoryGirl.build(:role, :permissions => [:view_work_packages, :edit_work_packages]) } + let(:user) { FactoryGirl.create :user, member_in_project: project, member_through_role: controller_role } + let(:cost_object) { FactoryGirl.create :cost_object, project: project } + let(:work_package) { FactoryGirl.create(:work_package, project: project) } + + before do + User.stub(:current).and_return user + end + + describe :update do + context 'when a cost report is assigned' do + before { put :update, ids: [work_package.id], work_package: {cost_object_id: cost_object.id} } + + subject { work_package.reload.cost_object.try :id } + + it { should == cost_object.id } + end + end + +end \ No newline at end of file diff --git a/spec/models/work_package_spec.rb b/spec/models/work_package_spec.rb index f2cb9b3271..999512dff2 100644 --- a/spec/models/work_package_spec.rb +++ b/spec/models/work_package_spec.rb @@ -11,8 +11,8 @@ describe WorkPackage do let(:project2) { FactoryGirl.create(:project_with_types, types: project.types) } let(:work_package) { FactoryGirl.create(:work_package, :project => project, - :type => project.types.first, - :author => user) } + :type => project.types.first, + :author => user) } let!(:cost_entry) { FactoryGirl.create(:cost_entry, work_package: work_package, project: project, units: 3, spent_on: Date.today, user: user, comments: "test entry") } let!(:cost_object) { FactoryGirl.create(:cost_object, project: project) } From dbc97d5fe6c8806a8a691ff88156565cef6628d7 Mon Sep 17 00:00:00 2001 From: Sebastian Schuster Date: Mon, 18 Nov 2013 16:39:36 +0100 Subject: [PATCH 5/5] Added changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5b4b835d2..07a584ed7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +* `#2591` Fix: Costs prevents work package context menu + ## 5.0.1.pre9 * Added missing translations