mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-04-29 13:28:22 +08:00
There exists a `localization_guardian` that checks if a user can localize based on settings like - `content_localization_allowed_groups` - `content_localization_allow_author_localization` However, it missed out checking if the user can even see the model. This commit fixes that by adding the checks. This issue was found as I was adding a new model (`tags`) and discovered they were absent for the older models. This commit also introduces a small refactor that `.find`s the model first on the controller and passes the object, so that the subsequent services do not have to `.find` them again.
21 lines
543 B
Ruby
21 lines
543 B
Ruby
# frozen_string_literal: true
|
|
|
|
class PostLocalizationCreator
|
|
def self.create(post:, locale:, raw:, user:)
|
|
Guardian.new(user).ensure_can_localize_post!(post)
|
|
|
|
localization =
|
|
PostLocalization.create!(
|
|
post: post,
|
|
locale: locale,
|
|
raw: raw,
|
|
cooked: post.post_analyzer.cook(raw, post.cooking_options || {}),
|
|
post_version: post.version,
|
|
localizer_user_id: user.id,
|
|
)
|
|
|
|
Jobs.enqueue(:process_localized_cooked, post_localization_id: localization.id)
|
|
|
|
localization
|
|
end
|
|
end
|