-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16078 from opf/implementation/55962-add-the-proje…
…ct-list-view-including-the-project-folder-custom-column [#55962] Add the project list view, including the "project folder" custom column
- Loading branch information
Showing
12 changed files
with
351 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# -- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) 2010-2024 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 Projects::Scopes | ||
module ActivatedInStorage | ||
extend ActiveSupport::Concern | ||
|
||
class_methods do | ||
def activated_in_storage(storage_ids) | ||
subquery = project_storages_subquery(storage_ids:) | ||
where(id: subquery) | ||
end | ||
|
||
def not_activated_in_storage(storage_ids) | ||
subquery = project_storages_subquery(storage_ids:) | ||
where.not(id: subquery) | ||
end | ||
|
||
private | ||
|
||
def project_storages_subquery(storage_ids:) | ||
Storages::ProjectStorage | ||
.select(:project_id) | ||
.where(storage_id: storage_ids) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
modules/storages/app/models/queries/storages/projects/filter/storages_filter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# frozen_string_literal: true | ||
|
||
# -- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) 2024 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. | ||
# ++ | ||
# | ||
|
||
# This filter is used to find projects (including archived projects) that use one | ||
# of the given storages ids. | ||
module Queries::Storages::Projects::Filter | ||
class StoragesFilter < ::Queries::Projects::Filters::ProjectFilter | ||
def self.key | ||
:storages | ||
end | ||
|
||
def type | ||
:list | ||
end | ||
|
||
def allowed_values | ||
@allowed_values ||= Storages::Storage | ||
.pluck(:name, :id) | ||
end | ||
|
||
def available? | ||
User.current.admin? | ||
end | ||
|
||
def apply_to(_query_scope) | ||
case operator | ||
when "=" | ||
super.activated_in_storage(values) | ||
when "!" | ||
super.not_activated_in_storage(values) | ||
else | ||
raise "unsupported operator" | ||
end | ||
end | ||
|
||
def where | ||
nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
modules/storages/spec/models/queries/storages/projects/filter/storages_filter_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#-- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) 2012-2024 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 Queries::Storages::Projects::Filter::StoragesFilter do | ||
it_behaves_like "basic query filter" do | ||
let(:class_key) { :storages } | ||
let(:type) { :list } | ||
end | ||
|
||
it_behaves_like "list query filter", scope: false do | ||
shared_let(:project) { create(:project) } | ||
shared_let(:storage1) { create(:storage, :as_generic) } | ||
shared_let(:storage2) { create(:storage, :as_generic) } | ||
|
||
let(:valid_values) do | ||
[storage1.id, storage2.id] | ||
end | ||
let(:name) { "Available project attributes" } | ||
|
||
describe "#apply_to" do | ||
let(:values) { valid_values } | ||
|
||
let(:project_ids_from_project_storages_handwritten_sql) do | ||
<<-SQL.squish | ||
SELECT "project_storages"."project_id" | ||
FROM "project_storages" | ||
WHERE "project_storages"."storage_id" | ||
IN (#{values.join(', ')}) | ||
SQL | ||
end | ||
|
||
context 'for "="' do | ||
let(:operator) { "=" } | ||
|
||
it "is the same as handwriting the query" do | ||
handwritten_scope_sql = <<-SQL.squish | ||
SELECT "projects".* FROM "projects" | ||
WHERE "projects"."id" IN (#{project_ids_from_project_storages_handwritten_sql}) | ||
SQL | ||
|
||
expect(instance.apply_to(Project).to_sql).to eql handwritten_scope_sql | ||
end | ||
end | ||
|
||
context 'for "!"' do | ||
let(:operator) { "!" } | ||
|
||
it "is the same as handwriting the query" do | ||
handwritten_scope_sql = <<-SQL.squish | ||
SELECT "projects".* FROM "projects" | ||
WHERE "projects"."id" NOT IN (#{project_ids_from_project_storages_handwritten_sql}) | ||
SQL | ||
|
||
expect(instance.apply_to(Project).to_sql).to eql handwritten_scope_sql | ||
end | ||
end | ||
|
||
context "for an unsupported operator" do | ||
let(:operator) { "!=" } | ||
|
||
it "raises an error" do | ||
expect { instance.apply_to(Project) }.to raise_error("unsupported operator") | ||
end | ||
end | ||
end | ||
|
||
describe "#allowed_values" do | ||
it "is a list of the possible values" do | ||
expected = [ | ||
[storage1.name, storage1.id], | ||
[storage2.name, storage2.id] | ||
] | ||
|
||
expect(instance.allowed_values).to match_array(expected) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.