LP14973322: Search for Users by Profile
authorJason Boyer <jboyer@library.in.gov>
Fri, 20 Apr 2018 18:49:25 +0000 (14:49 -0400)
committerMike Rylander <mrylander@gmail.com>
Tue, 22 May 2018 19:54:35 +0000 (15:54 -0400)
Stop treating profile like a text value, instead
include users in the selected profiles and descendants.

To test
-------
[0] Search for users by last name (and / or first) and do not
    select a profile, take note of results
[1] Select the top of your permission group tree (Users, likely) and
    search again, results should be the same.
[2] Select a group further down the tree (Circulators, Administrators,
    Patrons, etc.) and repeat the search, there should only be results
    from that group and its descendants.
[3] Finally, select a group with no child groups. Results will only be
    that specific group.

Signed-off-by: Jason Boyer <jboyer@library.in.gov>
Signed-off-by: Terran McCanna <tmccanna@georgialibraries.org>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Mike Rylander <mrylander@gmail.com>

Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/actor.pm
Open-ILS/web/js/ui/default/staff/services/patron_search.js

index a1e634d..134821a 100644 (file)
@@ -677,6 +677,7 @@ sub patron_search {
     # group 2 = phone, ident
     # group 3 = barcode
     # group 4 = dob
+    # group 5 = profile
 
     # Treatment of name fields depends on whether the org has 
     # diacritic_insensitivity turned on or off.
@@ -718,6 +719,10 @@ sub patron_search {
     my $addr = join ' AND ', map { "evergreen.lowercase(CAST($_ AS text)) ~ ?" } grep { ''.$$search{$_}{group} eq '1' } keys %$search;
     my @addrv = map { "^" . _clean_regex_chars($$search{$_}{value}) } grep { ''.$$search{$_}{group} eq '1' } keys %$search;
 
+    # should only be 1 profile sent but this construction makes dealing with the lists simpler.
+    my ($prof) = map { $$search{$_}{value} } grep {''.$$search{$_}{group} eq '5' } keys %$search;
+    $prof = int($prof) if $prof; # int or out
+
     my $pv = _clean_regex_chars($$search{phone}{value});
     my $iv = _clean_regex_chars($$search{ident}{value});
     my $nv = _clean_regex_chars($$search{name}{value});
@@ -816,6 +821,7 @@ sub patron_search {
     }
 
     my $descendants = "actor.org_unit_descendants($search_org)";
+    my $profile = "JOIN permission.grp_descendants($prof) p ON (p.id = users.profile)" if $prof;
 
     my $opt_in_where = '';
     if (lc($strict_opt_in) eq 'true') {
@@ -843,6 +849,7 @@ sub patron_search {
         SELECT  $distinct_list
           FROM  $u_table AS users $card
             JOIN $descendants d ON (d.id = users.home_ou)
+            $profile
             $select
             $clone_select
             $penalty_join
index f19678f..b0f1bed 100644 (file)
@@ -775,7 +775,7 @@ function($scope,  $q,  $routeParams,  $timeout,  $window,  $location,  egCore,
         angular.forEach(args, function(val, key) {
             if (!val) return;
             if (key == 'profile' && args.profile) {
-                search.profile = {value : args.profile.id(), group : 0};
+                search.profile = {value : args.profile.id(), group : 5};
             } else if (key == 'home_ou' && args.home_ou) {
                 search.home_ou = args.home_ou.id(); // passed separately
             } else if (key == 'inactive') {