diff --git a/app/assets/javascripts/repositories/index.js b/app/assets/javascripts/repositories/index.js index 307872a33..5b08815f7 100644 --- a/app/assets/javascripts/repositories/index.js +++ b/app/assets/javascripts/repositories/index.js @@ -1,4 +1,4 @@ -/* global HelperModule DataTableHelpers DataTableCheckboxes */ +/* global I18n animateSpinner HelperModule DataTableHelpers DataTableCheckboxes */ (function(global) { 'use strict'; @@ -92,6 +92,18 @@ HelperModule.flashAlertMsg(data.flash, 'success'); initRepositoriesDataTable('#repositoriesList'); reloadSidebar(); + }, + error: function(ev) { + if (ev.status === 403) { + HelperModule.flashAlertMsg( + I18n.t('repositories.js.permission_error'), ev.responseJSON.style + ); + } else if (ev.status === 422) { + HelperModule.flashAlertMsg( + ev.responseJSON.error, 'danger' + ); + animateSpinner(null, false); + } } }); }; @@ -106,6 +118,18 @@ HelperModule.flashAlertMsg(data.flash, 'success'); initRepositoriesDataTable('#repositoriesList', true); reloadSidebar(); + }, + error: function(ev) { + if (ev.status === 403) { + HelperModule.flashAlertMsg( + I18n.t('repositories.js.permission_error'), ev.responseJSON.style + ); + } else if (ev.status === 422) { + HelperModule.flashAlertMsg( + ev.responseJSON.error, 'danger' + ); + animateSpinner(null, false); + } } }); }; diff --git a/app/services/repositories/archive_repository_service.rb b/app/services/repositories/archive_repository_service.rb index b4d5bb8db..001b247a2 100644 --- a/app/services/repositories/archive_repository_service.rb +++ b/app/services/repositories/archive_repository_service.rb @@ -8,12 +8,13 @@ module Repositories ActiveRecord::Base.transaction do @repositories.each do |repository| log_activity(:archive_inventory, repository) - repository.archive!(@user) + repository.archive!(@user) RepositoryActions::ArchiveRowsService.call(repository: repository, repository_rows: repository.repository_rows.pluck(:id), user: @user, - team: @team) + team: @team, + log_activities: false) end rescue ActiveRecord::RecordNotSaved @errors[:archiving_error] = I18n.t('repositories.archive_inventories.unsuccess_flash') diff --git a/app/services/repositories/restore_repository_service.rb b/app/services/repositories/restore_repository_service.rb index 896aef8c0..000f74567 100644 --- a/app/services/repositories/restore_repository_service.rb +++ b/app/services/repositories/restore_repository_service.rb @@ -12,7 +12,9 @@ module Repositories RepositoryActions::RestoreRowsService.call(repository: repository, repository_rows: repository.repository_rows.pluck(:id), user: @user, - team: @team) + team: @team, + log_activities: false) + log_activity(:restore_inventory, repository) end rescue ActiveRecord::RecordNotSaved diff --git a/app/services/repository_actions/archive_rows_base_service.rb b/app/services/repository_actions/archive_rows_base_service.rb index 83e8047d0..4fec343cf 100644 --- a/app/services/repository_actions/archive_rows_base_service.rb +++ b/app/services/repository_actions/archive_rows_base_service.rb @@ -6,11 +6,12 @@ module RepositoryActions attr_reader :errors - def initialize(user:, team:, repository:, repository_rows:) + def initialize(user:, team:, repository:, repository_rows:, log_activities: true) @user = user @team = team @repository = repository @repository_rows = scoped_repository_rows(repository_rows) + @log_activities = log_activities @errors = {} end @@ -51,7 +52,7 @@ module RepositoryActions Activities::CreateActivityService .call(activity_type: type, owner: @user, - subject: row, + subject: row.repository, team: @team, message_items: { repository_row: row.id diff --git a/app/services/repository_actions/archive_rows_service.rb b/app/services/repository_actions/archive_rows_service.rb index e3da4b152..98f5057b4 100644 --- a/app/services/repository_actions/archive_rows_service.rb +++ b/app/services/repository_actions/archive_rows_service.rb @@ -6,9 +6,9 @@ module RepositoryActions return self unless valid? ActiveRecord::Base.transaction do - @repository_rows.each do |row| + @repository_rows.find_each(batch_size: 100) do |row| row.archive!(@user) - log_activity(:archive_inventory_item, row) + log_activity(:archive_inventory_item, row) if @log_activities end rescue ActiveRecord::RecordNotSaved @errors[:archiving_error] = I18n.t('repositories.archive_records.unsuccess_flash', @repository.name) diff --git a/app/services/repository_actions/restore_rows_service.rb b/app/services/repository_actions/restore_rows_service.rb index 016997b3b..6486e5a95 100644 --- a/app/services/repository_actions/restore_rows_service.rb +++ b/app/services/repository_actions/restore_rows_service.rb @@ -6,9 +6,9 @@ module RepositoryActions return self unless valid? ActiveRecord::Base.transaction do - @repository_rows.each do |row| + @repository_rows.find_each(batch_size: 100) do |row| row.restore!(@user) - log_activity(:restore_inventory_item, row) + log_activity(:restore_inventory_item, row) if @log_activities end rescue ActiveRecord::RecordNotSaved @errors[:restoring_error] = I18n.t('repositories.restore_records.unsuccess_flash', @repository.name)