/[A3C]/lib/A3C/LDAP.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/A3C/LDAP.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 44 by dpavlin, Sun Mar 30 21:59:34 2008 UTC revision 101 by dpavlin, Thu May 1 12:59:02 2008 UTC
# Line 104  sub count { Line 104  sub count {
104    
105  =head2 as_collection_of  =head2 as_collection_of
106    
107    my $connection = $ldap->collection('Organization', $limit);    my $connection = $ldap->collection(
108            # name of model to use
109            'Organization',
110            # optional params
111            limit => $limit,
112            filter => '(uid=foobar)',
113      );
114    
115  =cut  =cut
116    
117  my $collection2filter = {  my $collection2filter = {
118          'User'                  => '(objectClass=hrEduPerson)',          'Person'                => '(objectClass=hrEduPerson)',
119          'Organization'  => '(objectClass=hrEduOrg)',          'Organization'  => '(objectClass=hrEduOrg)',
120  };  };
121    
122  sub collection {  sub collection {
123          my ( $self, $model, $limit ) = @_;          my $self = shift;
124            my $model = shift or die "no model?";
125            my $args = {@_};
126    
127          $limit ||= 0;   # unlimited by default          $args->{limit} ||= 0;   # unlimited by default
128    
129          my $filter = $collection2filter->{$model};          my $filter = $collection2filter->{$model};
130          die "unknown model $model" unless $filter;  #       die "unknown model $model" unless $filter;
131            # fallback to model named as objectClass
132            $filter ||= "(objectClass=$model)";
133    
134            # add user filter
135            $filter = '(&' . $filter . $args->{filter} . ')' if $args->{filter};
136    
137          $self->search(          $self->search(
138                  base => $self->base,                  base => $self->base,
139                  filter => $filter,                  filter => $filter,
140                  sizelimit => $limit,                  sizelimit => $args->{limit},
141          );          );
142    
143          Jifty->log->info("searching LDAP for $model with $filter limit $limit returned ", $self->count, " results");          Jifty->log->info(
144                    "Searching LDAP for $model with $filter ",
145                    $args->{limit} ? 'limit ' . $args->{limit} . ' ' : '',
146                    'returned ', $self->count, ' results'
147            );
148    
149          my $class = Jifty->app_class('Model', $model . 'Collection' ) or die "can't create ${model}Collection";          my $class = Jifty->app_class('Model', $model . 'Collection' ) or die "can't create ${model}Collection";
150          my $collection = $class->new() or die "can't $class->new";          my $collection = $class->new() or die "can't $class->new";
# Line 136  sub collection { Line 153  sub collection {
153                  my $model_obj = Jifty->app_class('Model',$model)->new;                  my $model_obj = Jifty->app_class('Model',$model)->new;
154                  #warn dump( $model_obj );                  #warn dump( $model_obj );
155                  my $additional;                  my $additional;
 #               if ( $model eq 'User' ) {  
 #                       my $organization = A3C::Model::Organization->new;  
 #                       $self->ldap2model( $organization, $entry );  
 #                       $additional->{organization} = $organization;  
 #               }  
156                  $self->ldap2model( $model_obj, $entry, %$additional );                  $self->ldap2model( $model_obj, $entry, %$additional );
157                  $collection->add_record( $model_obj );                  $collection->add_record( $model_obj );
158          }          }
# Line 182  sub ldap2model { Line 194  sub ldap2model {
194          my ( $id, $message ) = $model->load_or_create( %$data, %$additional );          my ( $id, $message ) = $model->load_or_create( %$data, %$additional );
195    
196          if ( $id ) {          if ( $id ) {
197                  Jifty->log->info( $message || 'Added', ' ', ref($model), ' ', $model->id );                  Jifty->log->info( $message || 'Added', ' ', ref($model), ' ', $model->id, ' ', $model->name );
198          } else {          } else {
199                  Jifty->log->error( ref($model), " ", $message );                  Jifty->log->error( ref($model), " ", $message );
200          }          }

Legend:
Removed from v.44  
changed lines
  Added in v.101

  ViewVC Help
Powered by ViewVC 1.1.26