mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-06 07:26:04 +08:00
This commit starts to introduce services to replace actions in the ThemesController. We will start with the low langing fruit: * Create * Destroy * BulkDestroy * GetTranslations Endpoints like #import and #update will be much harder. Also, the https://github.com/discourse/discourse-theme-creator plugin overrides some of these controller actions directly, so we need to be careful.
50 lines
1.1 KiB
Ruby
50 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# Destroys a theme and logs the staff action. Related records are destroyed
|
|
# by ActiveRecord dependent: :destroy. Cannot be used to destroy system themes.
|
|
#
|
|
# @example
|
|
# Themes::Destroy.call(
|
|
# guardian: guardian,
|
|
# params: {
|
|
# id: theme.id,
|
|
# }
|
|
# )
|
|
#
|
|
class Themes::Destroy
|
|
include Service::Base
|
|
|
|
# @!method self.call(guardian:, params:)
|
|
# @param [Guardian] guardian
|
|
# @param [Hash] params
|
|
# @option params [Integer] :id The ID of the theme to destroy, must be greater than 0.
|
|
# @return [Service::Base::Context]
|
|
|
|
params do
|
|
attribute :id, :integer
|
|
|
|
# Negative theme IDs are for system themes only, which cannot be destroyed.
|
|
validates :id, presence: true, numericality: { only_integer: true, greater_than: 0 }
|
|
end
|
|
|
|
model :theme
|
|
|
|
transaction do
|
|
step :destroy_theme
|
|
step :log_theme_destroy
|
|
end
|
|
|
|
private
|
|
|
|
def fetch_theme(params:)
|
|
Theme.find_by(id: params.id)
|
|
end
|
|
|
|
def destroy_theme(theme:)
|
|
theme.destroy
|
|
end
|
|
|
|
def log_theme_destroy(theme:, guardian:)
|
|
StaffActionLogger.new(guardian.user).log_theme_destroy(theme)
|
|
end
|
|
end
|