mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 09:26:54 -06:00
FIX: Restore and deprecate the :type
param of uploads#create
(#29736)
Follow up to 6f8f6a7726
Prior to the linked commit, the `uploads#create` endpoint had a `upload_type` and `type` param that acted as aliases for each other and raised an error if both of them were missing. In the linked commit, we removed the `type` param and always required the `upload_type` param which break API consumers that only included `type` in their requests.
This commit adds back the `type` param temporarily and introduces a deprecation message for it so that API consumers are made aware of the eventual removal of the `type` param.
This commit is contained in:
parent
86a2558f5f
commit
00196b8652
@ -32,9 +32,21 @@ class UploadsController < ApplicationController
|
|||||||
1.minute.to_i,
|
1.minute.to_i,
|
||||||
).performed!
|
).performed!
|
||||||
|
|
||||||
|
type =
|
||||||
|
if params[:upload_type].presence
|
||||||
|
params[:upload_type]
|
||||||
|
elsif params[:type].presence
|
||||||
|
Discourse.deprecate(
|
||||||
|
"the :type param of `POST /uploads` is deprecated, use the :upload_type param instead",
|
||||||
|
since: "3.4",
|
||||||
|
drop_from: "3.5",
|
||||||
|
)
|
||||||
|
params[:type]
|
||||||
|
else
|
||||||
params.require(:upload_type)
|
params.require(:upload_type)
|
||||||
|
end
|
||||||
# 50 characters ought to be enough for the upload type
|
# 50 characters ought to be enough for the upload type
|
||||||
type = params[:upload_type].parameterize(separator: "_")[0..50]
|
type = type.parameterize(separator: "_")[0..50]
|
||||||
|
|
||||||
if type == "avatar" &&
|
if type == "avatar" &&
|
||||||
(
|
(
|
||||||
|
@ -61,6 +61,21 @@ RSpec.describe UploadsController do
|
|||||||
expect(response.status).to eq 200
|
expect(response.status).to eq 200
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "accepts the type param but logs a deprecation message when used" do
|
||||||
|
allow(Discourse).to receive(:deprecate)
|
||||||
|
post "/uploads.json",
|
||||||
|
params: {
|
||||||
|
file: Rack::Test::UploadedFile.new(logo_file),
|
||||||
|
type: "avatar",
|
||||||
|
}
|
||||||
|
expect(response.status).to eq 200
|
||||||
|
expect(Discourse).to have_received(:deprecate).with(
|
||||||
|
"the :type param of `POST /uploads` is deprecated, use the :upload_type param instead",
|
||||||
|
since: "3.4",
|
||||||
|
drop_from: "3.5",
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
it "is successful with an image" do
|
it "is successful with an image" do
|
||||||
post "/uploads.json", params: { file: logo, upload_type: "avatar" }
|
post "/uploads.json", params: { file: logo, upload_type: "avatar" }
|
||||||
expect(response.status).to eq 200
|
expect(response.status).to eq 200
|
||||||
|
Loading…
Reference in New Issue
Block a user