FIX: Allow error handling for formats besides JSON (#27811)

* Allow error handling for formats besides JSON

* Add a test and sets the default format as JSON
This commit is contained in:
Amanda Alves Branquinho 2024-07-11 11:59:00 -03:00 committed by GitHub
parent 3978db0811
commit 7f0e6e9592
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View File

@ -1107,7 +1107,7 @@ Discourse::Application.routes.draw do
put "bookmarks/bulk"
resources :posts, only: %i[show update create destroy] do
resources :posts, only: %i[show update create destroy], defaults: { format: "json" } do
delete "bookmark", to: "posts#destroy_bookmark"
put "wiki"
put "post_type"

View File

@ -642,6 +642,24 @@ RSpec.describe PostsController do
expect(post.topic.reload.category_id).not_to eq(category.id)
end
describe "trying to add a link without permission" do
it "returns an error message if links are added to posts when not allowed" do
post = create_post
sign_in(post.user)
SiteSetting.post_links_allowed_groups = Group::AUTO_GROUPS[:admins]
put "/posts/#{post.id}",
params: {
post: {
raw: "I'm editing this post to add www.linkhere.com",
},
}
expect(response.status).to eq(422)
expect(response.body).to include("Sorry, you can't include links in your posts.")
end
end
describe "with Post.plugin_permitted_update_params" do
before do
plugin = Plugin::Instance.new