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

Refactor and add filtering to item_component.rb

Mir Bhatiaf67dcaa3883c
diff --git a/app/components/activities/item_component.rb b/app/components/activities/item_component.rb
index 1906dfdf3d5..384144cc114 100644
--- a/app/components/activities/item_component.rb
+++ b/app/components/activities/item_component.rb
@@ -41,7 +41,7 @@ class Activities::ItemComponent < ViewComponent::Base
end
def project_suffix
- return if project_activity?
+ return if activity?(Project)
return if activity_is_from_current_project?
kind = activity_is_from_subproject? ? 'subproject' : 'project'
@@ -60,42 +60,31 @@ class Activities::ItemComponent < ViewComponent::Base
end
def rendered_details
- @rendered_details ||=
- @event.journal
- .details
- .filter_map { |detail| @event.journal.render_detail(detail, activity_page: @activity_page) }
+ filter_details.filter_map { |detail| @event.journal.render_detail(detail, activity_page: @activity_page) }
end
def comment
- return unless work_package_activity?
+ return unless activity?(WorkPackage)
@event.event_description
end
def description
- return if work_package_activity?
+ return if activity?(WorkPackage) || activity?(TimeEntry)
@event.event_description
end
def time_entry_url
- return unless time_entry_activity?
+ return unless activity?(TimeEntry)
@event.event_url
end
private
- def work_package_activity?
- @event.journal.journable_type == 'WorkPackage'
- end
-
- def project_activity?
- @event.journal.journable_type == 'Project'
- end
-
- def time_entry_activity?
- @event.journal.journable_type == 'TimeEntry'
+ def activity?(type)
+ @event.journal.journable_type == type.to_s
end
def activity_is_from_current_project?
@@ -105,4 +94,20 @@ class Activities::ItemComponent < ViewComponent::Base
def activity_is_from_subproject?
@current_project && (@event.project != @current_project)
end
+
+ def filter_details
+ details = @event.journal.details
+
+ details.delete(:user_id) if details[:logged_by_id] == details[:user_id]
+ delete_detail(details, :work_package_id)
+ delete_detail(details, :comments)
+ delete_detail(details, :activity_id)
+ delete_detail(details, :spent_on)
+
+ details
+ end
+
+ def delete_detail(details, field)
+ details.delete(field) if details[field] && details[field].first.nil?
+ end
end
diff --git a/modules/costs/app/models/time_entry.rb b/modules/costs/app/models/time_entry.rb
index ef0b33b9016..47949bd9854 100644
--- a/modules/costs/app/models/time_entry.rb
+++ b/modules/costs/app/models/time_entry.rb
@@ -58,8 +58,11 @@ class TimeEntry < ApplicationRecord
before_save :update_costs
register_journal_formatted_fields(:time_entry_hours, 'hours')
- register_journal_formatted_fields(:named_association, 'work_package_id')
register_journal_formatted_fields(:time_entry_named_association, 'user_id')
+ register_journal_formatted_fields(:named_association, 'work_package_id')
+ register_journal_formatted_fields(:named_association, 'activity_id')
+ register_journal_formatted_fields(:plaintext, 'comments')
+ register_journal_formatted_fields(:plaintext, 'spent_on')
def self.update_all(updates, conditions = nil, options = {})
# instead of a update_all, perform an individual update during work_package#move