diff --git a/.overcommit.yml b/.overcommit.yml
index ae6a4ce07..fa30f071f 100644
--- a/.overcommit.yml
+++ b/.overcommit.yml
@@ -3,3 +3,6 @@ PreCommit:
enabled: true
on_warn: fail
problem_on_unmodified_line: ignore
+ ScssLint:
+ enabled: true
+ problem_on_unmodified_line: ignore
diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb
index 47df4d5ab..3816f8914 100644
--- a/app/controllers/repositories_controller.rb
+++ b/app/controllers/repositories_controller.rb
@@ -1,8 +1,8 @@
class RepositoriesController < ApplicationController
before_action :load_vars,
- except: %i(index create create_modal parse_sheet import_records)
+ except: %i(index create create_modal parse_sheet)
before_action :load_parent_vars, except:
- %i(repository_table_index export_repository parse_sheet import_records)
+ %i(repository_table_index parse_sheet)
before_action :check_team, only: %i(parse_sheet import_records)
before_action :check_view_all_permissions, only: :index
before_action :check_view_permissions, only: %i(export_repository show)
@@ -243,6 +243,9 @@ class RepositoriesController < ApplicationController
status = import_records.import!
if status[:status] == :ok
+ log_activity(:import_inventory_items,
+ num_of_items: status[:nr_of_added])
+
flash[:success] = t('repositories.import_records.success_flash',
number_of_rows: status[:nr_of_added],
total_nr: status[:total_nr])
@@ -272,15 +275,7 @@ class RepositoriesController < ApplicationController
def export_repository
if params[:row_ids] && params[:header_ids]
RepositoryZipExport.generate_zip(params, @repository, current_user)
-
- Activities::CreateActivityService
- .call(activity_type: :export_inventory_items,
- owner: current_user,
- subject: current_team,
- team: current_team,
- message_items: {
- repository: @repository.id
- })
+ log_activity(:export_inventory_items)
else
flash[:alert] = t('zip_export.export_error')
end
@@ -355,12 +350,14 @@ class RepositoriesController < ApplicationController
end
end
- def log_activity(type_of)
+ def log_activity(type_of, message_items = {})
+ message_items = { repository: @repository.id }.merge(message_items)
+
Activities::CreateActivityService
.call(activity_type: type_of,
owner: current_user,
subject: @repository,
team: @team,
- message_items: { repository: @repository.id })
+ message_items: message_items)
end
end
diff --git a/app/models/repository_row.rb b/app/models/repository_row.rb
index 4daa0aae3..783c48ca7 100644
--- a/app/models/repository_row.rb
+++ b/app/models/repository_row.rb
@@ -30,4 +30,10 @@ class RepositoryRow < ApplicationRecord
def self.name_like(query)
where('repository_rows.name ILIKE ?', "%#{query}%")
end
+
+ def self.change_owner(team, user, new_owner)
+ joins(:repository)
+ .where('repositories.team_id = ? and repository_rows.created_by_id = ?', team, user)
+ .update_all(created_by_id: new_owner.id)
+ end
end
diff --git a/app/models/user_team.rb b/app/models/user_team.rb
index 77a1c4320..567b4d594 100644
--- a/app/models/user_team.rb
+++ b/app/models/user_team.rb
@@ -77,6 +77,10 @@ class UserTeam < ApplicationRecord
protocol.save
end
+ # Make new owner author of all inventory items that were added
+ # by departing user and belong to this team.
+ RepositoryRow.change_owner(team, user, new_owner)
+
super()
end
diff --git a/app/services/repository_datatable_service.rb b/app/services/repository_datatable_service.rb
index e2e347d57..2e2887230 100644
--- a/app/services/repository_datatable_service.rb
+++ b/app/services/repository_datatable_service.rb
@@ -60,7 +60,8 @@ class RepositoryDatatableService
search_value)
.pluck(:id)
.uniq
- repository_rows = RepositoryRow.where(id: repository_row_ids)
+ repository_rows = RepositoryRow.left_outer_joins(:created_by)
+ .where(id: repository_row_ids)
end
repository_rows
diff --git a/app/utilities/repository_import_parser/importer.rb b/app/utilities/repository_import_parser/importer.rb
index c526e2768..f82bbde65 100644
--- a/app/utilities/repository_import_parser/importer.rb
+++ b/app/utilities/repository_import_parser/importer.rb
@@ -108,8 +108,6 @@ module RepositoryImportParser
raise ActiveRecord::Rollback
end
- # Disable per row activity logging
- # log_activity(record_row)
@new_rows_added += 1
end
end
@@ -158,18 +156,5 @@ module RepositoryImportParser
end
current_column
end
-
- def log_activity(repository_row)
- Activities::CreateActivityService.call(
- activity_type: :create_item_inventory,
- owner: @user,
- subject: @repository,
- team: @repository.team,
- message_items: {
- repository_row: repository_row.id,
- repository: @repository.id
- }
- )
- end
end
end
diff --git a/app/views/my_modules/activities.html.erb b/app/views/my_modules/activities.html.erb
index 0a1982652..553b61c8d 100644
--- a/app/views/my_modules/activities.html.erb
+++ b/app/views/my_modules/activities.html.erb
@@ -2,17 +2,17 @@
<%= render partial: "shared/sidebar", locals: { current_task: @my_module, page: 'task' } %>
<%= render partial: "shared/secondary_navigation" %>
-
+
<%= render partial: "my_modules/activities/top_pane" %>
-
diff --git a/app/views/users/settings/user_teams/_destroy_user_team_modal_body.html.erb b/app/views/users/settings/user_teams/_destroy_user_team_modal_body.html.erb
index 7f5a68711..b77e2f226 100644
--- a/app/views/users/settings/user_teams/_destroy_user_team_modal_body.html.erb
+++ b/app/views/users/settings/user_teams/_destroy_user_team_modal_body.html.erb
@@ -15,6 +15,7 @@
<%= t("users.settings.user_teams.destroy_uo_alert_line_1") %>
<%= t("users.settings.user_teams.destroy_uo_alert_line_2").html_safe %>
<%= t("users.settings.user_teams.destroy_uo_alert_line_3") %>
+
<%= t("users.settings.user_teams.destroy_uo_alert_line_4") %>
<% end %>
diff --git a/app/views/users/settings/user_teams/_leave_user_team_modal_body.html.erb b/app/views/users/settings/user_teams/_leave_user_team_modal_body.html.erb
index 9e1c023c9..3701a7aa3 100644
--- a/app/views/users/settings/user_teams/_leave_user_team_modal_body.html.erb
+++ b/app/views/users/settings/user_teams/_leave_user_team_modal_body.html.erb
@@ -13,6 +13,7 @@
<%= t("users.settings.user_teams.leave_uo_alert_line_1") %>
<%= t("users.settings.user_teams.leave_uo_alert_line_2").html_safe %>
<%= t("users.settings.user_teams.leave_uo_alert_line_3")%>
+
<%= t("users.settings.user_teams.leave_uo_alert_line_4")%>
<% end %>
diff --git a/config/initializers/extends.rb b/config/initializers/extends.rb
index 92ea5213b..545ce6725 100644
--- a/config/initializers/extends.rb
+++ b/config/initializers/extends.rb
@@ -215,6 +215,7 @@ class Extends
user_leave_team: 104,
copy_inventory: 105,
export_protocol_from_task: 106,
+ import_inventory_items: 107,
create_tag: 108,
delete_tag: 109
}
@@ -227,7 +228,7 @@ class Extends
task_inventory: [55, 56],
experiment: [*27..31, 57],
reports: [48, 50, 49],
- inventories: [70, 71, 105, 72, 73, 74, 102, 75, 76, 77, 78, 96],
+ inventories: [70, 71, 105, 72, 73, 74, 102, 75, 76, 77, 78, 96, 107],
protocol_repository: [80, 103, 89, 87, 79, 90, 91, 88, 85, 86, 84, 81, 82, 83, 101],
team: [92, 94, 93, 97, 104]
}.freeze
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 1d3a6acf5..aa17b1017 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1504,14 +1504,16 @@ en:
leave_uo_alert_heading: "Leaving team has following consequences:"
leave_uo_alert_line_1: "you will lose access to all content belonging to the team (including projects, tasks, protocols and activities);"
leave_uo_alert_line_2: "all projects in the team where you were the sole
Owner will receive a new owner from the team administrators;"
- leave_uo_alert_line_3: "all repository protocols in the team belonging to you will be reassigned onto a new owner from team administrators."
+ leave_uo_alert_line_3: "all repository protocols in the team belonging to you will be reassigned onto a new owner from team administrators;"
+ leave_uo_alert_line_4: "all inventory items in the team added by you will be reassigned onto a new owner from team administrators."
leave_uo_confirm: "Leave"
destroy_uo_heading: "Remove user %{user} from team %{team}"
destroy_uo_message: "Are you sure you wish to remove user %{user} from team %{team}?"
destroy_uo_alert_heading: "Removing user from team has following consequences:"
destroy_uo_alert_line_1: "user will lose access to all content belonging to the team (including projects, tasks, protocols and activities);"
destroy_uo_alert_line_2: "all projects in the team where user was the sole
Owner will be reassigned onto you as a new owner;"
- destroy_uo_alert_line_3: "all repository protocols in the team belonging to user will be reassigned onto you."
+ destroy_uo_alert_line_3: "all repository protocols in the team belonging to user will be reassigned onto you;"
+ destroy_uo_alert_line_4: "all inventory items in the team added by user will be reassigned onto you."
destroy_uo_confirm: "Remove"
leave_flash: "Successfuly left team %{team}."
diff --git a/config/locales/global_activities/en.yml b/config/locales/global_activities/en.yml
index 02765cc33..14e5b2b4f 100644
--- a/config/locales/global_activities/en.yml
+++ b/config/locales/global_activities/en.yml
@@ -130,6 +130,7 @@ en:
create_tag_html: "%{user} created tag
%{tag} in project %{project}."
edit_tag_html: "%{user} edited tag
%{tag} in project %{project}."
delete_tag_html: "%{user} deleted tag
%{tag} in project %{project}."
+ import_inventory_items_html: "%{user} imported %{num_of_items} inventory item(s) to %{repository}."
activity_name:
create_project: "Project created"
@@ -231,6 +232,7 @@ en:
create_tag: "Tag created"
edit_tag: "Tag edited"
delete_tag: "Tag deleted"
+ import_inventory_items: "Inventory items imported"
activity_group:
projects: "Projects"
diff --git a/spec/controllers/repositories_controller_spec.rb b/spec/controllers/repositories_controller_spec.rb
index 40a112023..b477ddcc5 100644
--- a/spec/controllers/repositories_controller_spec.rb
+++ b/spec/controllers/repositories_controller_spec.rb
@@ -13,7 +13,7 @@ describe RepositoriesController, type: :controller do
describe 'POST create' do
let(:params) { { repository: { name: 'My Repository' } } }
- it 'calls create activity for unarchiving experiment' do
+ it 'calls create activity for creating inventory' do
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :create_inventory)))
@@ -32,7 +32,7 @@ describe RepositoriesController, type: :controller do
let(:params) { { id: repository.id, team_id: team.id } }
let(:action) { delete :destroy, params: params }
- it 'calls create activity for unarchiving experiment' do
+ it 'calls create activity for deleting inventory' do
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :delete_inventory)))
@@ -53,7 +53,7 @@ describe RepositoriesController, type: :controller do
end
let(:action) { put :update, params: params, format: :json }
- it 'calls create activity for unarchiving experiment' do
+ it 'calls create activity for renaming inventory' do
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :rename_inventory)))
@@ -87,7 +87,7 @@ describe RepositoriesController, type: :controller do
end
let(:action) { post :export_repository, params: params, format: :json }
- it 'calls create activity for unarchiving experiment' do
+ it 'calls create activity for exporting inventory items' do
expect(Activities::CreateActivityService)
.to(receive(:call)
.with(hash_including(activity_type: :export_inventory_items)))
@@ -100,4 +100,37 @@ describe RepositoriesController, type: :controller do
.to(change { Activity.count })
end
end
+
+ describe 'POST import_records' do
+ let(:repository) { create :repository, team: team }
+ let(:mappings) do
+ { '0': '-1', '1': '', '2': '', '3': '', '4': '', '5': '' }
+ end
+ let(:params) do
+ { id: repository.id,
+ team_id: team.id,
+ file_id: 'file_id',
+ mappings: mappings }
+ end
+ let(:action) { post :import_records, params: params, format: :json }
+
+ it 'calls create activity for importing inventory items' do
+ allow_any_instance_of(ImportRepository::ImportRecords)
+ .to receive(:import!).and_return(status: :ok)
+
+ expect(Activities::CreateActivityService)
+ .to(receive(:call)
+ .with(hash_including(activity_type: :import_inventory_items)))
+
+ action
+ end
+
+ it 'adds activity in DB' do
+ ImportRepository::ImportRecords.any_instance.stub(:import!)
+ .and_return(status: :ok)
+
+ expect { action }
+ .to(change { Activity.count })
+ end
+ end
end