active_fedora
active_fedora copied to clipboard
Setting permissions_attributes on new may mess up the has_model predicate
This occurs with ActiveFedora 11.1.6 & 11.5.2
For a Collection (which is an ActiveFedora::Base model) when I set the permissions_attributes on new the has_model of the Collection gets set incorrectly.
collection = Collection.new({"title"=>["Test"], "subtitle"=>"", "creators"=>{"0"=>{"id"=>"", "given_name"=>"Lorraine C", "sur_name"=>"Santy", "display_name"=>"Lorraine C Santy", "email"=>"", "psu_id"=>""}}, "description"=>["Test Description"], "keyword"=>["test"], "contributor"=>[""], "rights"=>"", "publisher"=>[""], "date_created"=>[""], "subject"=>[""], "language"=>[""], "identifier"=>[""], "based_near"=>[""], "related_url"=>[""], "resource_type"=>[""], "visibility"=>"open", "permissions_attributes"=>{"0"=>{"type"=>"group", "name"=>"umg/course.1479EEE5-988A-3A80-6BF2-45421CAAB5C3", "access"=>"edit"}}})
collection.has_model # ["Collection"]
collection.reload
collection.has_model # []
I traced this through and the assign attributes assigns the permission which autosaves the parent.
When there is no permissions_attributes in the new call, the model does not save on new and the has_model remains valid.
collection = Collection.new({"title"=>["Test"], "subtitle"=>"", "creators"=>{"0"=>{"id"=>"", "given_name"=>"Lorraine C", "sur_name"=>"Santy", "display_name"=>"Lorraine C Santy", "email"=>"", "psu_id"=>""}}, "description"=>["Test Description"], "keyword"=>["test"], "contributor"=>[""], "rights"=>"", "publisher"=>[""], "date_created"=>[""], "subject"=>[""], "language"=>[""], "identifier"=>[""], "based_near"=>[""], "related_url"=>[""], "resource_type"=>[""], "visibility"=>"open"})
collection.save
collection.has_model # ["Collection"]
collection.reload
collection.has_model # ["Collection"]
A workaround is to update the permissions_attributes after the new
collection = Collection.new({"title"=>["Test"], "subtitle"=>"", "creators"=>{"0"=>{"id"=>"", "given_name"=>"Lorraine C", "sur_name"=>"Santy", "display_name"=>"Lorraine C Santy", "email"=>"", "psu_id"=>""}}, "description"=>["Test Description"], "keyword"=>["test"], "contributor"=>[""], "rights"=>"", "publisher"=>[""], "date_created"=>[""], "subject"=>[""], "language"=>[""], "identifier"=>[""], "based_near"=>[""], "related_url"=>[""], "resource_type"=>[""], "visibility"=>"open"})
collection.has_model # ["Collection"]
collection.update_attributes({"permissions_attributes"=>{"0"=>{"type"=>"group", "name"=>"umg/course.1479EEE5-988A-3A80-6BF2-45421CAAB5C3", "access"=>"edit"}}}
collection.reload
collection.has_model # ["Collection"]
Again no save is needed becuase the update_attributes saves the parent model.