<commit_before>class User < ActiveRecord::Base
  # Adds acts_as_messageable for user mailboxes
  include Mailboxer::Models::Messageable
  # Connects this user object to Blacklights Bookmarks and Folders.
  include Blacklight::User

  Devise.add_module(:http_header_authenticatable,
                    :strategy => true,
                    :controller => :sessions,
                    :model => 'devise/models/http_header_authenticatable')

  devise :http_header_authenticatable

  # set this up as a messageable object
  acts_as_messageable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :login

  # This method should display the unique identifier for this user as defined by devise.
  # The unique identifier is what access controls will be enforced against.
  def user_key
    send(Devise.authentication_keys.first)
  end

  def to_s
    login
  end
  #alias_method :name, :to_s

  def name    
    return self.class.display_name(login)
  end

  # method needed for messaging
  def mailboxer_email(obj=nil)
    return nil
  end

  # Groups that user is a member of
  def groups
    self.class.groups(login) 
  end

  def self.groups(login)
    Hydra::LDAP.groups_for_user(Net::LDAP::Filter.eq('uid', login))  { |result| result.first[:psmemberof].select{ |y| y.starts_with? 'cn=umg/' }.map{ |x| x.sub(/^cn=/, '').sub(/,dc=psu,dc=edu/, '') } } rescue []
  end

  def attributes(attributes=[])
    self.class.attributes(login, attributes)
  end

  def self.attributes(login, attributes=[])
    Hydra::LDAP.get_user(Net::LDAP::Filter.eq('uid', login), attributes)
  end

  def self.current
    Thread.current[:user]
  end

  def self.current=(user)
    Thread.current[:user] = user
  end
  
  def self.display_name(login)
    begin
      res = ScholarSphere::LDAP.get_user(login, ["displayname"])
      logger.info "LDAP result = #{res[0].displayname}"
      return res[0].displayname[0].titleize
     rescue        
        return login
     end
  end
end<commit_msg>User.display_name method uses old, broken way of pulling back LDAP results, modify to use new-style LDAP incantation<commit_after>class User < ActiveRecord::Base
  # Adds acts_as_messageable for user mailboxes
  include Mailboxer::Models::Messageable
  # Connects this user object to Blacklights Bookmarks and Folders.
  include Blacklight::User

  Devise.add_module(:http_header_authenticatable,
                    :strategy => true,
                    :controller => :sessions,
                    :model => 'devise/models/http_header_authenticatable')

  devise :http_header_authenticatable

  # set this up as a messageable object
  acts_as_messageable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :login

  # This method should display the unique identifier for this user as defined by devise.
  # The unique identifier is what access controls will be enforced against.
  def user_key
    send(Devise.authentication_keys.first)
  end

  def to_s
    login
  end

  def name
    return self.class.display_name(login)
  end

  # method needed for messaging
  def mailboxer_email(obj=nil)
    return nil
  end

  # Groups that user is a member of
  def groups
    self.class.groups(login)
  end

  def self.groups(login)
    Hydra::LDAP.groups_for_user(Net::LDAP::Filter.eq('uid', login))  { |result| result.first[:psmemberof].select{ |y| y.starts_with? 'cn=umg/' }.map{ |x| x.sub(/^cn=/, '').sub(/,dc=psu,dc=edu/, '') } } rescue []
  end

  def attributes(attributes=[])
    self.class.attributes(login, attributes)
  end

  def self.attributes(login, attributes=[])
    Hydra::LDAP.get_user(Net::LDAP::Filter.eq('uid', login), attributes)
  end

  def self.current
    Thread.current[:user]
  end

  def self.current=(user)
    Thread.current[:user] = user
  end

  def self.display_name(login)
    res = Hydra::LDAP.get_user(Net::LDAP::Filter.eq('uid', login), ["displayname"])
    logger.info "LDAP result = #{res[0].displayname}"
    return res[0].displayname[0].titleize
  rescue
    return login
  end
end
{'fraction_non_alphanumeric': 0.10658153241650295, 'fraction_numerical': 0.0014734774066797642, 'mean_word_length': 3.4513661202185792, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4966175', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1257, 'n_words': 339}