mirror of
https://github.com/discourse/discourse.git
synced 2025-03-09 14:34:35 +00:00
Implemented strong_parameters for PostAction/PostActionsController.
PostActionsController now uses strong_parameters' #require to require certain parameters. ActionController::ParameterMissing is now thrown when a reqired parameter is missing, rather than Discourse::InvalidParameters.
This commit is contained in:
parent
3b245031a4
commit
f50b648844
@ -70,7 +70,7 @@ class PostActionsController < ApplicationController
|
||||
private
|
||||
|
||||
def fetch_post_from_params
|
||||
requires_parameter(:id)
|
||||
params.require(:id)
|
||||
finder = Post.where(id: params[:id])
|
||||
|
||||
# Include deleted posts if the user is a moderator (to guardian ?)
|
||||
@ -81,7 +81,7 @@ class PostActionsController < ApplicationController
|
||||
end
|
||||
|
||||
def fetch_post_action_type_id_from_params
|
||||
requires_parameter(:post_action_type_id)
|
||||
params.require(:post_action_type_id)
|
||||
@post_action_type_id = params[:post_action_type_id].to_i
|
||||
end
|
||||
end
|
||||
|
@ -5,6 +5,7 @@ require_dependency 'trashable'
|
||||
class PostAction < ActiveRecord::Base
|
||||
class AlreadyActed < StandardError; end
|
||||
|
||||
include ActiveModel::ForbiddenAttributesProtection
|
||||
include RateLimiter::OnCreateRecord
|
||||
include Trashable
|
||||
|
||||
|
@ -14,11 +14,11 @@ describe PostActionsController do
|
||||
end
|
||||
|
||||
it 'raises an error when the id is missing' do
|
||||
lambda { xhr :post, :create, post_action_type_id: PostActionType.types[:like] }.should raise_error(Discourse::InvalidParameters)
|
||||
lambda { xhr :post, :create, post_action_type_id: PostActionType.types[:like] }.should raise_error(ActionController::ParameterMissing)
|
||||
end
|
||||
|
||||
it 'raises an error when the post_action_type_id index is missing' do
|
||||
lambda { xhr :post, :create, id: @post.id }.should raise_error(Discourse::InvalidParameters)
|
||||
lambda { xhr :post, :create, id: @post.id }.should raise_error(ActionController::ParameterMissing)
|
||||
end
|
||||
|
||||
it "fails when the user doesn't have permission to see the post" do
|
||||
@ -70,7 +70,7 @@ describe PostActionsController do
|
||||
let!(:user) { log_in }
|
||||
|
||||
it 'raises an error when the post_action_type_id is missing' do
|
||||
lambda { xhr :delete, :destroy, id: post.id }.should raise_error(Discourse::InvalidParameters)
|
||||
lambda { xhr :delete, :destroy, id: post.id }.should raise_error(ActionController::ParameterMissing)
|
||||
end
|
||||
|
||||
it "returns 404 when the post action type doesn't exist for that user" do
|
||||
@ -116,7 +116,7 @@ describe PostActionsController do
|
||||
let!(:user) { log_in(:moderator) }
|
||||
|
||||
it "raises an error without a post_action_type_id" do
|
||||
-> { xhr :post, :clear_flags, id: flagged_post.id }.should raise_error(Discourse::InvalidParameters)
|
||||
-> { xhr :post, :clear_flags, id: flagged_post.id }.should raise_error(ActionController::ParameterMissing)
|
||||
end
|
||||
|
||||
it "raises an error when the user doesn't have access" do
|
||||
@ -160,13 +160,13 @@ describe PostActionsController do
|
||||
it 'raises an error without an id' do
|
||||
lambda {
|
||||
xhr :get, :users, post_action_type_id: PostActionType.types[:like]
|
||||
}.should raise_error(Discourse::InvalidParameters)
|
||||
}.should raise_error(ActionController::ParameterMissing)
|
||||
end
|
||||
|
||||
it 'raises an error without a post action type' do
|
||||
lambda {
|
||||
xhr :get, :users, id: post.id
|
||||
}.should raise_error(Discourse::InvalidParameters)
|
||||
}.should raise_error(ActionController::ParameterMissing)
|
||||
end
|
||||
|
||||
it "fails when the user doesn't have permission to see the post" do
|
||||
|
Loading…
x
Reference in New Issue
Block a user