Add user id tracking when discarding repository [SCI-2462]

This commit is contained in:
Oleksii Kriuchykhin 2018-05-29 15:33:02 +02:00
parent b8ce934976
commit 6cf9149baa
3 changed files with 12 additions and 13 deletions

View file

@ -74,7 +74,7 @@ class RepositoriesController < ApplicationController
flash[:success] = t('repositories.index.delete_flash',
name: @repository.name)
@repository.discard
ClearDiscardedRepositoriesJob.perform_later
@repository.destroy_discarded(current_user.id)
redirect_to team_repositories_path
end

View file

@ -1,11 +0,0 @@
class ClearDiscardedRepositoriesJob
class << self
def perform_later
Repository.with_discarded.discarded.destroy_all
end
handle_asynchronously :perform_later,
queue: :clear_discarded_repositories,
priority: 20
end
end

View file

@ -2,7 +2,9 @@ class Repository < ApplicationRecord
include SearchableModel
include RepositoryImportParser
include Discard::Model
attribute :discarded_by_id, :integer
belongs_to :team, optional: true
belongs_to :created_by,
foreign_key: :created_by_id,
@ -107,4 +109,12 @@ class Repository < ApplicationRecord
importer = RepositoryImportParser::Importer.new(sheet, mappings, user, self)
importer.run
end
def destroy_discarded(discarded_by_id = nil)
self.discarded_by_id = discarded_by_id
destroy
end
handle_asynchronously :destroy_discarded,
queue: :clear_discarded_repository,
priority: 20
end