mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-25 22:12:08 +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
34 lines
1,008 B
Ruby
Vendored
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
|