Merge pull request #1618 from urbanrotnik/ur-sci-3240-missing-activities-of-intentory

Missing activities, fix for showing report name, add step positions, fixed links [SCI-3240] [SCI-3246]
This commit is contained in:
Urban Rotnik 2019-04-02 11:02:57 +02:00 committed by GitHub
commit 6ec22c0b3b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 73 additions and 9 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -3,7 +3,7 @@
<div class="ga-breadcrumb">
<span class="fas fa-list-alt"></span>
<% 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) %>

View file

@ -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

View file

@ -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 <strong>%{step}</strong> in Protocol repository."
edit_step_in_protocol_repository_html: "%{user} edited protocol %{protocol}'s step <strong>%{step}</strong> in Protocol repository."
delete_step_in_protocol_repository_html: "%{user} deleted protocol %{protocol}'s step <strong>%{step}</strong> in Protocol repository."
add_step_to_protocol_repository_html: "%{user} created protocol %{protocol}'s step %{step_position} <strong>%{step}</strong> in Protocol repository."
edit_step_in_protocol_repository_html: "%{user} edited protocol %{protocol}'s step %{step_position} <strong>%{step}</strong> in Protocol repository."
delete_step_in_protocol_repository_html: "%{user} deleted protocol %{protocol}'s step %{step_position} <strong>%{step}</strong> 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"

View file

@ -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

View file

@ -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