UX: Improve error message when a topic cannot be moved due to category restrictions (#20900)

This commit is contained in:
Natalie Tay
2023-03-31 02:18:57 +08:00
committed by GitHub
parent 58270954b6
commit 068a36d354
3 changed files with 12 additions and 1 deletions

View File

@ -361,7 +361,14 @@ class TopicsController < ApplicationController
category = Category.find_by(id: params[:category_id]) category = Category.find_by(id: params[:category_id])
if category || (params[:category_id].to_i == 0) if category || (params[:category_id].to_i == 0)
guardian.ensure_can_move_topic_to_category!(category) 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 else
return render_json_error(I18n.t("category.errors.not_found")) return render_json_error(I18n.t("category.errors.not_found"))
end end

View File

@ -705,6 +705,7 @@ en:
disallowed_tags_generic: "This topic has disallowed tags." disallowed_tags_generic: "This topic has disallowed tags."
slug_contains_non_ascii_chars: "contains non-ascii characters" slug_contains_non_ascii_chars: "contains non-ascii characters"
is_already_in_use: "is already in use" 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: cannot_delete:
uncategorized: "This category is special. It is intended as a holding area for topics that have no category; it cannot be deleted." 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." has_subcategories: "Can't delete this category because it has sub-categories."

View File

@ -1391,6 +1391,9 @@ RSpec.describe TopicsController do
put "/t/#{topic.id}.json", params: { category_id: category.id } put "/t/#{topic.id}.json", params: { category_id: category.id }
expect(response.status).to eq(403) 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) expect(topic.reload.category_id).not_to eq(category.id)
end end