Prevent given external id at object creation.
This commit is contained in:
parent
8a3038c7b6
commit
4c2d3e50c3
3 changed files with 14 additions and 4 deletions
|
@ -264,7 +264,7 @@ class ApplicationController < ActionController::Base
|
|||
begin
|
||||
|
||||
# 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
|
||||
generic_object.save!
|
||||
|
|
|
@ -64,7 +64,7 @@ class UsersController < ApplicationController
|
|||
# @response_message 200 [User] Created User record.
|
||||
# @response_message 401 Invalid session.
|
||||
def create
|
||||
user = User.new( User.param_cleanup(params) )
|
||||
user = User.new( User.param_cleanup(params, true) )
|
||||
|
||||
begin
|
||||
# check if it's first user
|
||||
|
@ -122,7 +122,7 @@ class UsersController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
user.save
|
||||
user.save!
|
||||
|
||||
# if first user was added, set system init done
|
||||
if count <= 2
|
||||
|
|
|
@ -57,18 +57,28 @@ remove all not used model attributes of params
|
|||
|
||||
result = Model.param_cleanup(params)
|
||||
|
||||
for object creation, ignore id's
|
||||
|
||||
result = Model.param_cleanup(params, true)
|
||||
|
||||
|
||||
returns
|
||||
|
||||
result = params # params with valid attributes of model
|
||||
|
||||
=end
|
||||
|
||||
def self.param_cleanup(params)
|
||||
def self.param_cleanup(params, newObject = false)
|
||||
|
||||
if params == nil
|
||||
raise "No params for #{self.to_s}!"
|
||||
end
|
||||
|
||||
# ignore id for new objects
|
||||
if newObject && params[:id]
|
||||
params[:id] = nil
|
||||
end
|
||||
|
||||
# only use object attributes
|
||||
data = {}
|
||||
self.new.attributes.each {|item|
|
||||
|
|
Loading…
Reference in a new issue