From: Bill Erickson Date: Tue, 13 Nov 2012 22:52:03 +0000 (-0500) Subject: Org Unit Hiding : move scope checks into Perl X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=944fd802678648b0fef34ef9f1a3b997e49f4ca6;p=evergreen%2Fequinox.git Org Unit Hiding : move scope checks into Perl Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm index 5d536dd2d2..c8408b3cd1 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm @@ -288,6 +288,7 @@ sub load_common { $self->load_copy_location_groups; $self->staff_saved_searches_set_expansion_state if $ctx->{is_staff}; $self->load_search_filter_groups($ctx->{search_ou}); + $self->load_org_util_funcs; return Apache2::Const::OK; } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm index 660b20ef87..525eebceba 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -594,4 +594,83 @@ sub check_for_temp_list_warning { return $warn; } +sub load_org_util_funcs { + my $self = shift; + my $ctx = $self->ctx; + + # evaluates to true if test_ou is within the same depth- + # scoped tree as ctx_ou. both ou's are org unit objects. + $ctx->{org_within_scope} = sub { + my ($ctx_ou, $test_ou, $depth) = @_; + + return 1 if $ctx_ou->id == $test_ou->id; + + if ($depth) { + + # find the top-most ctx-org ancestor at the provided depth + while ($depth < $ctx_ou->ou_type->depth + and $ctx_ou->id != $test_ou->id) { + $ctx_ou = $ctx->{get_aou}->($ctx_ou->parent_ou); + } + + # the preceeding loop may have landed on our org + return 1 if $ctx_ou->id == $test_ou->id; + + } else { + + return 1 if defined $depth; # $depth == 0; + } + + for my $child (@{$ctx_ou->children}) { + return 1 if $ctx->{org_within_scope}->($child, $test_ou); + } + + return 0; + }; + + # Returns true if the provided org unit is within the same + # org unit hiding depth-scoped tree as the physical location. + # Org unit hiding is based on the immutable physical_loc + # and is not meant to change as search/pref/etc libs change + $ctx->{org_within_hiding_scope} = sub { + my $org_id = shift; + my $ploc = $ctx->{physical_loc} or return 1; + + my $depth = $ctx->{get_org_setting}->( + $ploc, 'opac.org_unit_hiding.depth'); + + return 1 unless $depth; # 0 or undef + + return $ctx->{org_within_scope}->( + $ctx->{get_aou}->($ploc), + $ctx->{get_aou}->($org_id), $depth); + + }; + + # Evaluates to true if the context org (defaults to get_library) + # is not within the hiding scope. Also evaluates to true if the + # user's pref_ou is set and it's out of hiding scope. + # Always evaluates to true when ctx.is_staff + $ctx->{org_hiding_disabled} = sub { + my $ctx_org = shift || $ctx->{search_ou}; + + return 1 if $ctx->{is_staff}; + + # beware locg values formatted as org:loc + $ctx_org =~ s/:.*//g; + + return 1 if !$ctx->{org_within_hiding_scope}->($ctx_org); + + return 1 if $ctx->{pref_ou} and $ctx->{pref_ou} != $ctx_org + and !$ctx->{org_within_hiding_scope}->($ctx->{pref_ou}); + + return 0; + }; + +} + + + + + 1; diff --git a/Open-ILS/src/templates/opac/parts/misc_util.tt2 b/Open-ILS/src/templates/opac/parts/misc_util.tt2 index f29ed96e4e..2695cce58b 100644 --- a/Open-ILS/src/templates/opac/parts/misc_util.tt2 +++ b/Open-ILS/src/templates/opac/parts/misc_util.tt2 @@ -165,7 +165,7 @@ ); END; - ou_hiding_disabled = org_hiding_disabled(); + ou_hiding_disabled = ctx.org_hiding_disabled(); FOR volume IN xml.findnodes('//*[local-name()="volumes"]/*[local-name()="volume"]'); @@ -235,7 +235,7 @@ # extract the circ_lib id from the circ_lib node circ_lib = copy.findnodes('./*[local-name()="circ_lib"]'); circ_lib_id = circ_lib.getAttribute('id').replace('.*/', ''); - NEXT UNLESS org_within_hiding_scope(circ_lib_id); + NEXT UNLESS ctx.org_within_hiding_scope(circ_lib_id); END; holding = { @@ -301,81 +301,4 @@ loc_name = 'locg'; loc_value = CGI.param(loc_name) || CGI.param('loc') || ctx.search_ou; END; - - # evaluates to true if test_ou is within the same depth- - # scoped tree as ctx_ou. both ou's are org unit objects. - MACRO org_within_scope(ctx_ou, test_ou, depth) BLOCK; - IF ctx_ou.id == test_ou.id; - 1; - ELSIF depth == 0; - # there's a party in my org tree and everyone's invited - 1; - ELSE; - # start at the top of the depth-scoped tree - # and search down until we find the test_ou - - IF depth; - WHILE depth < ctx_ou.ou_type.depth AND ctx_ou.id != test_ou.id; - ctx_ou = ctx.get_aou(ctx_ou.parent_ou); - END; - END; - - IF ctx_ou.id == test_ou.id; # may now be a parent org - 1; - ELSE; - - FOR child IN ctx_ou.children; - IF org_within_scope(child, test_ou); - 1; LAST; - END; - END; - END; - END; - END; - - MACRO org_within_hiding_scope(org_id) BLOCK; - # org unit hiding is based on the immutable physical_loc - # and is not meant to change as search/pref/etc libs change - - IF ctx.physical_loc; - - depth = ctx.get_org_setting(ctx.physical_loc, 'opac.org_unit_hiding.depth'); - IF depth; - - org_within_scope( - ctx.get_aou(ctx.physical_loc), - ctx.get_aou(org_id), - depth - ); - - ELSE; # depth is null or 0 - 1; - END; - ELSE; # no physical_loc means no org unit hiding - 1; - END; - END; - - # Evaluates to true if the context org (defaults to get_library) - # is not within the hiding scope. Also evaluates to true if the - # user's pref_ou is set and it's out of hiding scope. - # Always evaluates to true when ctx.is_staff - MACRO org_hiding_disabled(ctx_org) BLOCK; - IF ctx.is_staff; - 1; - ELSE; - SET ctx_org = ctx.search_ou UNLESS ctx_org; - - # beware locg values formatted as org:loc - ctx_org = ctx_org | replace(':.*', ''); - - IF !org_within_hiding_scope(ctx_org); - 1; - - ELSIF ctx.pref_ou AND ctx.pref_ou != ctx_org AND - !org_within_hiding_scope(ctx.pref_ou); - 1; - END; - END; - END; %] diff --git a/Open-ILS/src/templates/opac/parts/org_selector.tt2 b/Open-ILS/src/templates/opac/parts/org_selector.tt2 index 74e848eae2..62b189894a 100644 --- a/Open-ILS/src/templates/opac/parts/org_selector.tt2 +++ b/Open-ILS/src/templates/opac/parts/org_selector.tt2 @@ -22,7 +22,7 @@ BLOCK build_org_selector; # if the selected org unit is out of hiding scope, # disable the ou-hide scoping altogether. - hiding_disabled = org_hiding_disabled(value); + hiding_disabled = ctx.org_hiding_disabled(value); %] @@ -72,7 +72,7 @@ BLOCK build_org_selector; NEXT UNLESS ctx.is_staff OR visible; # org is not within hiding scope (though its children may be). - NEXT UNLESS hiding_disabled OR org_within_hiding_scope(ou_id); + NEXT UNLESS hiding_disabled OR ctx.org_within_hiding_scope(ou_id); node_value = ou_id; IF loc_grp; diff --git a/Open-ILS/src/templates/opac/parts/record/copy_counts.tt2 b/Open-ILS/src/templates/opac/parts/record/copy_counts.tt2 index a479fa6e5a..9a6c695c76 100644 --- a/Open-ILS/src/templates/opac/parts/record/copy_counts.tt2 +++ b/Open-ILS/src/templates/opac/parts/record/copy_counts.tt2 @@ -9,7 +9,7 @@ ou_avail = ctx.copy_summary.$depth.available; ou_id = ctx.copy_summary.$depth.org_unit; cp_org_unit = ctx.get_aou(ou_id); - skip_me = !ou_hiding_disabled AND !org_within_hiding_scope(ou_id); + skip_me = !ou_hiding_disabled AND !ctx.org_within_hiding_scope(ou_id); IF (cp_org_unit.opac_visible == 'f' AND !ctx.is_staff) OR skip_me; depth = depth + 1; NEXT; diff --git a/Open-ILS/src/templates/opac/parts/record/summary.tt2 b/Open-ILS/src/templates/opac/parts/record/summary.tt2 index a5767a1f23..65c516cfb6 100644 --- a/Open-ILS/src/templates/opac/parts/record/summary.tt2 +++ b/Open-ILS/src/templates/opac/parts/record/summary.tt2 @@ -112,8 +112,20 @@ IF num_uris > 0;

[% l('Current holds') %]

- [%- l("[quant,_1,current hold,current holds] with [quant,_2,total copy,total copies].", - ctx.record_hold_count, ctx.copy_summary.0.count) %] + [% + # If org hiding is enabled/relevant, only show + # counts for copies within the hiding scope. + count_entry = 0; + FOR count_chunk IN ctx.copy_summary; + IF ctx.org_within_hiding_scope(count_chunk.org_unit); + # always true when hiding is disabled + LAST; + END; + count_entry = count_entry + 1; + END; + l("[quant,_1,current hold,current holds] with [quant,_2,total copy,total copies].", + ctx.record_hold_count, ctx.copy_summary.$count_entry.count) + %]

[%- INCLUDE "opac/parts/record/copy_table.tt2" copies=ctx.copies %] diff --git a/Open-ILS/src/templates/opac/parts/result/copy_counts.tt2 b/Open-ILS/src/templates/opac/parts/result/copy_counts.tt2 index c04bdb2dbc..dc8aab797c 100644 --- a/Open-ILS/src/templates/opac/parts/result/copy_counts.tt2 +++ b/Open-ILS/src/templates/opac/parts/result/copy_counts.tt2 @@ -1,13 +1,13 @@ [%- depths = attrs.copy_counts.size; depth = 0; displayed_ous = {}; - hiding_disabled = org_hiding_disabled(); + hiding_disabled = ctx.org_hiding_disabled(); WHILE depth < depths; org_unit = ctx.get_aou(attrs.copy_counts.$depth.org_unit); ou_name = org_unit.name; displayed_ous.$ou_name = 1; IF attrs.copy_counts.$depth.count > 0 AND ( - hiding_disabled OR org_within_hiding_scope(org_unit.id)); + hiding_disabled OR ctx.org_within_hiding_scope(org_unit.id)); %]
[% IF ctx.get_aou(attrs.copy_counts.$depth.org_unit).opac_visible == 't' %] @@ -29,7 +29,7 @@ %] [%- IF attrs.plib_copy_counts.$depth.count > 0 AND ( - hiding_disabled OR org_within_hiding_scope(org_unit.id)) %] + hiding_disabled OR ctx.org_within_hiding_scope(org_unit.id)) %]
[% l('[_1] of [quant,_2,copy,copies] available at [_3].', attrs.plib_copy_counts.$depth.available,