Use grape to validate parameters in the members API
This commit is contained in:
parent
a77b40d45e
commit
da67dca14b
2 changed files with 6 additions and 8 deletions
|
@ -79,13 +79,12 @@ module API
|
|||
optional :expires_at, type: DateTime, desc: 'Date string in the format YEAR-MONTH-DAY'
|
||||
end
|
||||
put ":id/members/:user_id" do
|
||||
source = find_source(source_type, params[:id])
|
||||
source = find_source(source_type, params.delete(:id))
|
||||
authorize_admin_source!(source_type, source)
|
||||
|
||||
member = source.members.find_by!(user_id: params[:user_id])
|
||||
attrs = attributes_for_keys [:access_level, :expires_at]
|
||||
member = source.members.find_by!(user_id: params.delete(:user_id))
|
||||
|
||||
if member.update_attributes(attrs)
|
||||
if member.update_attributes(declared_params(include_missing: false))
|
||||
present member.user, with: Entities::Member, member: member
|
||||
else
|
||||
# This is to ensure back-compatibility but 400 behavior should be used
|
||||
|
|
|
@ -86,13 +86,12 @@ module API
|
|||
optional :expires_at, type: DateTime, desc: 'Date string in the format YEAR-MONTH-DAY'
|
||||
end
|
||||
put ":id/members/:user_id" do
|
||||
source = find_source(source_type, params[:id])
|
||||
source = find_source(source_type, params.delete(:id))
|
||||
authorize_admin_source!(source_type, source)
|
||||
|
||||
member = source.members.find_by!(user_id: params[:user_id])
|
||||
attrs = attributes_for_keys [:access_level, :expires_at]
|
||||
member = source.members.find_by!(user_id: params.delete(:user_id))
|
||||
|
||||
if member.update_attributes(attrs)
|
||||
if member.update_attributes(declared_params(include_missing: false))
|
||||
present member.user, with: ::API::Entities::Member, member: member
|
||||
else
|
||||
# This is to ensure back-compatibility but 400 behavior should be used
|
||||
|
|
Loading…
Reference in a new issue