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

Move more hierarchy related methods to Projects::Hierarchy

Dombi Attila03ef711d5f57
diff --git a/app/models/activities/base_activity_provider.rb b/app/models/activities/base_activity_provider.rb
index ff537b9dcc9..9c7e90fac57 100644
--- a/app/models/activities/base_activity_provider.rb
+++ b/app/models/activities/base_activity_provider.rb
@@ -219,7 +219,7 @@ class Activities::BaseActivityProvider
def restrict_projects_by_selection(options, query)
if (project = options[:project])
- query = query.where(project.project_condition(options[:with_subprojects]))
+ query = query.where(project.with_subprojects(options[:with_subprojects]))
end
query
diff --git a/app/models/project.rb b/app/models/project.rb
index 61c3e1af24f..2b00fb259fe 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -29,11 +29,11 @@
class Project < ApplicationRecord
extend FriendlyId
- include Projects::Storage
include Projects::Activity
- include Projects::Hierarchy
include Projects::AncestorsFromRoot
include Projects::CustomFields
+ include Projects::Hierarchy
+ include Projects::Storage
include Projects::WorkPackageCustomFields
include ::Scopes::Scoped
@@ -202,25 +202,6 @@ class Project < ApplicationRecord
Project.visible.select { |p| User.current.member_of? p }.sort_by(&:to_s)
end
- # Returns a :conditions SQL string that can be used to find the issues associated with this project.
- #
- # Examples:
- # project.project_condition(true) => "(projects.id = 1 OR (projects.lft > 1 AND projects.rgt < 10))"
- # project.project_condition(false) => "projects.id = 1"
- def project_condition(with_subprojects)
- projects_table = Project.arel_table
-
- stmt = projects_table[:id].eq(id)
- if with_subprojects && has_subprojects?
- stmt = stmt.or(projects_table[:lft].gt(lft).and(projects_table[:rgt].lt(rgt)))
- end
- stmt
- end
-
- def has_subprojects?
- !leaf?
- end
-
def types_used_by_work_packages
::Type.where(id: WorkPackage.where(project_id: project.id)
.select(:type_id)
diff --git a/app/models/projects/hierarchy.rb b/app/models/projects/hierarchy.rb
index 4cccfbeb091..aaa262bc0f3 100644
--- a/app/models/projects/hierarchy.rb
+++ b/app/models/projects/hierarchy.rb
@@ -114,6 +114,10 @@ module Projects::Hierarchy
parents | descendants # Set union
end
+ def has_subprojects?
+ !leaf?
+ end
+
# Returns an array of active subprojects.
def active_subprojects
project.descendants.where(active: true)
@@ -150,5 +154,20 @@ module Projects::Hierarchy
def remember_reorder
@reorder_nested_set = new_record? || name_changed?
end
+
+ # Returns a :conditions SQL string that can be used to find the issues associated with this project.
+ #
+ # Examples:
+ # project.with_subprojects(true) => "(projects.id = 1 OR (projects.lft > 1 AND projects.rgt < 10))"
+ # project.with_subprojects(false) => "projects.id = 1"
+ def with_subprojects(with_subprojects)
+ projects_table = Project.arel_table
+
+ stmt = projects_table[:id].eq(id)
+ if with_subprojects && has_subprojects?
+ stmt = stmt.or(projects_table[:lft].gt(lft).and(projects_table[:rgt].lt(rgt)))
+ end
+ stmt
+ end
end
end