Skip to content

Instantly share code, notes, and snippets.

@libryder
Created February 29, 2012 04:14
Show Gist options
  • Select an option

  • Save libryder/1937614 to your computer and use it in GitHub Desktop.

Select an option

Save libryder/1937614 to your computer and use it in GitHub Desktop.
Awesome refactoring
@parent_ou = OrganizationalUnit.where("api_key='#{@api_key}' and api_secret='#{@api_secret}' and master_node=1")
#get first descendents of ou then find all of their children recursively
children = @parent_ou.first.children
ou_children = (children + children.map(&:children)).flatten
#put the children ouid's in a new array
@ous = Array.new
ou_children.each do |child|
@ous.push child.id
end
@parent_ou = OrganizationalUnit.where("api_key='#{@api_key}' and api_secret='#{@api_secret}' and master_node=1")
# remove any session data for this user in case of a corrupt session - we're going to set a new one anyway
CakeSession.delete_all(["id = ?", "#{@api_key}#{@api_secret}"])
#get list of all ou's in organization
lft = @parent_ou.first.lft
rght = @parent_ou.first.rght
@ous = OrganizationalUnit.where("lft >= ? and rght <= ?", lft, rght).map(&:id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment