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
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.rbindex 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::BaseActivityProviderdef 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]))endquerydiff --git a/app/models/project.rb b/app/models/project.rbindex 61c3e1af24f..2b00fb259fe 100644--- a/app/models/project.rb+++ b/app/models/project.rb@@ -29,11 +29,11 @@class Project < ApplicationRecordextend FriendlyId- include Projects::Storageinclude Projects::Activity- include Projects::Hierarchyinclude Projects::AncestorsFromRootinclude Projects::CustomFields+ include Projects::Hierarchy+ include Projects::Storageinclude Projects::WorkPackageCustomFieldsinclude ::Scopes::Scoped@@ -202,25 +202,6 @@ class Project < ApplicationRecordProject.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.rbindex 4cccfbeb091..aaa262bc0f3 100644--- a/app/models/projects/hierarchy.rb+++ b/app/models/projects/hierarchy.rb@@ -114,6 +114,10 @@ module Projects::Hierarchyparents | descendants # Set unionend+ def has_subprojects?+ !leaf?+ end+# Returns an array of active subprojects.def active_subprojectsproject.descendants.where(active: true)@@ -150,5 +154,20 @@ module Projects::Hierarchydef 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+ endendend