Merge branch 'release/3.0' into dev

pull/6827/head
Christian Ratz 11 years ago
commit 4d9dd7bef7
  1. 12
      README.md
  2. 3
      doc/CHANGELOG.md
  3. 3
      lib/open_project/reporting/engine.rb
  4. 87
      lib/open_project/reporting/patches/custom_fields_controller_patch.rb
  5. 2
      lib/open_project/reporting/version.rb
  6. 4
      openproject-reporting.gemspec
  7. 147
      spec/controllers/custom_fields_controller_spec.rb

@ -16,19 +16,19 @@ Installation
OpenProject Reporting depends on OpenProject Plugins. Thus, if you haven't done it already, add the following line to the `Gemfile.plugins` in your OpenProject installation:
`gem "openproject-plugins", git: "https://github.com/opf/openproject-plugins.git", :branch => "dev"`
`gem "openproject-plugins", git: "https://github.com/opf/openproject-plugins.git", :branch => "stable"`
Reporting also depends on the OpenProject Costs plugin. If you have not installed it yet, you can do so by adding the following line to the `Gemfile.plugins` in your OpenProject installation:
`gem "openproject-costs", git: "https://github.com/finnlabs/openproject-costs.git", :branch => "dev"`
`gem "openproject-costs", git: "https://github.com/finnlabs/openproject-costs.git", :branch => "stable"`
Furthermore, OpenProject reporting depends on the ReportingEngine which should be installed by adding the following line to your `Gemfile.plugins` in your OpenProject installation folder:
`gem "reporting_engine", git: "https://github.com/finnlabs/reporting_engine.git", :branch => "dev"`
`gem "reporting_engine", git: "https://github.com/finnlabs/reporting_engine.git", :branch => "stable"`
Finally, add the following line to your `Gemfile.plugins` in your OpenProject installation folder to use the Reporting plugin:
`gem "openproject-reporting", git: "https://github.com/finnlabs/openproject-reporting.git", :branch => "dev"`
`gem "openproject-reporting", git: "https://github.com/finnlabs/openproject-reporting.git", :branch => "stable"`
Afterwards, run:
@ -40,8 +40,8 @@ Deinstallation
Remove the lines
`gem "reporting_engine", git: "https://github.com/finnlabs/reporting_engine.git", :branch => "dev"`
`gem "openproject-reporting", git: "https://github.com/finnlabs/openproject-reporting.git", :branch => "dev"`
`gem "reporting_engine", git: "https://github.com/finnlabs/reporting_engine.git", :branch => "stable"`
`gem "openproject-reporting", git: "https://github.com/finnlabs/openproject-reporting.git", :branch => "stable"`
from your `Gemfile.plugins` in your OpenProject installation folder and run:

@ -20,8 +20,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# Changelog
## 4.0.1
## 3.0.8
* `#7905` custom field not removed from cost report after delete
* `#5191` Public Release Reporting Plugin
* `#4024` Fix: Subpages have no unique page titles

@ -83,8 +83,9 @@ module OpenProject::Reporting
require_dependency 'widget/simple_table'
require_dependency 'widget/entry_table'
require_dependency 'widget/settings_patch'
require_dependency 'cost_query/group_by'
end
patches [:CostlogController, :TimelogController]
patches [:CostlogController, :TimelogController, :CustomFieldsController]
end
end

@ -0,0 +1,87 @@
#-- copyright
# OpenProject Reporting Plugin
#
# Copyright (C) 2010 - 2014 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.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#++
require_dependency 'costlog_controller'
module OpenProject::Reporting::Patches
module CustomFieldsControllerPatch
def self.included(base) # :nodoc:
base.send(:include, InstanceMethods)
base.class_eval do
unloadable
alias_method_chain :destroy, :custom_fields
end
end
module InstanceMethods
def destroy_with_custom_fields
id = @custom_field.id
reports = CostQuery.where("serialized LIKE '%CustomField#{id}%'")
remove_custom_field_from_cost_report(reports, id)
remove_custom_field_from_session(id)
destroy_without_custom_fields
end
private
def remove_custom_field_from_cost_report(affected_reports, id)
custom_field_name = "CustomField#{id}"
affected_reports.each do |report|
filters = reject_from_query_properties(report, :filters, custom_field_name)
group_bys = reject_from_query_properties(report, :group_bys, custom_field_name)
updated_report = build_query(report.engine, filters, group_bys)
report.migrate(updated_report)
report.save!
end
end
def reject_from_query_properties(report, property, custom_field_name)
report.serialized[property].reject { |f| f[0] == custom_field_name }
end
def build_query(report_engine, filters, groups = {})
query = report_engine.deserialize({ filters: filters, group_bys: groups })
query.serialize
query
end
def remove_custom_field_from_session(id)
custom_field_name = "custom_field#{id}".to_sym
report_engine_name = CostQuery.name.underscore.to_sym
cookie = session[report_engine_name]
if cookie
cookie[:filters][:operators].delete(custom_field_name)
cookie[:filters][:values].delete(custom_field_name)
cookie[:groups][:rows].delete(custom_field_name.to_s)
cookie[:groups][:columns].delete(custom_field_name.to_s)
session[report_engine_name] = cookie
end
end
end
end
end

@ -19,6 +19,6 @@
module OpenProject
module Reporting
VERSION = '4.0.1'
VERSION = '3.0.8'
end
end

@ -17,9 +17,9 @@ Gem::Specification.new do |s|
s.test_files = Dir["spec/**/*"]
s.add_dependency "rails", "~> 3.2.9"
s.add_dependency "openproject-plugins", "~> 1.0.6"
s.add_dependency "openproject-plugins", "~> 3.0.8"
s.add_dependency "reporting_engine", ">= 1.0.0"
s.add_dependency "openproject-costs", ">= 5.0.3"
s.add_dependency "openproject-costs", ">= 3.0.8"
s.add_development_dependency "factory_girl_rails", "~> 4.0"
end

@ -0,0 +1,147 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
describe CustomFieldsController do
let!(:custom_field) { FactoryGirl.create(:work_package_custom_field) }
let!(:custom_field_permanent) { FactoryGirl.create(:work_package_custom_field) }
let(:custom_field_name) { "CustomField#{custom_field.id}" }
let(:custom_field_permanent_name) { "CustomField#{custom_field_permanent.id}" }
let(:cost_query) { FactoryGirl.build(:cost_query) }
before do
@controller.stub(:authorize)
@controller.stub(:check_if_login_required)
@controller.stub(:require_admin)
CostQuery::Filter::CustomFieldEntries.reset!
CostQuery::Filter::CustomFieldEntries.all
CostQuery::GroupBy::CustomFieldEntries.reset!
CostQuery::GroupBy::CustomFieldEntries.all
end
describe '#destroy' do
shared_context 'remove custom field' do
before do
cost_query.filter(custom_field_permanent_name, { operator: '=', values: [] })
cost_query.group_by(custom_field_permanent_name)
cost_query.save!
delete :destroy, id: custom_field.id
end
end
shared_examples_for 'custom field is removed from cost query' do
include_context 'remove custom field'
shared_examples_for 'custom field removed' do
it { expect(subject).not_to include(name) }
end
shared_examples_for 'custom field exists' do
it { expect(subject).to include(name) }
end
describe 'custom field is removed from cost query filter' do
subject { CostQuery.find(cost_query.id).filters.collect(&:class).collect(&:name) }
it_behaves_like 'custom field removed' do
let(:name) { "CostQuery::Filter::#{custom_field_name}" }
end
end
describe 'custom field is removed from cost query group bys' do
subject { CostQuery.find(cost_query.id).group_bys.collect(&:class).collect(&:name) }
it_behaves_like 'custom field removed' do
let(:name) { "CostQuery::GroupBy::#{custom_field_name}" }
end
end
describe 'permanent custom field still exists in cost query filter' do
subject { cost_query.reload.filters.collect(&:class).collect(&:name) }
it_behaves_like 'custom field exists' do
let(:name) { "CostQuery::Filter::#{custom_field_permanent_name}" }
end
end
describe 'permanent custom field still exists in cost query group by' do
subject { cost_query.reload.group_bys.collect(&:class).collect(&:name) }
it_behaves_like 'custom field exists' do
let(:name) { "CostQuery::GroupBy::#{custom_field_permanent_name}" }
end
end
end
context 'with custom field filter set' do
before do
cost_query.filter(custom_field_name, { operator: '=', values: [] })
end
it_behaves_like 'custom field is removed from cost query'
end
context 'with custom field group by set' do
before do
cost_query.group_by(custom_field_name)
end
it_behaves_like 'custom field is removed from cost query'
end
context 'session' do
let(:engine_name) { CostQuery.name.underscore.to_sym }
let(:key) { :"custom_field#{custom_field.id}" }
let(:query) { { filters:
{
operators: { user_id: "=", key => "=" },
values: { user_id: ["96"], key => "" }
},
groups: { rows: [key.to_s], columns: [key.to_s] }
}
}
before { session[engine_name] = query }
describe 'does not contain custom field reference' do
include_context 'remove custom field'
it { expect(session[engine_name][:filters][:operators][key]).to be_nil }
it { expect(session[engine_name][:filters][:values][key]).to be_nil }
it { expect(session[engine_name][:groups][:rows]).not_to include(key.to_s) }
it { expect(session[engine_name][:groups][:columns]).not_to include(key.to_s) }
end
end
end
end
Loading…
Cancel
Save