]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm
Fix untranslatable strings in the selfcheck interface.
[working/Evergreen.git] / Open-ILS / src / perlmods / lib / OpenILS / WWW / EGCatLoader / Util.pm
1 package OpenILS::WWW::EGCatLoader;
2 use strict; use warnings;
3 use Apache2::Const -compile => qw(OK DECLINED FORBIDDEN HTTP_INTERNAL_SERVER_ERROR REDIRECT HTTP_BAD_REQUEST);
4 use File::Spec;
5 use OpenSRF::Utils::Logger qw/$logger/;
6 use OpenILS::Utils::CStoreEditor qw/:funcs/;
7 use OpenILS::Utils::Fieldmapper;
8 use OpenILS::Application::AppUtils;
9 use OpenSRF::MultiSession;
10 my $U = 'OpenILS::Application::AppUtils';
11
12 my $ro_object_subs; # cached subs
13 our %cache = ( # cached data
14     map => {en_us => {}},
15     list => {en_us => {}},
16     search => {en_us => {}},
17     org_settings => {en_us => {}},
18     search_filter_groups => {en_us => {}},
19     aou_tree => {en_us => undef},
20     aouct_tree => {},
21     eg_cache_hash => undef
22 );
23
24 sub init_ro_object_cache {
25     my $self = shift;
26     my $e = $self->editor;
27     my $ctx = $self->ctx;
28
29     # reset org unit setting cache on each page load to avoid the
30     # requirement of reloading apache with each org-setting change
31     $cache{org_settings} = {};
32
33     if($ro_object_subs) {
34         # subs have been built.  insert into the context then move along.
35         $ctx->{$_} = $ro_object_subs->{$_} for keys %$ro_object_subs;
36         return;
37     }
38
39     # make all "field_safe" classes accesible by default in the template context
40     my @classes = grep {
41         ($Fieldmapper::fieldmap->{$_}->{field_safe} || '') =~ /true/i
42     } keys %{ $Fieldmapper::fieldmap };
43
44     for my $class (@classes) {
45
46         my $hint = $Fieldmapper::fieldmap->{$class}->{hint};
47         next if $hint eq 'aou'; # handled separately
48
49         my $ident_field =  $Fieldmapper::fieldmap->{$class}->{identity};
50         (my $eclass = $class) =~ s/Fieldmapper:://o;
51         $eclass =~ s/::/_/g;
52
53         my $list_key = "${hint}_list";
54         my $get_key = "get_$hint";
55         my $search_key = "search_$hint";
56
57         # Retrieve the full set of objects with class $hint
58         $ro_object_subs->{$list_key} = sub {
59             my $method = "retrieve_all_$eclass";
60             $cache{list}{$ctx->{locale}}{$hint} = $e->$method() unless $cache{list}{$ctx->{locale}}{$hint};
61             return $cache{list}{$ctx->{locale}}{$hint};
62         };
63
64         # locate object of class $hint with Ident field $id
65         $cache{map}{$hint} = {};
66         $ro_object_subs->{$get_key} = sub {
67             my $id = shift;
68             return $cache{map}{$ctx->{locale}}{$hint}{$id} if $cache{map}{$ctx->{locale}}{$hint}{$id};
69             ($cache{map}{$ctx->{locale}}{$hint}{$id}) = grep { $_->$ident_field eq $id } @{$ro_object_subs->{$list_key}->()};
70             return $cache{map}{$ctx->{locale}}{$hint}{$id};
71         };
72
73         # search for objects of class $hint where field=value
74         $cache{search}{$hint} = {};
75         $ro_object_subs->{$search_key} = sub {
76             my ($field, $val, $filterfield, $filterval) = @_;
77             my $method = "search_$eclass";
78             my $cacheval = $val;
79             if (ref $val) {
80                 $val = [sort(@$val)] if ref $val eq 'ARRAY';
81                 $cacheval = OpenSRF::Utils::JSON->perl2JSON($val);
82                 #$self->apache->log->info("cacheval : $cacheval");
83             }
84             my $search_obj = {$field => $val};
85             if($filterfield) {
86                 $search_obj->{$filterfield} = $filterval;
87                 $cacheval .= ':' . $filterfield . ':' . $filterval;
88             }
89             #$cache{search}{$ctx->{locale}}{$hint}{$field} = {} unless $cache{search}{$ctx->{locale}}{$hint}{$field};
90             $cache{search}{$ctx->{locale}}{$hint}{$field}{$cacheval} = $e->$method($search_obj)
91                 unless $cache{search}{$ctx->{locale}}{$hint}{$field}{$cacheval};
92             return $cache{search}{$ctx->{locale}}{$hint}{$field}{$cacheval};
93         };
94     }
95
96     $ro_object_subs->{aou_tree} = sub {
97
98         # fetch the org unit tree
99         unless($cache{aou_tree}{$ctx->{locale}}) {
100             my $tree = $e->search_actor_org_unit([
101                 {   parent_ou => undef},
102                 {   flesh            => -1,
103                     flesh_fields    => {aou =>  ['children']},
104                     order_by        => {aou => 'name'}
105                 }
106             ])->[0];
107
108             # flesh the org unit type for each org unit
109             # and simultaneously set the id => aou map cache
110             sub flesh_aout {
111                 my $node = shift;
112                 my $ro_object_subs = shift;
113                 my $ctx = shift;
114                 $node->ou_type( $ro_object_subs->{get_aout}->($node->ou_type) );
115                 $cache{map}{$ctx->{locale}}{aou}{$node->id} = $node;
116                 flesh_aout($_, $ro_object_subs, $ctx) foreach @{$node->children};
117             };
118             flesh_aout($tree, $ro_object_subs, $ctx);
119
120             $cache{aou_tree}{$ctx->{locale}} = $tree;
121         }
122
123         return $cache{aou_tree}{$ctx->{locale}};
124     };
125
126     # Add a special handler for the tree-shaped org unit cache
127     $ro_object_subs->{get_aou} = sub {
128         my $org_id = shift;
129         return undef unless defined $org_id;
130         $ro_object_subs->{aou_tree}->(); # force the org tree to load
131         return $cache{map}{$ctx->{locale}}{aou}{$org_id};
132     };
133
134     # Returns a flat list of aou objects.  often easier to manage than a tree.
135     $ro_object_subs->{aou_list} = sub {
136         $ro_object_subs->{aou_tree}->(); # force the org tree to load
137         return [ values %{$cache{map}{$ctx->{locale}}{aou}} ];
138     };
139
140     # returns the org unit object by shortname
141     $ro_object_subs->{get_aou_by_shortname} = sub {
142         my $sn = shift or return undef;
143         my $list = $ro_object_subs->{aou_list}->();
144         return (grep {$_->shortname eq $sn} @$list)[0];
145     };
146
147     $ro_object_subs->{aouct_tree} = sub {
148
149         # fetch the org unit tree
150         unless(exists $cache{aouct_tree}{$ctx->{locale}}) {
151             $cache{aouct_tree}{$ctx->{locale}} = undef;
152
153             my $tree_id = $e->search_actor_org_unit_custom_tree(
154                 {purpose => 'opac', active => 't'},
155                 {idlist => 1}
156             )->[0];
157
158             if ($tree_id) {
159                 my $node_tree = $e->search_actor_org_unit_custom_tree_node([
160                 {parent_node => undef, tree => $tree_id},
161                 {   flesh        => -1,
162                     flesh_fields => {aouctn => ['children', 'org_unit']},
163                     order_by     => {aouctn => 'sibling_order'}
164                 }
165                 ])->[0];
166
167                 # tree-ify the org units.  note that since the orgs are fleshed
168                 # upon retrieval, this org tree will not clobber ctx->{aou_tree}.
169                 my @nodes = ($node_tree);
170                 while (my $node = shift(@nodes)) {
171                     my $aou = $node->org_unit;
172                     $aou->children([]);
173                     for my $cnode (@{$node->children}) {
174                         my $child_org = $cnode->org_unit;
175                         $child_org->parent_ou($aou->id);
176                         $child_org->ou_type( $ro_object_subs->{get_aout}->($child_org->ou_type) );
177                         push(@{$aou->children}, $child_org);
178                         push(@nodes, $cnode);
179                     }
180                 }
181
182                 $cache{aouct_tree}{$ctx->{locale}} = $node_tree->org_unit;
183             }
184         }
185
186         return $cache{aouct_tree}{$ctx->{locale}};
187     };
188
189     # turns an ISO date into something TT can understand
190     $ro_object_subs->{parse_datetime} = sub {
191         my $date = shift;
192
193         # Probably an accidental entry like '0212' instead of '2012',
194         # but 1) the leading 0 may get stripped in cstore and
195         # 2) DateTime::Format::ISO8601 returns an error as years
196         # must be 2 or 4 digits
197         if ($date =~ m/^\d{3}-/) {
198             $logger->warn("Invalid date had a 3-digit year: $date");
199             $date = '0' . $date;
200         } elsif ($date =~ m/^\d{1}-/) {
201             $logger->warn("Invalid date had a 1-digit year: $date");
202             $date = '000' . $date;
203         }
204
205         my $cleansed_date = cleanse_ISO8601($date);
206
207         $date = DateTime::Format::ISO8601->new->parse_datetime($cleansed_date);
208         return sprintf(
209             "%0.2d:%0.2d:%0.2d %0.2d-%0.2d-%0.4d",
210             $date->hour,
211             $date->minute,
212             $date->second,
213             $date->day,
214             $date->month,
215             $date->year
216         );
217     };
218
219     # retrieve and cache org unit setting values
220     $ro_object_subs->{get_org_setting} = sub {
221         my($org_id, $setting) = @_;
222
223         $cache{org_settings}{$ctx->{locale}}{$org_id}{$setting} =
224             $U->ou_ancestor_setting_value($org_id, $setting)
225                 unless exists $cache{org_settings}{$ctx->{locale}}{$org_id}{$setting};
226
227         return $cache{org_settings}{$ctx->{locale}}{$org_id}{$setting};
228     };
229
230     $ctx->{$_} = $ro_object_subs->{$_} for keys %$ro_object_subs;
231 }
232
233 sub generic_redirect {
234     my $self = shift;
235     my $url = shift;
236     my $cookie = shift; # can be an array of cgi.cookie's
237
238     $self->apache->print(
239         $self->cgi->redirect(
240             -url => $url || 
241                 $self->cgi->param('redirect_to') || 
242                 $self->ctx->{referer} || 
243                 $self->ctx->{home_page},
244             -cookie => $cookie
245         )
246     );
247
248     return Apache2::Const::REDIRECT;
249 }
250
251 sub get_records_and_facets {
252     my ($self, $rec_ids, $facet_key, $unapi_args) = @_;
253
254     $unapi_args ||= {};
255     $unapi_args->{site} ||= $self->ctx->{aou_tree}->()->shortname;
256     $unapi_args->{depth} ||= $self->ctx->{aou_tree}->()->ou_type->depth;
257     $unapi_args->{flesh_depth} ||= 5;
258
259     my @data;
260     my $outer_self = $self;
261     $self->timelog("get_records_and_facets(): about to call multisession");
262     my $ses = OpenSRF::MultiSession->new(
263         app => 'open-ils.cstore',
264         cap => 10, # XXX config
265         success_handler => sub {
266             my($self, $req) = @_;
267             my $data = $req->{response}->[0]->content;
268
269             $outer_self->timelog("get_records_and_facets(): got response content");
270
271             # Protect against requests for non-existent records
272             return unless $data->{'unapi.bre'};
273
274             my $xml = XML::LibXML->new->parse_string($data->{'unapi.bre'})->documentElement;
275
276             $outer_self->timelog("get_records_and_facets(): parsed xml");
277             # Protect against legacy invalid MARCXML that might not have a 901c
278             my $bre_id;
279             my $bre_id_nodes =  $xml->find('*[@tag="901"]/*[@code="c"]');
280             if ($bre_id_nodes) {
281                 $bre_id =  $bre_id_nodes->[0]->textContent;
282             } else {
283                 $logger->warn("Missing 901 subfield 'c' in " . $xml->toString());
284             }
285             push(@data, {id => $bre_id, marc_xml => $xml});
286             $outer_self->timelog("get_records_and_facets(): end of success handler");
287         }
288     );
289
290     $self->timelog("get_records_and_facets(): about to call unapi.bre via json_query (rec_ids has " . scalar(@$rec_ids));
291
292     $ses->request(
293         'open-ils.cstore.json_query',
294          {from => [
295             'unapi.bre', $_, 'marcxml','record', 
296             $unapi_args->{flesh}, 
297             $unapi_args->{site}, 
298             $unapi_args->{depth}, 
299             'acn=>' . $unapi_args->{flesh_depth} . ',acp=>' . $unapi_args->{flesh_depth}, 
300             undef, undef, $unapi_args->{pref_lib}
301         ]}
302     ) for @$rec_ids;
303
304
305     $self->timelog("get_records_and_facets():almost ready to fetch facets");
306     # collect the facet data
307     my $search = OpenSRF::AppSession->create('open-ils.search');
308     my $facet_req = $search->request(
309         'open-ils.search.facet_cache.retrieve', $facet_key
310     ) if $facet_key;
311
312     # gather up the unapi recs
313     $ses->session_wait(1);
314     $self->timelog("get_records_and_facets():past session wait");
315
316     my $facets = {};
317     if ($facet_key) {
318         my $tmp_facets = $facet_req->gather(1);
319         $self->timelog("get_records_and_facets(): gathered facet data");
320         for my $cmf_id (keys %$tmp_facets) {
321
322             # sort highest to lowest match count
323             my @entries;
324             my $entries = $tmp_facets->{$cmf_id};
325             for my $ent (keys %$entries) {
326                 push(@entries, {value => $ent, count => $$entries{$ent}});
327             };
328
329             # Sort facet entries by 1) count descending, 2) text ascending
330             @entries = sort {
331                 $b->{count} <=> $a->{count} ||
332                 $a->{value} cmp $b->{value}
333             } @entries;
334
335             $facets->{$cmf_id} = {
336                 cmf => $self->ctx->{get_cmf}->($cmf_id),
337                 data => \@entries
338             }
339         }
340         $self->timelog("get_records_and_facets(): gathered/sorted facet data");
341     } else {
342         $facets = undef;
343     }
344
345     $search->kill_me;
346
347     return ($facets, @data);
348 }
349
350 sub _resolve_org_id_or_shortname {
351     my ($self, $str) = @_;
352
353     if (length $str) {
354         # Match on shortname case insensitively, but only if there's exactly
355         # one match.  We wouldn't want the system to arbitrarily interpret
356         # 'foo' as either the org unit with shortname 'FOO' or 'Foo' and fail
357         # to make it clear to the user which one was chosen and why.
358         my $res = $self->editor->search_actor_org_unit({
359             shortname => {
360                 '=' => {
361                     transform => 'evergreen.lowercase',
362                     value => lc($str)
363                 }
364             }
365         });
366         return $res->[0]->id if $res and @$res == 1;
367     }
368
369     # Note that we don't validate IDs; we only try a shortname lookup and then
370     # assume anything else must be an ID.
371     return int($str); # Wrapping in int() prevents 500 on unmatched string.
372 }
373
374 sub _get_search_lib {
375     my $self = shift;
376     my $ctx = $self->ctx;
377
378     # avoid duplicate lookups
379     return $ctx->{search_ou} if $ctx->{search_ou};
380
381     my $loc = $ctx->{copy_location_group_org};
382     return $loc if $loc;
383
384     # loc param takes precedence
385     # XXX ^-- over what exactly? We could use clarification here. To me it looks
386     # like locg takes precedence over loc which in turn takes precedence over
387     # request headers which take precedence over pref_lib (which can be
388     # specified a lot of different ways and eventually falls back to
389     # physical_loc) and it all finally defaults to top of the org tree.
390     # To say nothing of all the code that doesn't look to this function at all
391     # but rather accesses some subset of these inputs directly.
392
393     $loc = $self->cgi->param('loc');
394     return $loc if $loc;
395
396     if ($self->apache->headers_in->get('OILS-Search-Lib')) {
397         return $self->apache->headers_in->get('OILS-Search-Lib');
398     }
399
400     my $pref_lib = $self->_get_pref_lib();
401     return $pref_lib if $pref_lib;
402
403     return $ctx->{aou_tree}->()->id;
404 }
405
406 sub _get_pref_lib {
407     my $self = shift;
408     my $ctx = $self->ctx;
409
410     # plib param takes precedence
411     my $plib = $self->cgi->param('plib');
412     return $plib if $plib;
413
414     if ($self->apache->headers_in->get('OILS-Pref-Lib')) {
415         return $self->apache->headers_in->get('OILS-Pref-Lib');
416     }
417
418     if ($ctx->{user}) {
419         # See if the user has a search library preference
420         my $lset = $self->editor->search_actor_user_setting({
421             usr => $ctx->{user}->id, 
422             name => 'opac.default_search_location'
423         })->[0];
424         return OpenSRF::Utils::JSON->JSON2perl($lset->value) if $lset;
425
426         # Otherwise return the user's home library
427         my $ou = $ctx->{user}->home_ou;
428         return ref($ou) ? $ou->id : $ou;
429     }
430
431     if ($ctx->{physical_loc}) {
432         return $ctx->{physical_loc};
433     }
434
435 }
436
437 # This is defensively coded since we don't do much manual reading from the
438 # file system in this module.
439 sub load_eg_cache_hash {
440     my ($self) = @_;
441
442     # just a context helper
443     $self->ctx->{eg_cache_hash} = sub { return $cache{eg_cache_hash}; };
444
445     # Need to actually load the value? If already done, move on.
446     return if defined $cache{eg_cache_hash};
447
448     # In this way even if we fail, we won't slow things down by ever trying
449     # again within this Apache process' lifetime.
450     $cache{eg_cache_hash} = 0;
451
452     my $path = File::Spec->catfile(
453         $self->apache->document_root, "eg_cache_hash"
454     );
455
456     if (not open FH, "<$path") {
457         $self->apache->log->warn("error opening $path : $!");
458         return;
459     } else {
460         my $buf;
461         my $rv = read FH, $buf, 64;  # defensive
462         close FH;
463
464         if (not defined $rv) {  # error
465             $self->apache->log->warn("error reading $path : $!");
466         } elsif ($rv > 0) {     # no error, something read
467             chomp $buf;
468             $cache{eg_cache_hash} = $buf;
469         }
470     }
471 }
472
473 # Extracts the copy location org unit and group from the 
474 # "logc" param, which takes the form org_id:grp_id.
475 sub extract_copy_location_group_info {
476     my $self = shift;
477     my $ctx = $self->ctx;
478     if (my $clump = $self->cgi->param('locg')) {
479         my ($org, $grp) = split(/:/, $clump);
480         $ctx->{copy_location_group_org} =
481             $self->_resolve_org_id_or_shortname($org);
482         $ctx->{copy_location_group} = $grp if $grp;
483     }
484 }
485
486 sub load_copy_location_groups {
487     my $self = shift;
488     my $ctx = $self->ctx;
489
490     # User can access to the search location groups at the current 
491     # search lib, the physical location lib, and the patron's home ou.
492     my @ctx_orgs = $ctx->{search_ou};
493     push(@ctx_orgs, $ctx->{physical_loc}) if $ctx->{physical_loc};
494     push(@ctx_orgs, $ctx->{user}->home_ou) if $ctx->{user};
495
496     my $grps = $self->editor->search_asset_copy_location_group([
497         {
498             opac_visible => 't',
499             owner => {
500                 in => {
501                     select => {aou => [{
502                         column => 'id', 
503                         transform => 'actor.org_unit_full_path',
504                         result_field => 'id',
505                     }]},
506                     from => 'aou',
507                     where => {id => \@ctx_orgs}
508                 }
509             }
510         },
511         {order_by => {acplg => 'pos'}}
512     ]);
513
514     my %buckets;
515     push(@{$buckets{$_->owner}}, $_) for @$grps;
516     $ctx->{copy_location_groups} = \%buckets;
517 }
518
519 sub set_file_download_headers {
520     my $self = shift;
521     my $filename = shift;
522     my $ctype = shift || "text/plain; encoding=utf8";
523
524     $self->apache->content_type($ctype);
525
526     $self->apache->headers_out->add(
527         "Content-Disposition",
528         "attachment;filename=$filename"
529     );
530
531     return Apache2::Const::OK;
532 }
533
534 sub apache_log_if_event {
535     my ($self, $event, $prefix_text, $success_ok, $level) = @_;
536
537     $prefix_text ||= "Evergreen returned event";
538     $success_ok ||= 0;
539     $level ||= "warn";
540
541     chomp $prefix_text;
542     $prefix_text .= ": ";
543
544     my $code = $U->event_code($event);
545     if (defined $code and ($code or not $success_ok)) {
546         $self->apache->log->$level(
547             $prefix_text .
548             ($event->{textcode} || "") . " ($code)" .
549             ($event->{note} ? (": " . $event->{note}) : "")
550         );
551         return 1;
552     }
553
554     return;
555 }
556
557 sub load_search_filter_groups {
558     my $self = shift;
559     my $ctx_org = shift;
560     my $org_list = $U->get_org_ancestors($ctx_org, 1);
561
562     my %seen;
563     for my $org_id (@$org_list) {
564
565         my $grps;
566         if (! ($grps = $cache{search_filter_groups}{$org_id}) ) {
567             $grps = $self->editor->search_actor_search_filter_group([
568                 {owner => $org_id},
569                 {   flesh => 2, 
570                     flesh_fields => {
571                         asfg => ['entries'],
572                         asfge => ['query']
573                     },
574                     order_by => {asfge => 'pos'}
575                 }
576             ]);
577             $cache{search_filter_groups}{$org_id} = $grps;
578         }
579
580         # for the current context, if a descendant org has a group 
581         # with a matching code replace the group from the parent.
582         $seen{$_->code} = $_ for @$grps;
583     }
584
585     return $self->ctx->{search_filter_groups} = \%seen;
586 }
587
588
589 sub check_for_temp_list_warning {
590     my $self = shift;
591     my $ctx = $self->ctx;
592     my $cgi = $self->cgi;
593
594     my $lib = $self->_get_search_lib;
595     my $warn = ($ctx->{get_org_setting}->($lib || 1, 'opac.patron.temporary_list_warn')) ? 1 : 0;
596
597     if ($warn && $ctx->{user}) {
598         $self->_load_user_with_prefs;
599         my $map = $ctx->{user_setting_map};
600         $warn = 0 if ($$map{'opac.temporary_list_no_warn'});
601     }
602
603     # Check for a cookie disabling the warning.
604     $warn = 0 if ($warn && $cgi->cookie('no_temp_list_warn'));
605
606     return $warn;
607 }
608
609 sub load_org_util_funcs {
610     my $self = shift;
611     my $ctx = $self->ctx;
612
613     # evaluates to true if test_ou is within the same depth-
614     # scoped tree as ctx_ou. both ou's are org unit objects.
615     $ctx->{org_within_scope} = sub {
616         my ($ctx_ou, $test_ou, $depth) = @_;
617
618         return 1 if $ctx_ou->id == $test_ou->id;
619
620         if ($depth) {
621
622             # find the top-most ctx-org ancestor at the provided depth
623             while ($depth < $ctx_ou->ou_type->depth 
624                     and $ctx_ou->id != $test_ou->id) {
625                 $ctx_ou = $ctx->{get_aou}->($ctx_ou->parent_ou);
626             }
627
628             # the preceeding loop may have landed on our org
629             return 1 if $ctx_ou->id == $test_ou->id;
630
631         } else {
632
633             return 1 if defined $depth; # $depth == 0;
634         }
635
636         for my $child (@{$ctx_ou->children}) {
637             return 1 if $ctx->{org_within_scope}->($child, $test_ou);
638         }
639
640         return 0;
641     };
642
643     # Returns true if the provided org unit is within the same 
644     # org unit hiding depth-scoped tree as the physical location.
645     # Org unit hiding is based on the immutable physical_loc
646     # and is not meant to change as search/pref/etc libs change
647     $ctx->{org_within_hiding_scope} = sub {
648         my $org_id = shift;
649         my $ploc = $ctx->{physical_loc} or return 1;
650
651         my $depth = $ctx->{get_org_setting}->(
652             $ploc, 'opac.org_unit_hiding.depth');
653
654         return 1 unless $depth; # 0 or undef
655
656         return $ctx->{org_within_scope}->( 
657             $ctx->{get_aou}->($ploc), 
658             $ctx->{get_aou}->($org_id), $depth);
659  
660     };
661
662     # Evaluates to true if the context org (defaults to get_library) 
663     # is not within the hiding scope.  Also evaluates to true if the 
664     # user's pref_ou is set and it's out of hiding scope.
665     # Always evaluates to true when ctx.is_staff
666     $ctx->{org_hiding_disabled} = sub {
667         my $ctx_org = shift || $ctx->{search_ou};
668
669         return 1 if $ctx->{is_staff};
670
671         # beware locg values formatted as org:loc
672         $ctx_org =~ s/:.*//g;
673
674         return 1 if !$ctx->{org_within_hiding_scope}->($ctx_org);
675
676         return 1 if $ctx->{pref_ou} and $ctx->{pref_ou} != $ctx_org 
677             and !$ctx->{org_within_hiding_scope}->($ctx->{pref_ou});
678
679         return 0;
680     };
681
682 }
683
684
685     
686
687
688 1;