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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[36415] Add public filter to projects list (#9057)
Oliver Günther65575d44f182
diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rbindex d7d1d0a1020..124b7078cfc 100644--- a/app/helpers/projects_helper.rb+++ b/app/helpers/projects_helper.rb@@ -46,6 +46,7 @@ module ProjectsHelperwhitelist = [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.rbindex 002c6909d09..9a42f70d26e 100644--- a/app/models/queries/projects.rb+++ b/app/models/queries/projects.rb@@ -38,6 +38,7 @@ module Queries::Projectsregister.filter query, filters::TypeFilterregister.filter query, filters::ActiveFilterregister.filter query, filters::TemplatedFilter+ register.filter query, filters::PublicFilterregister.filter query, filters::NameAndIdentifierFilterregister.filter query, filters::CustomFieldFilterregister.filter query, filters::CreatedAtFilterdiff --git a/app/models/queries/projects/filters/public_filter.rb b/app/models/queries/projects/filters/public_filter.rbnew file mode 100644index 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+enddiff --git a/spec/features/projects/projects_index_spec.rb b/spec/features/projects/projects_index_spec.rbindex 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 } doshared_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) doFactoryBot.create(:project,name: 'Plain project',identifier: 'plain-project')end- let!(:public_project) do+ shared_let(:public_project) doproject = FactoryBot.create(:project,name: 'Public project',identifier: 'public-project',@@ -55,7 +55,7 @@ describe 'Projects index page',project.saveprojectend- let!(:development_project) do+ shared_let(:development_project) doFactoryBot.create(:project,name: 'Development project',identifier: 'development-project')@@ -104,7 +104,7 @@ describe 'Projects index page',endfeature 'for project members' do- let!(:user) do+ shared_let(:user) doFactoryBot.create(:user,member_in_project: development_project,member_through_role: developer,@@ -340,12 +340,12 @@ describe 'Projects index page',endfeature 'Active or archived' do- let!(:parent_project) do+ shared_let(:parent_project) doFactoryBot.create(:project,name: 'Parent project',identifier: 'parent-project')end- let!(:child_project) do+ shared_let(:child_project) doFactoryBot.create(:project,name: 'Child project',identifier: 'child-project',@@ -424,19 +424,19 @@ describe 'Projects index page',endfeature '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',endfeature '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) dotoday = 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) doproject = FactoryBot.create(:project,name: 'Created today project',created_at: DateTime.now)@@ -530,22 +530,22 @@ describe 'Projects index page',project.save!projectend- let!(:project_created_on_this_week) do+ shared_let(:project_created_on_this_week) doFactoryBot.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) doFactoryBot.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) doFactoryBot.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' DateTimeFactoryBot.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+ endendfeature 'Non-admins with role with permission' do- let!(:can_copy_projects_role) do+ shared_let(:can_copy_projects_role) doFactoryBot.create :role, name: 'Can Copy Projects Role', permissions: [:copy_projects]end- let!(:can_add_subprojects_role) do+ shared_let(:can_add_subprojects_role) doFactoryBot.create :role, name: 'Can Add Subprojects Role', permissions: [:add_subprojects]end- let!(:parent_project) do+ shared_let(:parent_project) doFactoryBot.create(:project,name: 'Parent project',identifier: 'parent-project')end- let!(:can_copy_projects_manager) do+ shared_let(:can_copy_projects_manager) doFactoryBot.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) doFactoryBot.create(:user,member_in_project: parent_project,member_through_role: can_add_subprojects_role)@@ -842,20 +865,20 @@ describe 'Projects index page',endfeature '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) doFactoryBot.create(:project,parent: project,name: "Z Child")end- let!(:child_project_m) do+ shared_let(:child_project_m) doFactoryBot.create(:project,parent: project,name: "m Child") # intentionally written lowercase to test for case insensitive sortingend- let!(:child_project_a) do+ shared_let(:child_project_a) doFactoryBot.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.rbnew file mode 100644index 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+enddiff --git a/spec/support/pages/projects/index.rb b/spec/support/pages/projects/index.rbindex d2e136f7afb..32bb1ff12c4 100644--- a/spec/support/pages/projects/index.rb+++ b/spec/support/pages/projects/index.rb@@ -49,23 +49,34 @@ module Pagesclick_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) doreturn 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)endend@@ -134,6 +145,10 @@ module Pagesprivate+ 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)