mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
UX: Improve error message when a topic cannot be moved due to category restrictions (#20900)
This commit is contained in:
@ -361,7 +361,14 @@ class TopicsController < ApplicationController
|
||||
category = Category.find_by(id: params[:category_id])
|
||||
|
||||
if category || (params[:category_id].to_i == 0)
|
||||
begin
|
||||
guardian.ensure_can_move_topic_to_category!(category)
|
||||
rescue Discourse::InvalidAccess
|
||||
return(
|
||||
render_json_error I18n.t("category.errors.move_topic_to_category_disallowed"),
|
||||
status: :forbidden
|
||||
)
|
||||
end
|
||||
else
|
||||
return render_json_error(I18n.t("category.errors.not_found"))
|
||||
end
|
||||
|
@ -705,6 +705,7 @@ en:
|
||||
disallowed_tags_generic: "This topic has disallowed tags."
|
||||
slug_contains_non_ascii_chars: "contains non-ascii characters"
|
||||
is_already_in_use: "is already in use"
|
||||
move_topic_to_category_disallowed: "You cannot move this topic to a category where you do not have permission to create new topics."
|
||||
cannot_delete:
|
||||
uncategorized: "This category is special. It is intended as a holding area for topics that have no category; it cannot be deleted."
|
||||
has_subcategories: "Can't delete this category because it has sub-categories."
|
||||
|
@ -1391,6 +1391,9 @@ RSpec.describe TopicsController do
|
||||
put "/t/#{topic.id}.json", params: { category_id: category.id }
|
||||
|
||||
expect(response.status).to eq(403)
|
||||
expect(response.parsed_body["errors"].first).to eq(
|
||||
I18n.t("category.errors.move_topic_to_category_disallowed"),
|
||||
)
|
||||
expect(topic.reload.category_id).not_to eq(category.id)
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user