def set_attribute_data(data, user)
            return {} unless self.can_write_attributes?(data, user)
            data.each_with_object(Hash.new) do | (key, value), result |
                # First we set all the attributes that are allowed

                if self.setting_attribute_is_allowed?(key.to_sym, user)
                    result[key] = value
                    public_send("#{key}=", value)
                elsif value.present?
                    # allow nested params to be specified using Rails _attributes
                    name = key.to_s.gsub(/_attributes$/,'').to_sym

                    next unless self.class.has_exported_nested_attribute?(name, user)

                    association = self.association(name)
                    if value.is_a?(Hash) && [:belongs_to,:has_one].include?(association.reflection.macro)
                        target = send(name) || association.build
                        result[name] = target.set_attribute_data(value, user)
                    elsif value.is_a?(Array) && :has_many == association.reflection.macro
                        result[name] = _set_attribute_data_from_collection(association, name, value, user)
                    end
                end
            end
        end
def set_attribute_data(data, user)
            return {} unless self.can_write_attributes?(data, user)
            data.each_with_object(Hash.new) do | (key, value), result |
                # First we set all the attributes that are allowed

                if self.setting_attribute_is_allowed?(key.to_sym, user)
                    result[key] = value
                    public_send("#{key}=", value)
                elsif value.present?
                    # allow nested params to be specified using Rails _attributes
                    name = key.to_s.gsub(/_attributes$/,'').to_sym

                    next unless self.class.has_exported_nested_attribute?(name, user)

                    association = self.association(name)
                    if value.is_a?(Hash) && [:belongs_to,:has_one].include?(association.reflection.macro)
                        target = send(name) || association.build
                        result[name] = target.set_attribute_data(value, user)
                    elsif value.is_a?(Array) && :has_many == association.reflection.macro
                        result[name] = _set_attribute_data_from_collection(association, name, value, user)
                    end
                end
            end
        end
Takes in a hash containing attribute name/value pairs, as well as sub hashes/arrays.
 Sets all the attributes that are allowed and recursively sets sub-associations as well
 @param data [Hash]
 @param user [User] who is performing request
 @returns