Prevent given external id at object creation.

This commit is contained in:
Martin Edenhofer 2015-02-06 17:13:13 +01:00
parent 8a3038c7b6
commit 4c2d3e50c3
3 changed files with 14 additions and 4 deletions

View file

@ -264,7 +264,7 @@ class ApplicationController < ActionController::Base
begin begin
# create object # create object
generic_object = object.new( object.param_cleanup( params[object.to_app_model_url] ) ) generic_object = object.new( object.param_cleanup( params[object.to_app_model_url], true ) )
# save object # save object
generic_object.save! generic_object.save!

View file

@ -64,7 +64,7 @@ class UsersController < ApplicationController
# @response_message 200 [User] Created User record. # @response_message 200 [User] Created User record.
# @response_message 401 Invalid session. # @response_message 401 Invalid session.
def create def create
user = User.new( User.param_cleanup(params) ) user = User.new( User.param_cleanup(params, true) )
begin begin
# check if it's first user # check if it's first user
@ -122,7 +122,7 @@ class UsersController < ApplicationController
end end
end end
user.save user.save!
# if first user was added, set system init done # if first user was added, set system init done
if count <= 2 if count <= 2

View file

@ -57,18 +57,28 @@ remove all not used model attributes of params
result = Model.param_cleanup(params) result = Model.param_cleanup(params)
for object creation, ignore id's
result = Model.param_cleanup(params, true)
returns returns
result = params # params with valid attributes of model result = params # params with valid attributes of model
=end =end
def self.param_cleanup(params) def self.param_cleanup(params, newObject = false)
if params == nil if params == nil
raise "No params for #{self.to_s}!" raise "No params for #{self.to_s}!"
end end
# ignore id for new objects
if newObject && params[:id]
params[:id] = nil
end
# only use object attributes # only use object attributes
data = {} data = {}
self.new.attributes.each {|item| self.new.attributes.each {|item|