mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-05 08:41:11 +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.
18 lines
540 B
Ruby
18 lines
540 B
Ruby
# frozen_string_literal: true
|
|
|
|
class TopicLocalizationUpdater
|
|
def self.update(topic:, locale:, title:, user:)
|
|
Guardian.new(user).ensure_can_localize_topic!(topic)
|
|
|
|
localization = TopicLocalization.find_by(topic_id: topic.id, locale: locale)
|
|
raise Discourse::NotFound unless localization
|
|
|
|
return localization if localization.title == title
|
|
|
|
localization.title = title
|
|
localization.fancy_title = Topic.fancy_title(title)
|
|
localization.localizer_user_id = user.id
|
|
localization.save!
|
|
localization
|
|
end
|
|
end
|