Merge pull request #10368 from opf/feature/include-subprojects-attribute
[41135] Add new query attribute include_subprojectspull/10426/head
commit
241a7ea981
@ -0,0 +1,42 @@ |
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2022 the OpenProject GmbH |
||||
# |
||||
# 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 COPYRIGHT and LICENSE files for more details. |
||||
#++ |
||||
|
||||
module API |
||||
class ParserStruct < ::Hashie::Mash |
||||
## |
||||
# TODO: Hashie::Mash extends from Hash and |
||||
# does not allow overriding any enumerable methods. |
||||
# |
||||
# This clashed with moving the queries services to BaseContracted, |
||||
# as we now use a +group_by+ attribute clashing with +Enumerable#group_by#. |
||||
# This redefines the method to ensure it works with queries, but does not solve the underlying issue. |
||||
def group_by |
||||
self[:group_by] |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,14 @@ |
||||
class AddIncludeSubprojectsToQuery < ActiveRecord::Migration[6.1] |
||||
def change |
||||
add_column :queries, |
||||
:include_subprojects, |
||||
:boolean, |
||||
null: false, |
||||
default: Setting.display_subprojects_work_packages? |
||||
|
||||
# Remove the default now |
||||
reversible do |dir| |
||||
dir.up { change_column_default :queries, :include_subprojects, nil } |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,62 @@ |
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2022 the OpenProject GmbH |
||||
# |
||||
# 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 COPYRIGHT and LICENSE files for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
require 'contracts/shared/model_contract_shared_context' |
||||
require_relative 'shared_contract_examples' |
||||
|
||||
describe Queries::CreateContract do |
||||
include_context 'ModelContract shared context' |
||||
include_context 'with queries contract' |
||||
|
||||
describe 'include subprojects' do |
||||
let(:query) do |
||||
Query.new name: 'foo', |
||||
include_subprojects: include_subprojects, |
||||
project: project |
||||
end |
||||
|
||||
context 'when true' do |
||||
let(:include_subprojects) { true } |
||||
|
||||
it_behaves_like 'contract is valid' |
||||
end |
||||
|
||||
context 'when falsea' do |
||||
let(:include_subprojects) { false } |
||||
|
||||
it_behaves_like 'contract is valid' |
||||
end |
||||
|
||||
context 'when nil' do |
||||
let(:include_subprojects) { nil } |
||||
|
||||
it_behaves_like 'contract is invalid', include_subprojects: %i[inclusion] |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,52 @@ |
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2022 the OpenProject GmbH |
||||
# |
||||
# 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 COPYRIGHT and LICENSE files for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
require 'contracts/shared/model_contract_shared_context' |
||||
|
||||
shared_context 'with queries contract' do |
||||
let(:project) { build_stubbed :project } |
||||
let(:query) do |
||||
build_stubbed(:query, project: project, public: public, user: user) |
||||
end |
||||
|
||||
let(:current_user) do |
||||
build_stubbed(:user) do |user| |
||||
allow(user) |
||||
.to receive(:allowed_to?) do |permission, permission_project| |
||||
permissions.include?(permission) && project == permission_project |
||||
end |
||||
end |
||||
end |
||||
let(:contract) { described_class.new(query, current_user) } |
||||
|
||||
before do |
||||
# Assume project is always visible |
||||
allow(contract).to receive(:project_visible?).and_return true |
||||
end |
||||
end |
@ -0,0 +1,150 @@ |
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2022 the OpenProject GmbH |
||||
# |
||||
# 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 COPYRIGHT and LICENSE files for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe ::Query::Results, 'Project filter integration', type: :model, with_mail: false do |
||||
let(:query) do |
||||
build(:query, |
||||
user: user, |
||||
project: parent_project).tap do |q| |
||||
q.filters.clear |
||||
end |
||||
end |
||||
let(:query_results) do |
||||
described_class.new query |
||||
end |
||||
|
||||
shared_let(:parent_project) { create :project } |
||||
shared_let(:child_project) { create :project, parent: parent_project } |
||||
|
||||
shared_let(:second_parent_project) { create :project } |
||||
shared_let(:second_child_project) { create :project, parent: second_parent_project } |
||||
|
||||
shared_let(:user) do |
||||
create(:user, |
||||
firstname: 'user', |
||||
lastname: '1', |
||||
member_in_projects: [parent_project, child_project, second_parent_project, second_child_project], |
||||
member_with_permissions: [:view_work_packages]) |
||||
end |
||||
|
||||
shared_let(:parent_wp) { create :work_package, project: parent_project } |
||||
shared_let(:child_wp) { create :work_package, project: child_project } |
||||
|
||||
shared_let(:second_parent_wp) { create :work_package, project: second_parent_project } |
||||
shared_let(:second_child_wp) { create :work_package, project: second_child_project } |
||||
|
||||
before do |
||||
login_as user |
||||
end |
||||
|
||||
describe 'both parent projects selected' do |
||||
before do |
||||
query.add_filter 'project_id', '=', [parent_project.id, second_parent_project.id] |
||||
end |
||||
|
||||
context 'when subprojects included', with_settings: { display_subprojects_work_packages: true } do |
||||
it 'shows the sub work packages' do |
||||
expect(query_results.work_packages).to match_array [parent_wp, child_wp, second_parent_wp, second_child_wp] |
||||
end |
||||
end |
||||
|
||||
context 'when subprojects not included', with_settings: { display_subprojects_work_packages: false } do |
||||
it 'does not show the sub work packages' do |
||||
expect(query_results.work_packages).to match_array [parent_wp, second_parent_wp] |
||||
end |
||||
end |
||||
|
||||
context 'when subprojects explicitly disabled' do |
||||
before do |
||||
query.include_subprojects = false |
||||
end |
||||
|
||||
it 'does not show the sub work packages' do |
||||
expect(query_results.work_packages).to match_array [parent_wp, second_parent_wp] |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe 'one parent projects selected' do |
||||
before do |
||||
query.add_filter 'project_id', '=', [second_parent_project.id] |
||||
end |
||||
|
||||
context 'when subprojects included', with_settings: { display_subprojects_work_packages: true } do |
||||
it 'shows the sub work packages' do |
||||
expect(query_results.work_packages).to match_array [second_parent_wp, second_child_wp] |
||||
end |
||||
end |
||||
|
||||
context 'when subprojects not included', with_settings: { display_subprojects_work_packages: false } do |
||||
it 'does not show the sub work packages' do |
||||
expect(query_results.work_packages).to match_array [second_parent_wp] |
||||
end |
||||
end |
||||
|
||||
context 'when subprojects explicitly disabled' do |
||||
before do |
||||
query.include_subprojects = false |
||||
end |
||||
|
||||
it 'does not show the sub work packages' do |
||||
expect(query_results.work_packages).to match_array [second_parent_wp] |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe 'one parent and one other child selected' do |
||||
before do |
||||
query.add_filter 'project_id', '=', [child_project.id, second_parent_project.id] |
||||
end |
||||
|
||||
context 'when subprojects included', with_settings: { display_subprojects_work_packages: true } do |
||||
it 'shows the sub work packages' do |
||||
expect(query_results.work_packages).to match_array [child_wp, second_parent_wp, second_child_wp] |
||||
end |
||||
end |
||||
|
||||
context 'when subprojects not included', with_settings: { display_subprojects_work_packages: false } do |
||||
it 'does not show the sub work packages' do |
||||
expect(query_results.work_packages).to match_array [child_wp, second_parent_wp] |
||||
end |
||||
end |
||||
|
||||
context 'when subprojects explicitly disabled' do |
||||
before do |
||||
query.include_subprojects = false |
||||
end |
||||
|
||||
it 'does not show the sub work packages' do |
||||
expect(query_results.work_packages).to match_array [child_wp, second_parent_wp] |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue