mirror of
https://github.com/discourse/discourse.git
synced 2026-03-04 01:15:08 +08:00
This commit undoes the work here https://github.com/discourse/discourse/pull/36099 and here https://github.com/discourse/discourse/pull/36817, (and prevents the need for https://github.com/discourse/discourse/pull/36836) to favour the inline title editor. https://github.com/user-attachments/assets/d7444ed7-dd62-40b0-862b-509787e81f56
52 lines
1.5 KiB
Ruby
52 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class TopicLocalizationsController < ApplicationController
|
|
before_action :ensure_logged_in
|
|
|
|
def show
|
|
topic = Topic.find_by(id: params[:topic_id])
|
|
raise Discourse::NotFound unless topic
|
|
|
|
guardian.ensure_can_see!(topic)
|
|
|
|
localization = TopicLocalization.find_by(topic_id: topic.id, locale: params[:locale])
|
|
raise Discourse::NotFound unless localization
|
|
|
|
render json: TopicLocalizationSerializer.new(localization, root: false)
|
|
end
|
|
|
|
def create_or_update
|
|
topic_id, locale, title = params.require(%i[topic_id locale title])
|
|
|
|
topic = Topic.find_by(id: topic_id)
|
|
raise Discourse::NotFound unless topic
|
|
|
|
guardian.ensure_can_localize_topic!(topic)
|
|
|
|
topic_localization = TopicLocalization.find_by(topic_id: topic.id, locale: params[:locale])
|
|
if topic_localization
|
|
TopicLocalizationUpdater.update(
|
|
topic:,
|
|
locale: params[:locale],
|
|
title: params[:title],
|
|
user: current_user,
|
|
)
|
|
render json: success_json, status: :ok
|
|
else
|
|
TopicLocalizationCreator.create(topic:, locale:, title:, user: current_user)
|
|
render json: success_json, status: :created
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
topic_id, locale = params.require(%i[topic_id locale])
|
|
|
|
topic = Topic.find_by(id: topic_id)
|
|
raise Discourse::NotFound unless topic
|
|
|
|
guardian.ensure_can_localize_topic!(topic)
|
|
|
|
TopicLocalizationDestroyer.destroy(topic:, locale:, acting_user: current_user)
|
|
head :no_content
|
|
end
|
|
end
|