2020-05-24 23:13:21 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module DesignManagement
|
|
|
|
class DeleteDesignsService < DesignService
|
|
|
|
include RunsDesignActions
|
|
|
|
include OnSuccessCallbacks
|
|
|
|
|
|
|
|
def initialize(project, user, params = {})
|
|
|
|
super
|
|
|
|
|
|
|
|
@designs = params.fetch(:designs)
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
return error('Forbidden!') unless can_delete_designs?
|
|
|
|
|
|
|
|
version = delete_designs!
|
2020-06-23 00:09:42 +05:30
|
|
|
EventCreateService.new.destroy_designs(designs, current_user)
|
2022-10-11 01:57:18 +05:30
|
|
|
Gitlab::UsageDataCounters::IssueActivityUniqueCounter.track_issue_designs_removed_action(author: current_user,
|
|
|
|
project: project)
|
2021-11-11 11:23:49 +05:30
|
|
|
TodosDestroyer::DestroyedDesignsWorker.perform_async(designs.map(&:id))
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
success(version: version)
|
|
|
|
end
|
|
|
|
|
|
|
|
def commit_message
|
|
|
|
n = designs.size
|
|
|
|
|
|
|
|
<<~MSG
|
|
|
|
Removed #{n} #{'designs'.pluralize(n)}
|
|
|
|
|
|
|
|
#{formatted_file_list}
|
|
|
|
MSG
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :designs
|
|
|
|
|
|
|
|
def delete_designs!
|
|
|
|
DesignManagement::Version.with_lock(project.id, repository) do
|
|
|
|
run_actions(build_actions)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_delete_designs?
|
|
|
|
Ability.allowed?(current_user, :destroy_design, issue)
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_actions
|
|
|
|
designs.map { |d| design_action(d) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def design_action(design)
|
2020-06-23 00:09:42 +05:30
|
|
|
on_success do
|
|
|
|
counter.count(:delete)
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
DesignManagement::DesignAction.new(design, :delete)
|
|
|
|
end
|
|
|
|
|
|
|
|
def counter
|
|
|
|
::Gitlab::UsageDataCounters::DesignsCounter
|
|
|
|
end
|
|
|
|
|
|
|
|
def formatted_file_list
|
|
|
|
designs.map { |design| "- #{design.full_path}" }.join("\n")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
DesignManagement::DeleteDesignsService.prepend_mod_with('DesignManagement::DeleteDesignsService')
|