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

Add a new query instead of changing the existing one

Klaus Zanders45d49229b507
diff --git a/app/models/principal.rb b/app/models/principal.rb
index b9c41ff679b..6bddf057d8f 100644
--- a/app/models/principal.rb
+++ b/app/models/principal.rb
@@ -80,10 +80,18 @@ class Principal < ApplicationRecord
:status
scope :in_project, ->(project) {
- where(id: Member.of_anything_in_project(project).select(:user_id))
+ where(id: Member.of_project(project).select(:user_id))
}
scope :not_in_project, ->(project) {
+ where.not(id: Member.of_project(project).select(:user_id))
+ }
+
+ scope :in_anything_in_project, ->(project) {
+ where(id: Member.of_anything_in_project(project).select(:user_id))
+ }
+
+ scope :not_in_anything_in_project, ->(project) {
where.not(id: Member.of_anything_in_project(project).select(:user_id))
}
diff --git a/app/models/queries/principals.rb b/app/models/queries/principals.rb
index 4d119fa0fde..f29be25c54a 100644
--- a/app/models/queries/principals.rb
+++ b/app/models/queries/principals.rb
@@ -28,6 +28,7 @@
module Queries::Principals
::Queries::Register.register(PrincipalQuery) do
+ filter Filters::AccessToAnythingInProjectFilter
filter Filters::TypeFilter
filter Filters::MemberFilter
filter Filters::MentionableOnWorkPackageFilter
diff --git a/app/models/queries/principals/filters/access_to_anything_in_project_filter.rb b/app/models/queries/principals/filters/access_to_anything_in_project_filter.rb
new file mode 100644
index 00000000000..bce23d6b0c4
--- /dev/null
+++ b/app/models/queries/principals/filters/access_to_anything_in_project_filter.rb
@@ -0,0 +1,66 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 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.
+#++
+
+class Queries::Principals::Filters::AccessToAnythingInProjectFilter < Queries::Principals::Filters::PrincipalFilter
+ def allowed_values
+ Project.active.pluck(:name, :id)
+ end
+
+ def type
+ :list_optional
+ end
+
+ def self.key
+ :access_to_anything_in_project
+ end
+
+ def scope
+ case operator
+ when '='
+ visible_scope.in_anything_in_project(values)
+ when '!'
+ visible_scope.not_in_anything_in_project(values)
+ when '*'
+ member_included_scope.where.not(members: { id: nil })
+ when '!*'
+ member_included_scope.where.not(id: Member.distinct(:user_id).select(:user_id))
+ end
+ end
+
+ private
+
+ def visible_scope
+ Principal.visible(User.current)
+ end
+
+ def member_included_scope
+ visible_scope
+ .includes(:members)
+ .merge(Member.of_any_project)
+ end
+end
diff --git a/lib/api/v3/queries/schemas/access_to_project_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/access_to_project_filter_dependency_representer.rb
new file mode 100644
index 00000000000..005ea5009ac
--- /dev/null
+++ b/lib/api/v3/queries/schemas/access_to_project_filter_dependency_representer.rb
@@ -0,0 +1,61 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 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
+ module V3
+ module Queries
+ module Schemas
+ class AccessToProjectFilterDependencyRepresenter <
+ PrincipalFilterDependencyRepresenter
+ def json_cache_key
+ if filter.project
+ super + [filter.project.id]
+ else
+ super
+ end
+ end
+
+ private
+
+ def filter_query
+ params = [{ status: { operator: '!',
+ values: [Principal.statuses[:locked].to_s] } }]
+
+ params << if filter.project
+ { access_to_anything_in_project: { operator: '=', values: [filter.project.id.to_s] } }
+ else
+ { access_to_anything_in_project: { operator: '*', values: [] } }
+ end
+
+ params
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/api/v3/queries/schemas/filter_dependency_representer_factory.rb b/lib/api/v3/queries/schemas/filter_dependency_representer_factory.rb
index 6d1916165a0..c1e45d2e277 100644
--- a/lib/api/v3/queries/schemas/filter_dependency_representer_factory.rb
+++ b/lib/api/v3/queries/schemas/filter_dependency_representer_factory.rb
@@ -56,8 +56,8 @@ module API
UpdatedAtFilter: 'DateTimeFilter',
AuthorFilter: 'UserFilter',
ResponsibleFilter: 'AllPrincipalsFilter',
- AssignedToFilter: 'AllPrincipalsFilter',
- SharedWithUserFilter: 'AllPrincipalsFilter',
+ AssignedToFilter: 'AccessToProjectFilter',
+ SharedWithUserFilter: 'AccessToProjectFilter',
WatcherFilter: 'UserFilter'
}