--- lib/A3C/LDAP.pm 2008/03/30 16:58:21 42 +++ lib/A3C/LDAP.pm 2008/04/02 17:02:43 59 @@ -104,7 +104,13 @@ =head2 as_collection_of - my $connection = $ldap->collection('Organization', $limit); + my $connection = $ldap->collection( + # name of model to use + 'Organization', + # optional params + limit => $limit, + filter => '(uid=foobar)', + ); =cut @@ -114,20 +120,29 @@ }; sub collection { - my ( $self, $model, $limit ) = @_; + my $self = shift; + my $model = shift or die "no model?"; + my $args = {@_}; - $limit ||= 100; # FIXME + $args->{limit} ||= 0; # unlimited by default my $filter = $collection2filter->{$model}; die "unknown model $model" unless $filter; + # add user filter + $filter = '(&' . $filter . $args->{filter} . ')' if $args->{filter}; + $self->search( base => $self->base, filter => $filter, - sizelimit => $limit, + sizelimit => $args->{limit}, ); - Jifty->log->info("searching LDAP for $model with $filter limit $limit returned ", $self->count, " results"); + Jifty->log->info( + "Searching LDAP for $model with $filter ", + $args->{limit} ? 'limit ' . $args->{limit} . ' ' : '', + 'returned ', $self->count, ' results' + ); my $class = Jifty->app_class('Model', $model . 'Collection' ) or die "can't create ${model}Collection"; my $collection = $class->new() or die "can't $class->new"; @@ -173,7 +188,7 @@ if ( grep(/^\Q$attr\E$/, @columns ) ) { $data->{$attr} = $entry->get_value( $attr ); } elsif ( $attr !~ m/^(objectClass)$/i ) { - Jifty->log->error(ref($model)," doesn't have $attr"); + Jifty->log->warn(ref($model)," doesn't have $attr"); } } @@ -182,7 +197,7 @@ my ( $id, $message ) = $model->load_or_create( %$data, %$additional ); if ( $id ) { - Jifty->log->info( $message || 'Added', ' ', ref($model), ' ', $model->id ); + Jifty->log->info( $message || 'Added', ' ', ref($model), ' ', $model->id, ' ', $model->name ); } else { Jifty->log->error( ref($model), " ", $message ); }