A platform for community discussion. Free, open, simple.
DEV: Handle ActionController::Parameters in update_tags (#38453)
Isaac Janzencad1ee0b7520
diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rbindex 4837367c2ae..3af51eef940 100644--- a/app/controllers/topics_controller.rb+++ b/app/controllers/topics_controller.rb@@ -495,7 +495,12 @@ class TopicsController < ApplicationControllertopic = Topic.find_by(id: params[:topic_id])guardian.ensure_can_edit_tags!(topic)- tags = params[:tags] || []+ tags =+ if params[:tags].is_a?(ActionController::Parameters)+ params[:tags].values+ else+ params[:tags] || []+ endif tags.present? && tags.first.is_a?(String)Discourse.deprecate(diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rbindex 8e28d4c4d37..b6cafea75f3 100644--- a/spec/requests/topics_controller_spec.rb+++ b/spec/requests/topics_controller_spec.rb@@ -2380,6 +2380,23 @@ RSpec.describe TopicsController doexpect(topic.tags.pluck(:id)).to contain_exactly(tag.id)end+ it "can update tags when params are form-encoded as indexed hash" do+ expect do+ put "/t/#{topic.id}/tags.json",+ params: {+ tags: {+ "0" => {+ id: tag.id,+ name: tag.name,+ },+ },+ }+ end.to change { topic.reload.first_post.revisions.count }.by(1)++ expect(response.status).to eq(200)+ expect(topic.tags.pluck(:id)).to contain_exactly(tag.id)+ end+it "can create a new tag" doSiteSetting.create_tag_allowed_groups = Group::AUTO_GROUPS[:trust_level_0]