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
change the filtering on the visible time entries to be done in the join
ulfertsfeb3a40a0cea
diff --git a/app/models/work_packages/scopes/include_spent_time.rb b/app/models/work_packages/scopes/include_spent_time.rbindex 4aa24c1183c..50ae482b8ec 100644--- a/app/models/work_packages/scopes/include_spent_time.rb+++ b/app/models/work_packages/scopes/include_spent_time.rb@@ -31,12 +31,11 @@ module WorkPackages::Scopes::IncludeSpentTimeclass_methods dodef include_spent_time(user, work_package = nil)- query = join_time_entries(user)-- scope = left_join_self_and_descendants(user, work_package)- .joins(query.join_sources)+ scope = with(visible_time_entries_cte.name => allowed_to_view_time_entries(user))+ .left_join_self_and_descendants(user, work_package)+ .joins(join_visible_time_entries.join_sources).group(:id)- .select("SUM(time_entries.hours) AS hours")+ .select("SUM(#{visible_time_entries_cte.name}.hours) AS hours")if work_packagescope.where(id: work_package.id)@@ -47,18 +46,14 @@ module WorkPackages::Scopes::IncludeSpentTimeprotected- def join_time_entries(user)- join_condition = time_entries_table[:work_package_id]- .eq(wp_descendants[:id])- .and(allowed_to_view_time_entries(user))-+ def join_visible_time_entrieswp_table- .outer_join(time_entries_table)- .on(join_condition)+ .outer_join(visible_time_entries_cte)+ .on(visible_time_entries_cte[:work_package_id].eq(wp_descendants[:id]))enddef allowed_to_view_time_entries(user)- time_entries_table[:id].in(TimeEntry.not_ongoing.visible(user).select(:id).arel)+ TimeEntry.not_ongoing.visible(user).select(:id, :work_package_id, :hours).arelenddef wp_table@@ -71,8 +66,8 @@ module WorkPackages::Scopes::IncludeSpentTime@wp_descendants ||= wp_table.alias("descendants")end- def time_entries_table- @time_entries_table ||= TimeEntry.arel_table+ def visible_time_entries_cte+ @visible_time_entries_cte ||= Arel::Table.new("visible_time_entries")endendend