diff --git a/app/helpers/global_activities_helper.rb b/app/helpers/global_activities_helper.rb index b88e632ab..fa98ad583 100644 --- a/app/helpers/global_activities_helper.rb +++ b/app/helpers/global_activities_helper.rb @@ -5,30 +5,25 @@ module GlobalActivitiesHelper include ActionView::Helpers::UrlHelper include InputSanitizeHelper - def generate_activity_content(activity) + def generate_activity_content(activity, no_links = false) parameters = {} activity.values[:message_items].each do |key, value| parameters[key] = if value.is_a? String value else - generate_link(value, activity) + no_links ? generate_name(value) : generate_link(value, activity) end end - I18n.t("global_activities.content.#{activity.type_of}_html", - parameters.symbolize_keys) + sanitize_input(I18n.t("global_activities.content.#{activity.type_of}_html", + parameters.symbolize_keys)) end def generate_link(message_item, activity) - type = message_item[:type] - id = message_item[:id] - getter = message_item[:getter] - value = message_item[:value] + obj = message_item[:type].constantize.find_by_id(message_item[:id]) + return message_item[:value] unless obj - obj = type.constantize.find_by_id id - return value unless obj - - current_value = obj.public_send(getter || 'name') + current_value = generate_name(message_item) team = activity.team path = '' @@ -70,4 +65,10 @@ module GlobalActivitiesHelper end route_to_other_team(path, obj, current_value) end + + def generate_name(message_item) + obj = message_item[:type].constantize.find_by_id(message_item[:id]) + return message_item[:value] unless obj + obj.public_send(message_item[:getter] || 'name') + end end diff --git a/app/models/activity.rb b/app/models/activity.rb index 07c4389d8..b0d38f775 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -90,6 +90,6 @@ class Activity < ApplicationRecord end def activity_version - errors.add(:activity, 'wrong combination of associations') if (experiment || my_module) && subject + errors.add(:activity, 'wrong combination of associations') if (experiment_id || my_module_id) && subject end end diff --git a/app/services/activities_service.rb b/app/services/activities_service.rb index 3d6534ad0..f496594ba 100644 --- a/app/services/activities_service.rb +++ b/app/services/activities_service.rb @@ -76,4 +76,13 @@ class ActivitiesService subjects.each { |_sub, children| children.uniq! } end + + def self.my_module_activities(my_module) + subjects_with_children = load_subjects_children(MyModule: [my_module.id]) + query = Activity.where(project: my_module.experiment.project) + query.where( + subjects_with_children.map { '(subject_type = ? AND subject_id IN(?))' }.join(' OR '), + *subjects_with_children.flatten + ) + end end diff --git a/app/views/my_modules/repository.html.erb b/app/views/my_modules/repository.html.erb index 904f0491d..1c8c1e75e 100644 --- a/app/views/my_modules/repository.html.erb +++ b/app/views/my_modules/repository.html.erb @@ -5,7 +5,7 @@ <% provide(:head_title, t("my_modules.repository.head_title", project: h(@project.name), module: h(@my_module.name), - repository: @repository.name).html_safe) %> + repository: h(@repository.name)).html_safe) %> <%= render partial: "shared/sidebar", locals: { current_task: @my_module, page: 'task' } %> <%= render partial: "shared/secondary_navigation" %> diff --git a/app/views/reports/elements/_my_module_activity_element.html.erb b/app/views/reports/elements/_my_module_activity_element.html.erb index 22192e36c..25b845d03 100644 --- a/app/views/reports/elements/_my_module_activity_element.html.erb +++ b/app/views/reports/elements/_my_module_activity_element.html.erb @@ -1,7 +1,7 @@ <% if my_module.blank? and @my_module.present? then my_module = @my_module end %> <% if order.blank? and @order.present? then order = @order end %> <% timestamp = Time.current + 1.year - 2.days %> -<% activities = my_module.activities.order(created_at: order) %> +<% activities = ActivitiesService.my_module_activities(my_module).order(created_at: order) %>