From dcf9cb39d3243ea3a59035c150d521cf5816b9c8 Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Mon, 22 Oct 2012 18:02:23 -0400 Subject: [PATCH] TPAC: First part of locg param can be branch shortname Addresses LP #1020625. You can use the locg param, which can set an an OU for search context (and which has other implications related to location/scope) by shortname now. As long as your shortnames are something that work in an HTTP query string, don't contain colons, and as long as you don't have numeric shortnames for any orgs that would mask orgs with the sames numbers as an ID (but that would be a lousy setup anyway), this should work. Now case insensitive per recommendation by Michael Peters. In the event that you have org units with names that are the same except for case (probably a bad practice), the locg parameter will simply fail to set your context, rather than try to guess which org unit you meant. Signed-off-by: Lebbeous Fogle-Weekley Signed-off-by: Pasi Kallinen Signed-off-by: Dan Scott Conflicts: Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm --- .../lib/OpenILS/WWW/EGCatLoader/Util.pm | 35 ++++++++++++++++++- .../src/templates/opac/parts/misc_util.tt2 | 3 +- 2 files changed, 36 insertions(+), 2 deletions(-) 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 93cc3e120d..fa6b473ed9 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -347,6 +347,30 @@ sub get_records_and_facets { return ($facets, @data); } +sub _resolve_org_id_or_shortname { + my ($self, $str) = @_; + + if (length $str) { + # Match on shortname case insensitively, but only if there's exactly + # one match. We wouldn't want the system to arbitrarily interpret + # 'foo' as either the org unit with shortname 'FOO' or 'Foo' and fail + # to make it clear to the user which one was chosen and why. + my $res = $self->editor->search_actor_org_unit({ + shortname => { + '=' => { + transform => 'evergreen.lowercase', + value => lc($str) + } + } + }); + return $res->[0]->id if $res and @$res == 1; + } + + # Note that we don't validate IDs; we only try a shortname lookup and then + # assume anything else must be an ID. + return int($str); # Wrapping in int() prevents 500 on unmatched string. +} + sub _get_search_lib { my $self = shift; my $ctx = $self->ctx; @@ -358,6 +382,14 @@ sub _get_search_lib { return $loc if $loc; # loc param takes precedence + # XXX ^-- over what exactly? We could use clarification here. To me it looks + # like locg takes precedence over loc which in turn takes precedence over + # request headers which take precedence over pref_lib (which can be + # specified a lot of different ways and eventually falls back to + # physical_loc) and it all finally defaults to top of the org tree. + # To say nothing of all the code that doesn't look to this function at all + # but rather accesses some subset of these inputs directly. + $loc = $self->cgi->param('loc'); return $loc if $loc; @@ -445,7 +477,8 @@ sub extract_copy_location_group_info { my $ctx = $self->ctx; if (my $clump = $self->cgi->param('locg')) { my ($org, $grp) = split(/:/, $clump); - $ctx->{copy_location_group_org} = $org; + $ctx->{copy_location_group_org} = + $self->_resolve_org_id_or_shortname($org); $ctx->{copy_location_group} = $grp if $grp; } } diff --git a/Open-ILS/src/templates/opac/parts/misc_util.tt2 b/Open-ILS/src/templates/opac/parts/misc_util.tt2 index a1dbb94f0a..63d6b44114 100644 --- a/Open-ILS/src/templates/opac/parts/misc_util.tt2 +++ b/Open-ILS/src/templates/opac/parts/misc_util.tt2 @@ -420,7 +420,8 @@ # which is a superset of 'loc'. BLOCK get_library; loc_name = 'locg'; - loc_value = CGI.param(loc_name) || CGI.param('loc') || ctx.search_ou; + loc_value = ctx.copy_location_group_org || # resolved locg + CGI.param(loc_name) || CGI.param('loc') || ctx.search_ou; END; %] -- 2.43.2