Merge branch 'dev' into feature/rails3_escape_units

Conflicts:
	CHANGELOG.md
pull/6827/head
Philipp Tessenow 11 years ago
commit 25ef4b2d7c
  1. 2
      CHANGELOG.md
  2. 4
      app/models/cost_object.rb
  3. 2
      app/models/journal/cost_object_journal.rb
  4. 31
      app/views/hooks/costs/_view_work_packages_context_menu_end.html.erb
  5. 2
      db/migrate/20130916094369_legacy_issues_costs_data_to_work_packages.rb
  6. 3
      lib/open_project/costs/engine.rb
  7. 47
      lib/open_project/costs/patches/work_packages_controller_patch.rb
  8. 24
      spec/controllers/work_packages_bulk_controller_spec.rb
  9. 4
      spec/models/work_package_spec.rb

@ -1,6 +1,8 @@
# Changelog
* `#1020` fix XSS when displaying costs
* `#2591` Fix: Costs prevents work package context menu
* added icon for new project menu
## 5.0.1.pre9

@ -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

@ -2,7 +2,7 @@
#-- copyright
# OpenProject is a project management system.
#
# Copyright (C) 2012-2013 the OpenProject Team
# Copyright (C) 2012-2013 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.

@ -1,24 +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
%>
<li class="folder">
<a href="#" class="submenu"><%= l(:label_cost_object) %></a>
<ul>
<% unless possible_cost_objects.empty? -%>
<% possible_cost_objects.each do |co| -%>
<li>
<%= 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] %>
</li>
<% 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 -%>
<li><%= l(cost_objects_any ? :notice_cost_object_conflict : :notice_no_cost_objects_available)%></li>
<li class="folder">
<a href="#" class="submenu"><%= l(:label_cost_object) %></a>
<ul>
<li><%= l(cost_objects_any ? :notice_cost_object_conflict : :notice_no_cost_objects_available)%></li>
</ul>
</li>
<% end -%>
</ul>
</li>
<% end %>

@ -1,7 +1,7 @@
#-- copyright
# OpenProject is a project management system.
#
# Copyright (C) 2012-2013 the OpenProject Team
# Copyright (C) 2012-2013 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.

@ -164,7 +164,8 @@ module OpenProject::Costs
{:controller => '/cost_objects', :action => 'index'},
:param => :project_id,
:before => :settings,
:caption => :cost_objects_title
:caption => :cost_objects_title,
:html => {:'data-icon2' => 'C'}
menu :project_menu,
:new_budget,

@ -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

@ -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

@ -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) }

Loading…
Cancel
Save