discourse/app/controllers/topic_localizations_controller.rb
Natalie Tay 3f8ccda7aa
FEATURE: Allow post authors to localize their own posts (#36178)
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
2025-11-25 11:02:22 +08:00

34 lines
1,008 B
Ruby
Vendored

# frozen_string_literal: true
class TopicLocalizationsController < ApplicationController
before_action :ensure_logged_in
def create_or_update
topic_id, locale, title = params.require(%i[topic_id locale title])
guardian.ensure_can_localize_topic!(topic_id)
topic_localization = TopicLocalization.find_by(topic_id: topic_id, locale: params[:locale])
if topic_localization
TopicLocalizationUpdater.update(
topic_id: topic_id,
locale: params[:locale],
title: params[:title],
user: current_user,
)
render json: success_json, status: :ok
else
TopicLocalizationCreator.create(topic_id:, locale:, title:, user: current_user)
render json: success_json, status: :created
end
end
def destroy
topic_id, locale = params.require(%i[topic_id locale])
guardian.ensure_can_localize_topic!(topic_id)
TopicLocalizationDestroyer.destroy(topic_id:, locale:, acting_user: current_user)
head :no_content
end
end