google-code-export / ruby-activeldap

Automatically exported from code.google.com/p/ruby-activeldap
Other
1 stars 1 forks source link

to_xml should handle :except and :only options #5

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create an user ActiveLdap mapping
2. user = User.find(:first)
3. user.to_xml(:except => [:objectClass, :userPassword])

What is the expected output? What do you see instead?
Expected:
<user>
  <dn>cn=Joe Bloggs,ou=people,dc=plop,dc=org</dn>
  <cn>Joe Bloggs</cn>
  <displayName>Mr J Bloggs</displayName>
  <gender>1</gender>
  <hgPersonUid>743</hgPersonUid>
  <mail>gwarf12@plop.org</mail>
  <o>HealthGrid</o>
  <sn>Joe Bloggs</sn>
  <st>France</st>
  <uid>joe.bloggs</uid>
</user>

Actual output:
<user>
  <dn>cn=Joe Bloggs,ou=people,dc=plop,dc=org</dn>
  <cn>Joe Bloggs</cn>
  <displayName>Mr J Bloggs</displayName>
  <gender>1</gender>
  <hgPersonUid>743</hgPersonUid>
  <mail>gwarf12@plop.org</mail>
  <o>HealthGrid</o>
  <objectClass>hgPerson</objectClass>
  <objectClass>inetOrgPerson</objectClass>
  <objectClass>organizationalPerson</objectClass>
  <objectClass>person</objectClass>
  <objectClass>top</objectClass>
  <sn>Joe Bloggs</sn>
  <st>France</st>
  <uid>joe.bloggs</uid>
  <userPassword>{SHA}ZPr10LHcMR/Q+Ur2T2wpagMEVXE=</userPassword>
</user>

What version of the product are you using? On what operating system?
- activeldap 1.0.1
- Rails 2.1.0
- archlinux and debian etch

Please provide any additional information below.
The way ActiveRecord does this:
- http://api.rubyonrails.org/classes/ActiveRecord/XmlSerialization.html#M000923
-
http://github.com/rails/rails/tree/master/activerecord/lib/active_record/seriali
zers/xml_serializer.rb

Thanks a lot for all you work.

Original issue reported on code.google.com by baptiste@bapt.name on 7 Jul 2008 at 2:23

GoogleCodeExporter commented 9 years ago
For now, in order to be able to use the :except option, I redefine to_xml in my 
model
(see the underlined line):

  def to_xml(options={})
    logger.info "plop"
    root = options[:root] || self.class.name.underscore
    result = "<#{root}>\n"
    result << "  <dn>#{dn}</dn>\n"  
    normalize_data(@data).sort_by {|key, values| key}.each do |key, values|
      next if Array(options[:except]).include?(key.to_sym)
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      targets = []
      values.each do |value|
        if value.is_a?(Hash)
          value.each do |option, real_value|
            targets << [real_value, " #{option}=\"true\""]
          end 
        else
          targets << [value]
        end 
      end 
      targets.sort_by {|value, attr| value}.each do |value, attr|
        result << "  <#{key}#{attr}>#{value}</#{key}>\n"
      end 
    end 
    result << "</#{root}>\n"
    result
  end 

Regards,
Baptiste

Original comment by baptiste@bapt.name on 7 Jul 2008 at 3:17

GoogleCodeExporter commented 9 years ago
It's supported in trunk.

Original comment by kou...@gmail.com on 8 Jul 2008 at 11:20

GoogleCodeExporter commented 9 years ago
Sorry for the noise.

Baptiste

Original comment by baptiste@bapt.name on 8 Jul 2008 at 2:39

GoogleCodeExporter commented 9 years ago
It's not a noise.
Thanks for your API improvement suggestion. :)

Original comment by kou...@gmail.com on 8 Jul 2008 at 8:27