diff --git a/app/helpers/global_activities_helper.rb b/app/helpers/global_activities_helper.rb
index fa98ad583..8512caefa 100644
--- a/app/helpers/global_activities_helper.rb
+++ b/app/helpers/global_activities_helper.rb
@@ -45,9 +45,11 @@ module GlobalActivitiesHelper
path = obj.archived? ? projects_path : project_path(obj)
when Experiment
return current_value unless obj.navigable?
+
path = obj.archived? ? experiment_archive_project_path(obj.project) : canvas_experiment_path(obj)
when MyModule
return current_value unless obj.navigable?
+
path = obj.archived? ? module_archive_experiment_path(obj.experiment) : protocols_my_module_path(obj)
when Protocol
if obj.in_repository?
@@ -59,16 +61,28 @@ module GlobalActivitiesHelper
end
when Result
return current_value unless obj.navigable?
+
path = obj.archived? ? archive_my_module_path(obj.my_module) : results_my_module_path(obj.my_module)
+ when Step
+ return current_value
+ when Report
+ path = reports_path
else
return current_value
end
- route_to_other_team(path, obj, current_value)
+ route_to_other_team(path, team, 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')
+
+ value = obj.public_send(message_item[:value_for] || 'name')
+ value = t('global_activities.index.no_name') if value.blank?
+
+ # format if is datetime format
+ value = l(value, format: :full_date) if value.methods.include? :strftime
+
+ value
end
end
diff --git a/app/models/repository.rb b/app/models/repository.rb
index ab43f6db7..f1f8c1a88 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -113,6 +113,13 @@ class Repository < ApplicationRecord
end
# If everything is okay, return new_repo
+ Activities::CreateActivityService
+ .call(activity_type: :copy_inventory,
+ owner: created_by,
+ subject: new_repo,
+ team: new_repo.team,
+ message_items: { repository_new: new_repo.id, repository_original: id })
+
new_repo
end
diff --git a/app/services/repository_actions/duplicate_rows.rb b/app/services/repository_actions/duplicate_rows.rb
index 91a412ed3..138dd0fa9 100644
--- a/app/services/repository_actions/duplicate_rows.rb
+++ b/app/services/repository_actions/duplicate_rows.rb
@@ -36,6 +36,13 @@ module RepositoryActions
row.repository_cells.each do |cell|
duplicate_repository_cell(cell, new_row)
end
+
+ Activities::CreateActivityService
+ .call(activity_type: :copy_inventory_item,
+ owner: @user,
+ subject: @repository,
+ team: @repository.team,
+ message_items: { repository_row_new: new_row.id, repository_row_original: row.id })
end
end
diff --git a/app/views/global_activities/references/_repository.html.erb b/app/views/global_activities/references/_repository.html.erb
index 8cbf026f2..f0dab5953 100644
--- a/app/views/global_activities/references/_repository.html.erb
+++ b/app/views/global_activities/references/_repository.html.erb
@@ -3,7 +3,7 @@
<% if subject %>
- <%= route_to_other_team(repositories_path(subject),
+ <%= route_to_other_team(repository_path(subject.id),
team,
subject.name&.truncate(Constants::NAME_TRUNCATION_LENGTH),
title: subject.name) %>
diff --git a/config/initializers/extends.rb b/config/initializers/extends.rb
index 0d93f5e2c..27f9bf21a 100644
--- a/config/initializers/extends.rb
+++ b/config/initializers/extends.rb
@@ -209,7 +209,9 @@ class Extends
export_system_logs: 98,
edit_wopi_file_on_result: 99,
edit_wopi_file_on_step: 100,
- edit_wopi_file_on_step_in_repository: 101
+ edit_wopi_file_on_step_in_repository: 101,
+ copy_inventory: 105,
+ copy_inventory_item: 102
}.freeze
ACTIVITY_GROUPS = {
@@ -220,8 +222,8 @@ class Extends
task_inventory: [55, 56],
experiment: [*27..31, 57],
reports: [48, 49, 50],
- inventories: [*70..78],
- protocol_repository: [*79..91],
+ inventories: [*70..78, 105, 102],
+ protocol_repository: [*79..91, 101],
team: [*92..96],
exports: [*97..98]
}.freeze
diff --git a/config/locales/global_activities/en.yml b/config/locales/global_activities/en.yml
index 40de2109d..243f23739 100644
--- a/config/locales/global_activities/en.yml
+++ b/config/locales/global_activities/en.yml
@@ -32,6 +32,7 @@ en:
select_users: "Select Users"
select_objects: "Select Objects"
deselect_all_objects: "Deselect All Objects"
+ no_name: "(unnamed)"
content:
create_project_html: "%{user} created project %{project}."
rename_project_html: "%{user} renamed project %{project}."
@@ -106,11 +107,13 @@ en:
delete_item_inventory_html: "%{user} deleted inventory item %{repository_row}."
create_column_inventory_html: "%{user} created column %{repository_column} in inventory %{repository}."
edit_column_inventory_html: "%{user} edited column %{repository_column} in inventory %{repository}."
+ copy_inventory_html: "%{user} copied inventory %{repository_new} from inventory %{repository_original} as template"
+ copy_inventory_item_html: "%{user} copied inventory item %{repository_row_new} from inventory item %{repository_row_original}"
delete_column_inventory_html: "%{user} deleted column %{repository_column} in inventory %{repository}."
create_protocol_in_repository_html: "%{user} created protocol %{protocol} in Protocol repository."
- add_step_to_protocol_repository_html: "%{user} created protocol %{protocol}'s step %{step} in Protocol repository."
- edit_step_in_protocol_repository_html: "%{user} edited protocol %{protocol}'s step %{step} in Protocol repository."
- delete_step_in_protocol_repository_html: "%{user} deleted protocol %{protocol}'s step %{step} in Protocol repository."
+ add_step_to_protocol_repository_html: "%{user} created protocol %{protocol}'s step %{step_position} %{step} in Protocol repository."
+ edit_step_in_protocol_repository_html: "%{user} edited protocol %{protocol}'s step %{step_position} %{step} in Protocol repository."
+ delete_step_in_protocol_repository_html: "%{user} deleted protocol %{protocol}'s step %{step_position} %{step} in Protocol repository."
edit_description_in_protocol_repository_html: "%{user} edited protocol %{protocol}'s description in Protocol repository."
edit_keywords_in_protocol_repository_html: "%{user} edited protocol %{protocol}'s keywords in Protocol repository."
edit_authors_in_protocol_repository_html: "%{user} edited protocol %{protocol}'s authors in Protocol repository."
@@ -201,6 +204,8 @@ en:
delete_item_inventory: "Inventory item deleted"
create_column_inventory: "Inventory column created"
edit_column_inventory: "Inventory column edited"
+ copy_inventory: "Inventory copied"
+ copy_inventory_item: "Inventory item copied"
delete_column_inventory: "Inventory column deleted"
update_protocol_in_repository_from_task: "Protocol updated from task"
create_protocol_in_repository: "Protocol created"
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index 0c38f71f1..f6095cb71 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -42,4 +42,21 @@ describe Repository, type: :model do
expect(repo).to_not be_valid
end
end
+
+ describe '.copy' do
+ let(:created_by) { create :user }
+ let(:repository) { create :repository }
+
+ it 'calls create activity for copying inventory' do
+ expect(Activities::CreateActivityService)
+ .to(receive(:call).with(hash_including(activity_type: :copy_inventory)))
+
+ repository.copy(created_by, 'name for copied repo')
+ end
+
+ it 'adds activity in DB' do
+ expect { repository.copy(created_by, 'name for copied repo') }
+ .to(change { Activity.count })
+ end
+ end
end
diff --git a/spec/services/repository_actions/duplicate_rows_spec.rb b/spec/services/repository_actions/duplicate_rows_spec.rb
index 2dc3b2cd0..5b433ab98 100644
--- a/spec/services/repository_actions/duplicate_rows_spec.rb
+++ b/spec/services/repository_actions/duplicate_rows_spec.rb
@@ -79,5 +79,17 @@ describe RepositoryActions::DuplicateRows do
service_obj.call
expect(service_obj.number_of_duplicated_items).to eq 0
end
+
+ it 'calls create activity for copying intentory items 3 times' do
+ expect(Activities::CreateActivityService)
+ .to(receive(:call).with(hash_including(activity_type: :copy_inventory_item))).exactly(3).times
+
+ described_class.new(user, repository, @rows_ids).call
+ end
+
+ it 'adds 3 activities in DB' do
+ expect { described_class.new(user, repository, @rows_ids).call }
+ .to(change { Activity.count }.by(3))
+ end
end
end