From craig.white at ttiltd.com Thu Dec 1 18:43:02 2011 From: craig.white at ttiltd.com (Craig White) Date: Thu, 1 Dec 2011 16:43:02 -0700 Subject: [activeldap-discuss] deleting with a leaf Message-ID: Can't seem to find any way to get this done... goal is to delete 'uid=mhenderson,ou=people,dc=company,dc=local' but he has an "AddressBook" ou below his entry (which of course, only he can use)... $ ldapsearch -x -b 'uid=mhenderson,ou=people,dc=company,dc=local' '(ou=addressbook)' # extended LDIF # # LDAPv3 # base with scope subtree # filter: (ou=addressbook) # requesting: ALL # # AddressBook, mhenderson, people, company.local dn: ou=AddressBook,uid=mhenderson,ou=people,dc=company,dc=local objectClass: organizationalUnit ou: AddressBook which leaves me with a problem that I can't seem to figure out how to get it removed in any reasonable fashion. irb(main):082:0> @person = Person.find('mhenderson') => # snipped a bunch of data... irb(main):083:0> @person.delete ActiveLdap::DeleteError: Failed to delete LDAP entry: <["uid=mhenderson,ou=People,dc=company,dc=local"]>: Operation not allowed on non-leaf from /usr/local/lib/ruby/gems/1.8/gems/activeldap-3.1.1/lib/active_ldap/operations.rb:521:in `delete_entry' from /usr/local/lib/ruby/gems/1.8/gems/activeldap-3.1.1/lib/active_ldap/operations.rb:512:in `delete' from /usr/local/lib/ruby/gems/1.8/gems/activeldap-3.1.1/lib/active_ldap/persistence.rb:24:in `delete' from (irb):83 from :0 @person.destroy - same error but with callbacks naturally Lacking any real API, I ended up getting all of @person's methods and dumping them into a word processor and replacing all the commas with line feeds and it was 22 pages but nothing seemingly will delete/destroy the subject entry and of course, the children which is obviously what I'm hoping to do. Obviously I have no problem deleting someone who doesn't have any similar AddressBook OU. Can anyone toss me a bone here? Craig -- Craig White ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ craig.white at ttiltd.com 1.800.869.6908 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ www.ttiassessments.com Need help communicating between generations at work to achieve your desired success? Let us help! From kou at cozmixng.org Sat Dec 3 01:48:52 2011 From: kou at cozmixng.org (Kouhei Sutou) Date: Sat, 03 Dec 2011 15:48:52 +0900 (JST) Subject: [activeldap-discuss] deleting with a leaf In-Reply-To: References: Message-ID: <20111203.154852.2026084516173574022.kou@cozmixng.org> Hi, In "[activeldap-discuss] deleting with a leaf" on Thu, 1 Dec 2011 16:43:02 -0700, Craig White wrote: > Can't seem to find any way to get this done... > > goal is to delete 'uid=mhenderson,ou=people,dc=company,dc=local' > > but he has an "AddressBook" ou below his entry (which of course, only he can use)... Could you try delete_all or destroy_all? > irb(main):082:0> @person = Person.find('mhenderson') @person.delete_all or @person.destroy_all Thanks, -- kou From craig.white at ttiltd.com Mon Dec 5 10:40:21 2011 From: craig.white at ttiltd.com (Craig White) Date: Mon, 5 Dec 2011 08:40:21 -0700 Subject: [activeldap-discuss] deleting with a leaf In-Reply-To: <20111203.154852.2026084516173574022.kou@cozmixng.org> References: <20111203.154852.2026084516173574022.kou@cozmixng.org> Message-ID: <985E8810-F8BB-4BAE-ACBB-E508E8D04BBD@ttiltd.com> On Dec 2, 2011, at 11:48 PM, Kouhei Sutou wrote: > Hi, > > In > "[activeldap-discuss] deleting with a leaf" on Thu, 1 Dec 2011 16:43:02 -0700, > Craig White wrote: > >> Can't seem to find any way to get this done... >> >> goal is to delete 'uid=mhenderson,ou=people,dc=company,dc=local' >> >> but he has an "AddressBook" ou below his entry (which of course, only he can use)... > > Could you try delete_all or destroy_all? > >> irb(main):082:0> @person = Person.find('mhenderson') > > @person.delete_all > or > @person.destroy_all ---- For the record... $ gem list --local | grep activeldap activeldap (3.1.1) $ ruby -v ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-linux], MBARI 0x8770, Ruby Enterprise Edition 2011.03 **** anyway, had delete_all or destroy_all worked for me, I wouldn't have asked the list but since you asked... irb(main):043:0> @person = Person.find('mhenderson') => #, must: @person.delete_all ActiveLdap::DeleteError: Failed to delete LDAP entry: <["uid=mhenderson,ou=people,dc=company,dc=local"]>: Operation not allowed on non-leaf from /usr/local/lib/ruby/gems/1.8/gems/activeldap-3.1.1/lib/active_ldap/operations.rb:521:in `delete_entry' from /usr/local/lib/ruby/gems/1.8/gems/activeldap-3.1.1/lib/active_ldap/operations.rb:541:in `delete_all' from /usr/local/lib/ruby/gems/1.8/gems/activeldap-3.1.1/lib/active_ldap/base.rb:1035:in `delete_all' from (irb):44 irb(main):045:0> @person.destroy_all ActiveLdap::DeleteError: Failed to delete LDAP entry: <["uid=mhenderson,ou=People,dc=company,dc=local"]>: Operation not allowed on non-leaf from /usr/local/lib/ruby/gems/1.8/gems/activeldap-3.1.1/lib/active_ldap/operations.rb:521:in `delete_entry' from /usr/local/lib/ruby/gems/1.8/gems/activeldap-3.1.1/lib/active_ldap/operations.rb:512:in `delete' from /usr/local/lib/ruby/gems/1.8/gems/activeldap-3.1.1/lib/active_ldap/persistence.rb:19:in `destroy' from /usr/local/lib/ruby/gems/1.8/gems/activeldap-3.1.1/lib/active_ldap/callbacks.rb:50:in `destroy' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:390:in `_run_destroy_callbacks' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:81:in `send' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:81:in `run_callbacks' from /usr/local/lib/ruby/gems/1.8/gems/activeldap-3.1.1/lib/active_ldap/callbacks.rb:50:in `destroy' from /usr/local/lib/ruby/gems/1.8/gems/activeldap-3.1.1/lib/active_ldap/operations.rb:503:in `destroy_all' from /usr/local/lib/ruby/gems/1.8/gems/activeldap-3.1.1/lib/active_ldap/operations.rb:500:in `each' from /usr/local/lib/ruby/gems/1.8/gems/activeldap-3.1.1/lib/active_ldap/operations.rb:500:in `destroy_all' from /usr/local/lib/ruby/gems/1.8/gems/activeldap-3.1.1/lib/active_ldap/base.rb:1039:in `destroy_all' from (irb):45 Now I could resort to executing a 'system("ldapmodify ... ) command to delete the addressbook ou under the @person object before attemtping to delete the @person but that seemingly defeats the purpose of using activeldap. and I don't think that this matters but I am including my Person class... which you should note, I am including/using an 'encrypt.rb' function lifted from activesambaldap that permits me to hash sambaLMPassword, sambaNTPassword attributes in the 'Microsoft' manner and perhaps you want to consider adding this code (very simple) to activeldap. class Person < ActiveLdap::Base require "encrypt.rb" ldap_mapping :dn_attribute => "uid", :prefix => "ou=People", :classes => ["top", "person", "PosixAccount", 'shadowAccount', 'inetOrgPerson', 'inetLocalMailRecipient', 'sambaSamAccount', 'hostObject'] # Associate with primary belonged group belongs_to :primary_group, :foreign_key => 'gidNumber', :class_name => 'Group', :primary_key => 'gidNumber' # Associate with all belonged groups belongs_to :groups, :foreign_key => 'uid', :class_name => 'Group', :many => 'memberUid' # Associate with all belonged hosts has_many :hosts, :foreign_key => 'cn', :class_name => 'Host', :primary_key => 'host' def validate errors.add(:base, "You must enter a value for the 'uid' (login name)") unless self.uid.to_s != '' errors.add(:base, "You must enter a value for the 'UID Number'") unless self.uidNumber.to_s != '' errors.add(:base, "You must enter a value for the 'GID Number'") unless self.gidNumber.to_s != '' errors.add(:base, "You must enter a value for the 'login shell'") unless self.loginShell.to_s != '' errors.add(:base, "You must enter a value for the 'first name'") unless self.givenName.to_s != '' errors.add(:base, "You must enter a value for the 'last name'") unless self.sn.to_s != '' errors.add(:base, "You must enter a value for the user's 'HOME' directory") unless self.uidNumber.to_s != '' return errors end def validate? self.validate['base'] == [] end def disabled? self.userPassword.include? "Disabled" end def self.by_uid Person.find(:all, '*').sort {|a,b| a.uid <=> b.uid} end def self.by_cn Person.find(:all, '*').sort {|a,b| a.cn <=> b.cn} end def self.by_loginShell Person.find(:all, '*').sort {|a,b| [a.loginShell, a.uid] <=> [b.loginShell, b.uid] } end def self.by_dn Person.find(:all, '*').sort {|a,b| a.dn <=> b.dn } end def self.by_uidNumber Person.find(:all, '*').sort {|a,b| a.uidNumber <=> b.uidNumber } end def self.with_valid_shell self.find(:all, :attribute => 'loginShell', :value => '/bin/bash').collect{|person| person.uid}.sort{|a,b| a <=> b} end def self.last_uidNumber self.find(:all, '*').sort {|a,b| a.uidNumber <=> b.uidNumber }.last.uidNumber end def self.next_sambaSID self.find(:all, '*').sort {|a,b| a.sambaSID <=> b.sambaSID }.last.sambaSID.split('-')[7].to_i + 2 end def memberships self.groups.collect{|p| p.cn}.sort{|a,b| a <=> b} end def persisted? false end # Returns the host attributes in a sorted, collected list def hostlist if self.host == nil then results = [] else results = self.host.sort {|a,b| a <=> b }.collect { |host| host } end return results end def hostlist_columnized if self.host == nil then results = '' else results = self.host.sort {|a,b| a <=> b }.collect { |host| host + "\n" } end return results end def email_aliases if self.mailLocalAddress == nil then results = '' else results = self.mailLocalAddress.sort {|a,b| a <=> b}.collect { |mailLocalAddress| mailLocalAddress } end return results end def email_aliases_columnized if self.mailLocalAddress == nil then results = '' else results = self.mailLocalAddress.sort {|a,b| a <=> b}.collect { |mailLocalAddress| mailLocalAddress + "\n" } end return results end end From craig.white at ttiltd.com Mon Dec 5 14:59:20 2011 From: craig.white at ttiltd.com (Craig White) Date: Mon, 5 Dec 2011 12:59:20 -0700 Subject: [activeldap-discuss] deleting with a leaf In-Reply-To: <20111203.154852.2026084516173574022.kou@cozmixng.org> References: <20111203.154852.2026084516173574022.kou@cozmixng.org> Message-ID: <71961D9B-FC93-4D5B-98E6-9C41D18CE2DC@ttiltd.com> On Dec 2, 2011, at 11:48 PM, Kouhei Sutou wrote: > Hi, > > In > "[activeldap-discuss] deleting with a leaf" on Thu, 1 Dec 2011 16:43:02 -0700, > Craig White wrote: > >> Can't seem to find any way to get this done... >> >> goal is to delete 'uid=mhenderson,ou=people,dc=company,dc=local' >> >> but he has an "AddressBook" ou below his entry (which of course, only he can use)... > > Could you try delete_all or destroy_all? > >> irb(main):082:0> @person = Person.find('mhenderson') > > @person.delete_all > or > @person.destroy_all ---- as noted previously, @person.delete_all and @person.destroy_all failed but I was able to longhand the following code to execute prior to @person.delete/destroy... if ActiveLdap::Base.search(:base => @person.dn.to_s, :filter => '(ou=addressbook)', :scope => :sub) != [] then leaf = ActiveLdap::Base.create leaf.add_class('organizationalunit') leaf.dn = "ou=addressbook," + @person.dn.to_s leaf.delete end Not elegant but does get the job done. Thanks Craig From craig.white at ttiltd.com Mon Dec 5 15:05:53 2011 From: craig.white at ttiltd.com (Craig White) Date: Mon, 5 Dec 2011 13:05:53 -0700 Subject: [activeldap-discuss] Useful activeldap info Message-ID: <021D44E8-7609-484A-B5FE-376189F7B4E7@ttiltd.com> Just wanted to point out that the lack of a usable API was really slowing me down but I found that it was available here (rubydoc.info)... http://rubydoc.info/github/ncdc/ruby-activeldap/master/frames Also - FWIW - and it may or not be of interest to activeldap developers but I found that the following module to generate sambaNTPassword and sambaLMPassword attributes to be very useful (from activesambaldap (0.0.8)) require 'openssl' module Samba module Encrypt module_function def lm_hash(password, encoding=nil) dos_password = Private.convert_encoding("ISO-8859-1", encoding || "UTF-8", password.upcase) if dos_password.size > 14 warn("password is truncated to 14 characters") dos_password = dos_password[0, 14] end Private.encrypt_14characters(dos_password).unpack("C*").collect do |char| "%02X" % char end.join end def ntlm_hash(password, encoding=nil) ucs2_password = Private.convert_encoding("UCS-2", encoding || "UTF-8", password) if ucs2_password.size > 256 raise ArgumentError.new("must be <= 256 characters in UCS-2") end hex = OpenSSL::Digest::MD4.new(ucs2_password).hexdigest.upcase hex end module Private module_function def convert_encoding(to, from, str) if same_encoding?(to, from) str else require 'iconv' Iconv.iconv(to, from, str).join end end def normalize_encoding(encoding) encoding.downcase.gsub(/-/, "_") end def same_encoding?(a, b) na = normalize_encoding(a) nb = normalize_encoding(b) na == nb or na.gsub(/_/, '') == nb.gsub(/_/, '') end def str_to_key(str) key = "\000" * 8 key[0] = str[0] >> 1; key[1] = ((str[0] & 0x01) << 6) | (str[1] >> 2); key[2] = ((str[1] & 0x03) << 5) | (str[2] >> 3); key[3] = ((str[2] & 0x07) << 4) | (str[3] >> 4); key[4] = ((str[3] & 0x0F) << 3) | (str[4] >> 5); key[5] = ((str[4] & 0x1F) << 2) | (str[5] >> 6); key[6] = ((str[5] & 0x3F) << 1) | (str[6] >> 7); key[7] = str[6] & 0x7F; key.size.times do |i| key[i] = (key[i] << 1); end key end def des_crypt56(input, key_str, forward_only) key = str_to_key(key_str) encoder = OpenSSL::Cipher::DES.new encoder.encrypt encoder.key = key encoder.update(input) end LM_MAGIC = "KGS!@\#$%" def encrypt_14characters(chars) raise ArgumentError.new("must be <= 14 characters") if chars.size > 14 chars = chars.to_s.ljust(14, "\000") des_crypt56(LM_MAGIC, chars[0, 7], true) + des_crypt56(LM_MAGIC, chars[7, 7], true) end end end end -- Craig White ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ craig.white at ttiltd.com 1.800.869.6908 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ www.ttiassessments.com Need help communicating between generations at work to achieve your desired success? Let us help! From kou at cozmixng.org Wed Dec 7 07:02:17 2011 From: kou at cozmixng.org (Kouhei Sutou) Date: Wed, 07 Dec 2011 21:02:17 +0900 (JST) Subject: [activeldap-discuss] Useful activeldap info In-Reply-To: <021D44E8-7609-484A-B5FE-376189F7B4E7@ttiltd.com> References: <021D44E8-7609-484A-B5FE-376189F7B4E7@ttiltd.com> Message-ID: <20111207.210217.495980597959149680.kou@cozmixng.org> Hi, In <021D44E8-7609-484A-B5FE-376189F7B4E7 at ttiltd.com> "[activeldap-discuss] Useful activeldap info" on Mon, 5 Dec 2011 13:05:53 -0700, Craig White wrote: > Also - FWIW - and it may or not be of interest to activeldap developers but I found that the following module to generate sambaNTPassword and sambaLMPassword attributes to be very useful (from activesambaldap (0.0.8)) I'm interested in it becuase I'm the author of it. :-) Umm... Should we import ActiveSambaLdap libraries into ActiveLdap...? Thanks, -- kou From kou at cozmixng.org Wed Dec 7 07:10:01 2011 From: kou at cozmixng.org (Kouhei Sutou) Date: Wed, 07 Dec 2011 21:10:01 +0900 (JST) Subject: [activeldap-discuss] deleting with a leaf In-Reply-To: <71961D9B-FC93-4D5B-98E6-9C41D18CE2DC@ttiltd.com> References: <20111203.154852.2026084516173574022.kou@cozmixng.org> <71961D9B-FC93-4D5B-98E6-9C41D18CE2DC@ttiltd.com> Message-ID: <20111207.211001.1444722151710842193.kou@cozmixng.org> Hi, In <71961D9B-FC93-4D5B-98E6-9C41D18CE2DC at ttiltd.com> "Re: [activeldap-discuss] deleting with a leaf" on Mon, 5 Dec 2011 12:59:20 -0700, Craig White wrote: >> Could you try delete_all or destroy_all? >> >>> irb(main):082:0> @person = Person.find('mhenderson') >> >> @person.delete_all >> or >> @person.destroy_all > ---- > as noted previously, @person.delete_all and @person.destroy_all failed but I was able to longhand the following code to execute prior to @person.delete/destroy... > > if ActiveLdap::Base.search(:base => @person.dn.to_s, :filter => '(ou=addressbook)', :scope => :sub) != [] then > leaf = ActiveLdap::Base.create > leaf.add_class('organizationalunit') > leaf.dn = "ou=addressbook," + @person.dn.to_s > leaf.delete > end > > Not elegant but does get the job done. Ah, OK. I find a problem. You need to create an class that matches all entries: class Entry < ActiveLdap::Base ldap_mapping :prefix => "", :classes => ["top"], :scope => :sub self.dn_attribute = nil end @person.delete_all finds all sub entries, deletes them and deletes self. But @person.class can't find addressbook entries because they has different objectClasses. Entry.find(@person.dn).delete_all will delete @person. Thanks, -- kou From craig.white at ttiltd.com Wed Dec 7 10:22:55 2011 From: craig.white at ttiltd.com (Craig White) Date: Wed, 7 Dec 2011 08:22:55 -0700 Subject: [activeldap-discuss] Useful activeldap info In-Reply-To: <20111207.210217.495980597959149680.kou@cozmixng.org> References: <021D44E8-7609-484A-B5FE-376189F7B4E7@ttiltd.com> <20111207.210217.495980597959149680.kou@cozmixng.org> Message-ID: <85A5437D-DC00-4243-ACB9-5B11FE2AE07B@ttiltd.com> On Dec 7, 2011, at 5:02 AM, Kouhei Sutou wrote: > Hi, > > In <021D44E8-7609-484A-B5FE-376189F7B4E7 at ttiltd.com> > "[activeldap-discuss] Useful activeldap info" on Mon, 5 Dec 2011 13:05:53 -0700, > Craig White wrote: > >> Also - FWIW - and it may or not be of interest to activeldap developers but I found that the following module to generate sambaNTPassword and sambaLMPassword attributes to be very useful (from activesambaldap (0.0.8)) > > I'm interested in it becuase I'm the author of it. :-) ---- good job - I think it took me all of 10 minutes to incorporate into my application so I found it very worthwhile since my own needs required a way to generate sambaNTPassword attributes (hash). ---- > > Umm... Should we import ActiveSambaLdap libraries into > ActiveLdap...? ---- I was thinking that it was a relatively small amount of code to provide the utility to generate sambaNTPassword & sambaLMPassword attributes (hash) but I don't know if I am typical of the activeldap user. The 3 things that have taken an extremely inordinate amount of time for me were: - beyond the tutorial/reference/rails page, I needed greater detail about the API which I finally found on rubydoc.info (previously linked). - validations, errors were passed as LDAP technical details that were not suitable for users and so I had to figure out how to override them. In the end, I have ended up writing my own validate/validate? methods in my models and testing them prior to saving - pagination, can't seem to get will_paginate to work but I suspect that is a limitation of will_paginate and non-activerecord models but I haven't spent much time on this. I really love the ability to access the LDAP DSA with ruby/rails but along with the time it has taken me to get up to rails 3.1 speed, it has been very slow going but I am close to having a fully functional application. Thanks Craig From craig.white at ttiltd.com Wed Dec 7 12:09:15 2011 From: craig.white at ttiltd.com (Craig White) Date: Wed, 7 Dec 2011 10:09:15 -0700 Subject: [activeldap-discuss] deleting with a leaf In-Reply-To: <20111207.211001.1444722151710842193.kou@cozmixng.org> References: <20111203.154852.2026084516173574022.kou@cozmixng.org> <71961D9B-FC93-4D5B-98E6-9C41D18CE2DC@ttiltd.com> <20111207.211001.1444722151710842193.kou@cozmixng.org> Message-ID: On Dec 7, 2011, at 5:10 AM, Kouhei Sutou wrote: > Hi, > > In <71961D9B-FC93-4D5B-98E6-9C41D18CE2DC at ttiltd.com> > "Re: [activeldap-discuss] deleting with a leaf" on Mon, 5 Dec 2011 12:59:20 -0700, > Craig White wrote: > >>> Could you try delete_all or destroy_all? >>> >>>> irb(main):082:0> @person = Person.find('mhenderson') >>> >>> @person.delete_all >>> or >>> @person.destroy_all >> ---- >> as noted previously, @person.delete_all and @person.destroy_all failed but I was able to longhand the following code to execute prior to @person.delete/destroy... >> >> if ActiveLdap::Base.search(:base => @person.dn.to_s, :filter => '(ou=addressbook)', :scope => :sub) != [] then >> leaf = ActiveLdap::Base.create >> leaf.add_class('organizationalunit') >> leaf.dn = "ou=addressbook," + @person.dn.to_s >> leaf.delete >> end >> >> Not elegant but does get the job done. > > Ah, OK. I find a problem. > > You need to create an class that matches all entries: > > class Entry < ActiveLdap::Base > ldap_mapping :prefix => "", > :classes => ["top"], > :scope => :sub > self.dn_attribute = nil > end > > @person.delete_all finds all sub entries, deletes them and > deletes self. But @person.class can't find addressbook > entries because they has different objectClasses. > > Entry.find(@person.dn).delete_all > > will delete @person. ---- indeed that does the trick and was an extremely valuable snippet of information and of course, much cleaner and more logical than the way I went about it. This sort of answers how I would build an LDAP Browser function (not sure that I will do this but I certainly wondered how I would abstractly collect each layer and clearly this would make such a thing possible). If you ever modify the 'tutorial' page, you should add this information because it really is essential to have a means to load any dn. The method is not without some hurdles to jump though because the return is an array of hashes... irb(main):079:0> @test = Entry.find(:all, '*', :scope => :one, :base => 'dc= company,dc=local') => [#, must:, ...snip... irb(main):080:0> @test[0] => #, must:, may: @test[0].cn => "test" irb(main):082:0> @test[0].dn => #"test"}, {"dc"=>"company"}, {"dc"=>"local"}]> It's a chore to get that into the form of 'cn=test,dc=company,dc=local' which is what I expected the 'dn' to return Thanks for all of your help Craig From tlepich at verizon.net Wed Dec 7 12:49:41 2011 From: tlepich at verizon.net (Ted Lepich) Date: Wed, 7 Dec 2011 12:49:41 -0500 Subject: [activeldap-discuss] pagination Message-ID: Fyi, I was able to get WIllPaginate to work by adding an :offset parameter to ActiveLdap find_every. Note: This is from activeldap-1.2.2 (I haven't had a chance to upgrade this application yet). This required a couple changes to operations.rb. 25c25 < :sort_by, :order, :connection, :base] --- > :sort_by, :order, :connection, :base, :offset] 282a283 > offset = options.delete(:offset) || offset --- 296a307 > results = results[offset, results.size] if offset Then in my rails controllers I can do something like this: ========================================= def index if params['sort'].blank? then sort = 'myName' else sort = params['sort'] end if params['order'].blank? then order = 'ascend' else order = params['order'] end params[:page] = 1 if params[:page].blank? perpage = session[:perpage] || 20 @people = WillPaginate::Collection.create(params[:page], perpage) do |pager| result = Person.find(:all, :sort_by => sort, :order => order, :limit => pager.per_page, :offset => pager.offset) # inject the result array into the paginated collection: pager.replace(result) unless pager.total_entries # the pager didn't manage to guess the total count, do it manually pager.total_entries = Person.count end end respond_to do |format| format.html do if (request.xhr?) render(:update) do |page| page.replace_html 'record-list', :partial => 'list', :layout => false end end end And this at the bottom of my view (_list partial in my case) add this: <%= will_paginate @people %> best regards, ted From craig.white at ttiltd.com Thu Dec 8 13:43:24 2011 From: craig.white at ttiltd.com (Craig White) Date: Thu, 8 Dec 2011 11:43:24 -0700 Subject: [activeldap-discuss] pagination In-Reply-To: References: Message-ID: <4A9190A8-1BB6-486B-97B4-64C49F34FB52@ttiltd.com> On Dec 7, 2011, at 10:49 AM, Ted Lepich wrote: > Fyi, I was able to get WIllPaginate to work by adding an :offset parameter to ActiveLdap find_every. > > Note: This is from activeldap-1.2.2 (I haven't had a chance to upgrade this application yet). > > This required a couple changes to operations.rb. > > 25c25 > < :sort_by, :order, :connection, :base] > --- >> :sort_by, :order, :connection, :base, :offset] > 282a283 >> offset = options.delete(:offset) || offset > --- > 296a307 >> results = results[offset, results.size] if offset > > > Then in my rails controllers I can do something like this: > ========================================= > > def index > if params['sort'].blank? then sort = 'myName' else sort = params['sort'] end > if params['order'].blank? then order = 'ascend' else order = params['order'] end > params[:page] = 1 if params[:page].blank? > perpage = session[:perpage] || 20 > > @people = WillPaginate::Collection.create(params[:page], perpage) do |pager| > result = Person.find(:all, :sort_by => sort, :order => order, :limit => pager.per_page, :offset => pager.offset) > # inject the result array into the paginated collection: > pager.replace(result) > > unless pager.total_entries > # the pager didn't manage to guess the total count, do it manually > pager.total_entries = Person.count > end > end > > respond_to do |format| > format.html do > if (request.xhr?) > render(:update) do |page| > page.replace_html 'record-list', :partial => 'list', :layout => false > end > end > end > > > > And this at the bottom of my view (_list partial in my case) add this: > > <%= will_paginate @people %> ---- activeldap version 3.1.1 That does seem to work... # diff -u operations.rb-dist operations.rb --- operations.rb-dist 2011-12-08 11:03:55.632851232 -0700 +++ operations.rb 2011-12-08 11:28:23.377099818 -0700 @@ -22,7 +22,7 @@ module Common VALID_SEARCH_OPTIONS = [:attribute, :value, :filter, :prefix, :classes, :scope, :limit, :attributes, - :sort_by, :order, :connection, :base] + :sort_by, :order, :connection, :base, :offset] def search(options={}, &block) validate_search_options(options) @@ -280,6 +280,7 @@ sort_by = options.delete(:sort_by) || self.sort_by order = options.delete(:order) || self.order limit = options.delete(:limit) if sort_by or order + offset = options.delete(:offset) || offset options[:attributes] |= ["objectClass"] if options[:attributes] results = search(options).collect do |dn, attrs| @@ -295,6 +296,7 @@ end results.reverse! if normalize_sort_order(order || "ascend") == :descend + results = results[offset, results.size] if offset results = results[0, limit] if limit results end Had to make sure that the 'if offset' line is before the 'if limit' line because that seems to always be true. Since I made a lot of adjustments to live without will_paginate, I will have to put this on the side for the moment as I am knee deep in jquery so I am back to my old people_controller until I get a chance to integrate what I have done for column view/sorting and life without pagination into what is now possible but in the meantime, this allows me to verify that it won't break activeldap (and so far it hasn't). I didn't want to let any more time pass without acknowledging this valuable assistance though. I would think that this would be a very welcome change to the activeldap source since it actually allows will_paginate to work with activeldap models. Thanks Craig From steve at wasabidesigns.co.uk Tue Dec 20 06:22:49 2011 From: steve at wasabidesigns.co.uk (Steve Bell) Date: Tue, 20 Dec 2011 11:22:49 +0000 Subject: [activeldap-discuss] Silly question about removing a user from a group Message-ID: <618A0A0B-68C7-441F-BB2E-90F04B72AC2F@wasabidesigns.co.uk> Hi All, I've got activeldap up and running creating and querying users and groups in openldap and associating them together, all based on the examples provided. However, I'm not sure of the easiest way to remove a user from a group. Probably something really easy, but I couldn't find any examples through a google search. Any suggestions or pointers would be much appreciated. -Steve From craig.white at ttiltd.com Tue Dec 20 10:07:27 2011 From: craig.white at ttiltd.com (Craig White) Date: Tue, 20 Dec 2011 08:07:27 -0700 Subject: [activeldap-discuss] Silly question about removing a user from a group In-Reply-To: <618A0A0B-68C7-441F-BB2E-90F04B72AC2F@wasabidesigns.co.uk> References: <618A0A0B-68C7-441F-BB2E-90F04B72AC2F@wasabidesigns.co.uk> Message-ID: <8D709E77-8B93-44FF-91A4-8E42D5983FE9@ttiltd.com> On Dec 20, 2011, at 4:22 AM, Steve Bell wrote: > Hi All, > > I've got activeldap up and running creating and querying users and groups in openldap and associating them together, all based on the examples provided. However, I'm not sure of the easiest way to remove a user from a group. Probably something really easy, but I couldn't find any examples through a google search. > > Any suggestions or pointers would be much appreciated. ----- here's how I do that in a rails app (though others might now of a cleaner way) params[:id] = SOME_GROUP_NAME params[:delete] = SOME_UID_IN_LDAP @group = Group.find(params[:id]) deleteme = Array.new deleteme << params[:delete] memberlist = @group.memberlist @group.memberUID = memberlist - deleteme @group.save Craig From alexey.chebotar at gmail.com Tue Dec 27 11:50:53 2011 From: alexey.chebotar at gmail.com (Alexey Chebotar) Date: Tue, 27 Dec 2011 18:50:53 +0200 Subject: [activeldap-discuss] [ANN] Ruby/LDAP 0.9.12 Message-ID: Hi guys, I'm glad to announce new version of ruby-ldap after long time of silence. This is a bugfix release, that would not be possible without contribution of the following people: - Marek Veber and Antonio Terceiro fixed memory leaks; - Hiroki Najima fixed compile problems on ruby 1.9.2 and wrote How to compile ruby-ldap on Windows wiki. - Yuri Arabadji sent me a patch with experimental code for enabling client certificate authentication for mozilla ldap 6.0. Other changes you can read in NOTES or ChangeLog * https://raw.github.com/alexey-chebotar/ruby-ldap/master/NOTES * https://raw.github.com/alexey-chebotar/ruby-ldap/master/ChangeLog Thank you for contribution. -------------- next part -------------- An HTML attachment was scrubbed... URL: