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

Show correct number in attachments tab

Henriette Darge3205338db0f0
diff --git a/app/models/relation.rb b/app/models/relation.rb
index 5906c3c01a1..f57f195fb1f 100644
--- a/app/models/relation.rb
+++ b/app/models/relation.rb
@@ -103,14 +103,6 @@ class Relation < ApplicationRecord
scope :follows_with_lag,
-> { follows.where("lag > 0") }
- scope :visible_involved,
- ->(work_package) do
- visible_sql = WorkPackage.visible(User.current).select(:id).to_sql
- where("(from_id IN (?) AND to_id IN (#{visible_sql})) OR (to_id IN (?) AND from_id IN (#{visible_sql}))",
- work_package,
- work_package)
- end
-
validates :lag, numericality: { allow_nil: true }
validates :to, uniqueness: { scope: :from }
diff --git a/config/initializers/menus.rb b/config/initializers/menus.rb
index 28fa3edaa69..8800c3d6a77 100644
--- a/config/initializers/menus.rb
+++ b/config/initializers/menus.rb
@@ -655,16 +655,18 @@ Redmine::MenuManager.map :work_package_split_view do |menu|
{ tab: :files },
skip_permissions_check: true,
badge: ->(work_package:, **) {
- Attachment.where(container_type: "WorkPackage",
- container_id: work_package)
- .count
+ count = Storages::FileLink.where(container_type: "WorkPackage", container_id: work_package).count
+ unless work_package.hide_attachments?
+ count += work_package.attachments.count
+ end
+ count
},
caption: :"js.work_packages.tabs.files"
menu.push :relations,
{ tab: :relations },
skip_permissions_check: true,
badge: ->(work_package:, **) {
- Relation.visible_involved(work_package).count + WorkPackage.where(parent_id: work_package).count
+ work_package.relations.count + work_package.children.count
},
caption: :"js.work_packages.tabs.relations"
menu.push :watchers,
diff --git a/spec/models/queries/relations/filters/involved_filter_spec.rb b/spec/models/queries/relations/filters/involved_filter_spec.rb
index e39735f0053..e76b51d7d71 100644
--- a/spec/models/queries/relations/filters/involved_filter_spec.rb
+++ b/spec/models/queries/relations/filters/involved_filter_spec.rb
@@ -67,12 +67,6 @@ RSpec.describe Queries::Relations::Filters::InvolvedFilter do
expect(instance.apply_to(model).to_sql).to eql expected.to_sql
end
-
- it "is the same as the visible_involved scope" do
- expected = Relation.visible_involved("1")
-
- expect(instance.apply_to(model).to_sql).to eql expected.to_sql
- end
end
context 'for "!"' do