discourse/lib/post_localization_destroyer.rb
Natalie Tay 71b96243e1
FIX: Also check if user can see post or topic prior to letting them localize it (#36749)
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.
2025-12-18 02:12:58 +08:00

13 lines
378 B
Ruby

# frozen_string_literal: true
class PostLocalizationDestroyer
def self.destroy(post:, locale:, acting_user:)
Guardian.new(acting_user).ensure_can_localize_post!(post)
localization = PostLocalization.find_by(post_id: post.id, locale:)
raise Discourse::NotFound unless localization
localization.destroy!
post.publish_change_to_clients! :revised
end
end