mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
Implemented strong_parameters for Upload/UploadsController.
The topic_id param is now required using strong_parameters' #require method. If the parameter is missing ActionController::ParameterMissing will be raised instead of Discourse::InvalidParameters.
This commit is contained in:
@ -2,7 +2,7 @@ class UploadsController < ApplicationController
|
|||||||
before_filter :ensure_logged_in
|
before_filter :ensure_logged_in
|
||||||
|
|
||||||
def create
|
def create
|
||||||
requires_parameter(:topic_id)
|
params.require(:topic_id)
|
||||||
file = params[:file] || params[:files].first
|
file = params[:file] || params[:files].first
|
||||||
|
|
||||||
# only supports images for now
|
# only supports images for now
|
||||||
|
@ -5,6 +5,8 @@ require 's3'
|
|||||||
require 'local_store'
|
require 'local_store'
|
||||||
|
|
||||||
class Upload < ActiveRecord::Base
|
class Upload < ActiveRecord::Base
|
||||||
|
include ActiveModel::ForbiddenAttributesProtection
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :topic
|
belongs_to :topic
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ describe UploadsController do
|
|||||||
|
|
||||||
context 'missing params' do
|
context 'missing params' do
|
||||||
it 'raises an error without the topic_id param' do
|
it 'raises an error without the topic_id param' do
|
||||||
-> { xhr :post, :create }.should raise_error(Discourse::InvalidParameters)
|
-> { xhr :post, :create }.should raise_error(ActionController::ParameterMissing)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user