mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-21 07:35:47 +08:00
We should allow authors to localize their own content. This is gated behind the `content_localization_allow_author_localization` setting, which is enabled by default. Meta: https://meta.discourse.org/t/feature-request-allow-users-to-localize-only-their-own-topics/389147
18 lines
546 B
Ruby
Vendored
18 lines
546 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class TopicLocalizationUpdater
|
|
def self.update(topic_id:, locale:, title:, user:)
|
|
Guardian.new(user).ensure_can_localize_topic!(topic_id)
|
|
|
|
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
|