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

[36415] Add public filter to projects list (#9057)

Oliver Günther65575d44f182
diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb
index d7d1d0a1020..124b7078cfc 100644
--- a/app/helpers/projects_helper.rb
+++ b/app/helpers/projects_helper.rb
@@ -46,6 +46,7 @@ module ProjectsHelper
whitelist = [
Queries::Projects::Filters::ActiveFilter,
Queries::Projects::Filters::TemplatedFilter,
+ Queries::Projects::Filters::PublicFilter,
Queries::Projects::Filters::ProjectStatusFilter,
Queries::Projects::Filters::CreatedAtFilter,
Queries::Projects::Filters::LatestActivityAtFilter,
diff --git a/app/models/queries/projects.rb b/app/models/queries/projects.rb
index 002c6909d09..9a42f70d26e 100644
--- a/app/models/queries/projects.rb
+++ b/app/models/queries/projects.rb
@@ -38,6 +38,7 @@ module Queries::Projects
register.filter query, filters::TypeFilter
register.filter query, filters::ActiveFilter
register.filter query, filters::TemplatedFilter
+ register.filter query, filters::PublicFilter
register.filter query, filters::NameAndIdentifierFilter
register.filter query, filters::CustomFieldFilter
register.filter query, filters::CreatedAtFilter
diff --git a/app/models/queries/projects/filters/public_filter.rb b/app/models/queries/projects/filters/public_filter.rb
new file mode 100644
index 00000000000..2a2348f6efb
--- /dev/null
+++ b/app/models/queries/projects/filters/public_filter.rb
@@ -0,0 +1,37 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.
+#++
+
+class Queries::Projects::Filters::PublicFilter < Queries::Projects::Filters::ProjectFilter
+ include Queries::Filters::Shared::BooleanFilter
+
+ def self.key
+ :public
+ end
+end
diff --git a/spec/features/projects/projects_index_spec.rb b/spec/features/projects/projects_index_spec.rb
index 2f3f3ce4a63..d7eec938f09 100644
--- a/spec/features/projects/projects_index_spec.rb
+++ b/spec/features/projects/projects_index_spec.rb
@@ -35,18 +35,18 @@ describe 'Projects index page',
with_settings: { login_required?: false } do
shared_let(:admin) { FactoryBot.create :admin }
- let!(:manager) { FactoryBot.create :role, name: 'Manager' }
- let!(:developer) { FactoryBot.create :role, name: 'Developer' }
+ shared_let(:manager) { FactoryBot.create :role, name: 'Manager' }
+ shared_let(:developer) { FactoryBot.create :role, name: 'Developer' }
- let!(:custom_field) { FactoryBot.create :project_custom_field }
- let!(:invisible_custom_field) { FactoryBot.create :project_custom_field, visible: false }
+ shared_let(:custom_field) { FactoryBot.create :project_custom_field }
+ shared_let(:invisible_custom_field) { FactoryBot.create :project_custom_field, visible: false }
- let!(:project) do
+ shared_let(:project) do
FactoryBot.create(:project,
name: 'Plain project',
identifier: 'plain-project')
end
- let!(:public_project) do
+ shared_let(:public_project) do
project = FactoryBot.create(:project,
name: 'Public project',
identifier: 'public-project',
@@ -55,7 +55,7 @@ describe 'Projects index page',
project.save
project
end
- let!(:development_project) do
+ shared_let(:development_project) do
FactoryBot.create(:project,
name: 'Development project',
identifier: 'development-project')
@@ -104,7 +104,7 @@ describe 'Projects index page',
end
feature 'for project members' do
- let!(:user) do
+ shared_let(:user) do
FactoryBot.create(:user,
member_in_project: development_project,
member_through_role: developer,
@@ -340,12 +340,12 @@ describe 'Projects index page',
end
feature 'Active or archived' do
- let!(:parent_project) do
+ shared_let(:parent_project) do
FactoryBot.create(:project,
name: 'Parent project',
identifier: 'parent-project')
end
- let!(:child_project) do
+ shared_let(:child_project) do
FactoryBot.create(:project,
name: 'Child project',
identifier: 'child-project',
@@ -424,19 +424,19 @@ describe 'Projects index page',
end
feature 'project status filter' do
- let!(:no_status_project) do
+ shared_let(:no_status_project) do
# A project that never had project status associated.
FactoryBot.create(:project,
name: 'No status project')
end
- let!(:green_project) do
+ shared_let(:green_project) do
# A project that has a project status associated.
FactoryBot.create(:project,
name: 'Green project',
status: FactoryBot.create(:project_status))
end
- let!(:gray_project) do
+ shared_let(:gray_project) do
# A project that once had a project status associated, that was later unset.
FactoryBot.create(:project,
name: 'Gray project',
@@ -511,17 +511,17 @@ describe 'Projects index page',
end
feature 'other filter types' do
- let!(:list_custom_field) { FactoryBot.create :list_project_custom_field }
- let!(:date_custom_field) { FactoryBot.create :date_project_custom_field }
- let(:datetime_of_this_week) do
+ shared_let(:list_custom_field) { FactoryBot.create :list_project_custom_field }
+ shared_let(:date_custom_field) { FactoryBot.create :date_project_custom_field }
+ shared_let(:datetime_of_this_week) do
today = Date.today
# Ensure that the date is not today but still in the middle of the week to not run into week-start-issues here.
date_of_this_week = today + ((today.wday % 7) > 2 ? -1 : 1)
DateTime.parse(date_of_this_week.to_s + 'T11:11:11+00:00')
end
- let(:fixed_datetime) { DateTime.parse('2017-11-11T11:11:11+00:00') }
+ shared_let(:fixed_datetime) { DateTime.parse('2017-11-11T11:11:11+00:00') }
- let!(:project_created_on_today) do
+ shared_let(:project_created_on_today) do
project = FactoryBot.create(:project,
name: 'Created today project',
created_at: DateTime.now)
@@ -530,22 +530,22 @@ describe 'Projects index page',
project.save!
project
end
- let!(:project_created_on_this_week) do
+ shared_let(:project_created_on_this_week) do
FactoryBot.create(:project,
name: 'Created on this week project',
created_at: datetime_of_this_week)
end
- let!(:project_created_on_six_days_ago) do
+ shared_let(:project_created_on_six_days_ago) do
FactoryBot.create(:project,
name: 'Created on six days ago project',
created_at: DateTime.now - 6.days)
end
- let!(:project_created_on_fixed_date) do
+ shared_let(:project_created_on_fixed_date) do
FactoryBot.create(:project,
name: 'Created on fixed date project',
created_at: fixed_datetime)
end
- let!(:todays_wp) do
+ shared_let(:todays_wp) do
# This WP should trigger a change to the project's 'latest activity at' DateTime
FactoryBot.create(:work_package,
updated_at: DateTime.now,
@@ -732,28 +732,51 @@ describe 'Projects index page',
pending "NOT WORKING YET: Date vs. DateTime issue: Selecting same date for from and to value shows projects of that date"
end
+
+ feature 'public filter' do
+ scenario 'filter on "public" status' do
+ load_and_open_filters admin
+
+ expect(page).to have_text(project.name)
+ expect(page).to have_text(public_project.name)
+
+ SeleniumHubWaiter.wait
+ projects_page.filter_by_public('no')
+
+ expect(page).to have_text(project.name)
+ expect(page).to have_no_text(public_project.name)
+
+ load_and_open_filters admin
+
+ SeleniumHubWaiter.wait
+ projects_page.filter_by_public('yes')
+
+ expect(page).to have_text(public_project.name)
+ expect(page).to have_no_text(project.name)
+ end
+ end
end
feature 'Non-admins with role with permission' do
- let!(:can_copy_projects_role) do
+ shared_let(:can_copy_projects_role) do
FactoryBot.create :role, name: 'Can Copy Projects Role', permissions: [:copy_projects]
end
- let!(:can_add_subprojects_role) do
+ shared_let(:can_add_subprojects_role) do
FactoryBot.create :role, name: 'Can Add Subprojects Role', permissions: [:add_subprojects]
end
- let!(:parent_project) do
+ shared_let(:parent_project) do
FactoryBot.create(:project,
name: 'Parent project',
identifier: 'parent-project')
end
- let!(:can_copy_projects_manager) do
+ shared_let(:can_copy_projects_manager) do
FactoryBot.create(:user,
member_in_project: parent_project,
member_through_role: can_copy_projects_role)
end
- let!(:can_add_subprojects_manager) do
+ shared_let(:can_add_subprojects_manager) do
FactoryBot.create(:user,
member_in_project: parent_project,
member_through_role: can_add_subprojects_role)
@@ -842,20 +865,20 @@ describe 'Projects index page',
end
feature 'order' do
- let!(:integer_custom_field) { FactoryBot.create(:int_project_custom_field) }
+ shared_let(:integer_custom_field) { FactoryBot.create(:int_project_custom_field) }
# order is important here as the implementation uses lft
# first but then reorders in ruby
- let!(:child_project_z) do
+ shared_let(:child_project_z) do
FactoryBot.create(:project,
parent: project,
name: "Z Child")
end
- let!(:child_project_m) do
+ shared_let(:child_project_m) do
FactoryBot.create(:project,
parent: project,
name: "m Child") # intentionally written lowercase to test for case insensitive sorting
end
- let!(:child_project_a) do
+ shared_let(:child_project_a) do
FactoryBot.create(:project,
parent: project,
name: "A Child")
diff --git a/spec/models/queries/projects/filters/public_filter_spec.rb b/spec/models/queries/projects/filters/public_filter_spec.rb
new file mode 100644
index 00000000000..824d618cfe0
--- /dev/null
+++ b/spec/models/queries/projects/filters/public_filter_spec.rb
@@ -0,0 +1,38 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.
+#++
+
+require 'spec_helper'
+
+describe Queries::Projects::Filters::PublicFilter, type: :model do
+ it_behaves_like 'boolean query filter' do
+ let(:model) { Project }
+ let(:attribute) { :public }
+ end
+end
diff --git a/spec/support/pages/projects/index.rb b/spec/support/pages/projects/index.rb
index d2e136f7afb..32bb1ff12c4 100644
--- a/spec/support/pages/projects/index.rb
+++ b/spec/support/pages/projects/index.rb
@@ -49,23 +49,34 @@ module Pages
click_button 'Apply'
end
+ def filter_by_public(value)
+ set_filter('public',
+ 'Public',
+ 'is',
+ [value])
+
+ click_button 'Apply'
+ end
+
def set_filter(name, human_name, human_operator = nil, values = [])
select human_name, from: 'add_filter_select'
selected_filter = page.find("li[filter-name='#{name}']")
- within(selected_filter) do
- select(human_operator, from: 'operator') unless name == 'active'
+ select(human_operator, from: 'operator') unless boolean_filter?(name)
+ within(selected_filter) do
return unless values.any?
- case name
- when 'name_and_identifier'
+ case
+ when name == 'name_and_identifier'
set_name_and_identifier_filter(values)
- when 'active'
+ when boolean_filter?(name)
set_toggle_filter(values)
- when 'created_at'
+ when name == 'created_at'
+ select(human_operator, from: 'operator')
set_created_at_filter(human_operator, values)
- when /cf_\d+/
+ when name =~ /cf_\d+/
+ select(human_operator, from: 'operator')
set_custom_field_filter(selected_filter, human_operator, values)
end
end
@@ -134,6 +145,10 @@ module Pages
private
+ def boolean_filter?(filter)
+ %w[active public templated].include?(filter.to_s)
+ end
+
def within_row(project)
row = page.find('#project-table tr', text: project.name)