Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[#64515] check view_project_phases permission in filter

Tobias Dillmann3591a2bf7a37
diff --git a/app/models/queries/work_packages/filter/project_phase_filter.rb b/app/models/queries/work_packages/filter/project_phase_filter.rb
index 4330854a76d..082d7b1e8a4 100644
--- a/app/models/queries/work_packages/filter/project_phase_filter.rb
+++ b/app/models/queries/work_packages/filter/project_phase_filter.rb
@@ -97,12 +97,13 @@ class Queries::WorkPackages::Filter::ProjectPhaseFilter < Queries::WorkPackages:
private
- def project_phase_feature_flag_enabled?
- OpenProject::FeatureDecisions.stages_and_gates_active?
+ def project_phase_feature_available?
+ OpenProject::FeatureDecisions.stages_and_gates_active? &&
+ User.current.allowed_in_any_project?(:view_project_phases)
end
def project_phase_definitions
- return Project::PhaseDefinition.none unless project_phase_feature_flag_enabled?
+ return Project::PhaseDefinition.none unless project_phase_feature_available?
Project::PhaseDefinition.order(position: :asc)
end
diff --git a/spec/features/work_packages/table/project_phase_field_spec.rb b/spec/features/work_packages/table/project_phase_field_spec.rb
index d8a8964531d..c24c24a34a4 100644
--- a/spec/features/work_packages/table/project_phase_field_spec.rb
+++ b/spec/features/work_packages/table/project_phase_field_spec.rb
@@ -1,5 +1,33 @@
# frozen_string_literal: true
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 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"
RSpec.describe "Project phase field in the work package table", :js do
@@ -341,7 +369,7 @@ RSpec.describe "Project phase field in the work package table", :js do
end
end
- context "without the necessary permissions to view_phases" do
+ context "without the necessary permissions to view phases in some projects" do
let!(:query) { build(:global_query, user: current_user) }
let(:another_project_permissions) do
all_permissions - [:view_project_phases]
@@ -378,6 +406,10 @@ RSpec.describe "Project phase field in the work package table", :js do
end
describe "filtering" do
+ it "offers a phase filter" do
+ expect(query.available_filters.map(&:name)).to include(:project_phase_definition_id)
+ end
+
context "when filtering to include multiple phases" do
let(:query_filters) do
[{
@@ -413,6 +445,21 @@ RSpec.describe "Project phase field in the work package table", :js do
end
end
+ context "without the necessary permissions to view phases in all projects" do
+ let(:project_permissions) { all_permissions - [:view_project_phases] }
+ let(:query_columns) { %w(subject) }
+
+ it "does not offer a phase column" do
+ expect(query.available_columns.map(&:name)).not_to include(:project_phase)
+ end
+
+ describe "filtering" do
+ it "does not offer a phase filter" do
+ expect(query.available_filters.map(&:name)).not_to include(:project_phase_definition_id)
+ end
+ end
+ end
+
context "with the feature flag being inactive", with_flag: { stages_and_gates: false } do
let(:query_columns) { %w(subject) }
diff --git a/spec/models/queries/work_packages/filter/project_phase_filter_spec.rb b/spec/models/queries/work_packages/filter/project_phase_filter_spec.rb
index 064a3d8e2a3..50ab8e3870e 100644
--- a/spec/models/queries/work_packages/filter/project_phase_filter_spec.rb
+++ b/spec/models/queries/work_packages/filter/project_phase_filter_spec.rb
@@ -34,59 +34,107 @@ RSpec.describe Queries::WorkPackages::Filter::ProjectPhaseFilter do
it_behaves_like "basic query filter" do
let(:type) { :list }
let(:class_key) { :project_phase_definition_id }
+ current_user { build_stubbed(:user) }
context "with feature flag being active", with_flag: { stages_and_gates: true } do
- describe "#available?" do
- context "with existing phases" do
- before do
- create(:project_phase_definition)
+ context "with the permission to view project phases" do
+ before do
+ mock_permissions_for(current_user, &:allow_everything)
+ login_as(current_user)
+ end
+
+ describe "#available?" do
+ context "with existing phases" do
+ before do
+ create(:project_phase_definition)
+ end
+
+ it "is true" do
+ expect(instance).to be_available
+ end
end
- it "is true" do
- expect(instance).to be_available
+ context "without existing phases" do
+ it "is false" do
+ expect(instance).not_to be_available
+ end
end
end
- context "without existing phases" do
- it "is false" do
- expect(instance).not_to be_available
+ describe "#allowed_values" do
+ context "with existing phases" do
+ let!(:definition) { create(:project_phase_definition) }
+ let!(:other_definition) { create(:project_phase_definition) }
+ let!(:first_definition) { create(:project_phase_definition, position: 0) }
+
+ it "returns an array of phase definition options, ordered by position" do
+ expect(instance.allowed_values)
+ .to contain_exactly([first_definition.name, first_definition.id.to_s],
+ [definition.name, definition.id.to_s],
+ [other_definition.name, other_definition.id.to_s])
+ end
+ end
+
+ context "without existing phases" do
+ it "returns an empty array" do
+ expect(instance.allowed_values)
+ .to be_empty
+ end
end
end
- end
- describe "#allowed_values" do
- context "with existing phases" do
- let!(:definition) { create(:project_phase_definition) }
- let!(:other_definition) { create(:project_phase_definition) }
- let!(:first_definition) { create(:project_phase_definition, position: 0) }
+ describe "#value_objects" do
+ let(:definition1) { create(:project_phase_definition) }
+ let(:definition2) { create(:project_phase_definition) }
- it "returns an array of phase definition options, ordered by position" do
- expect(instance.allowed_values)
- .to contain_exactly([first_definition.name, first_definition.id.to_s],
- [definition.name, definition.id.to_s],
- [other_definition.name, other_definition.id.to_s])
+ before do
+ instance.values = [definition1.id.to_s, definition2.id.to_s]
end
- end
- context "without existing phases" do
- it "returns an empty array" do
- expect(instance.allowed_values)
- .to be_empty
+ it "returns an array of types" do
+ expect(instance.value_objects)
+ .to contain_exactly(definition1, definition2)
end
end
end
- describe "#value_objects" do
- let(:definition1) { create(:project_phase_definition) }
- let(:definition2) { create(:project_phase_definition) }
+ context "without the permission to view project phases" do
+ describe "#available?" do
+ context "with existing phases" do
+ before do
+ create(:project_phase_definition)
+ end
+
+ it "is false" do
+ expect(instance).not_to be_available
+ end
+ end
- before do
- instance.values = [definition1.id.to_s, definition2.id.to_s]
+ context "without existing phases" do
+ it "is false" do
+ expect(instance).not_to be_available
+ end
+ end
end
- it "returns an array of types" do
- expect(instance.value_objects)
- .to contain_exactly(definition1, definition2)
+ describe "#allowed_values" do
+ context "with existing phases" do
+ let!(:definition) { create(:project_phase_definition) }
+ let!(:other_definition) { create(:project_phase_definition) }
+ let!(:first_definition) { create(:project_phase_definition, position: 0) }
+
+ it "returns an empty array" do
+ expect(instance.allowed_values)
+ .to be_empty
+ end
+ end
+
+ context "without existing phases" do
+ it "returns an empty array" do
+ expect(instance.allowed_values)
+ .to be_empty
+ end
+ end
end
end
end