Add configurable mapping of patron profile names
authorJeff Godin <jgodin@tadl.org>
Wed, 21 Aug 2013 21:42:21 +0000 (17:42 -0400)
committerJeff Godin <jgodin@tadl.org>
Wed, 21 Aug 2013 21:45:09 +0000 (17:45 -0400)
Support mapping patron profile names to new values using a
"userpriv" file.

This is a re-implementation of a feature from MCLS / Jon Scott code
received via e-mail.

See userpriv-example for an example mapping file.

Signed-off-by: Jeff Godin <jgodin@tadl.org>
iNCIPit-example.ini
iNCIPit.cgi
userpriv-example [new file with mode: 0644]

index 5a2d3e8..68d5b83 100644 (file)
@@ -23,6 +23,7 @@ init_pickup_lib = 2
 [path]
 oils_header  = /openils/bin/support-scripts/oils_header.pl
 opensrf_core = /openils/conf/opensrf_core.xml
+userpriv_map = userpriv
 
 [status]
 loan_requested = 110
index 3610fd1..e701df5 100644 (file)
@@ -126,6 +126,31 @@ sub load_config {
     return $Config;
 }
 
+# load and parse userpriv_map file, returning a hashref
+sub load_userpriv_map {
+    my $filename = shift;
+    my $map = {};
+    if (open(my $fh, "<", $filename)) {
+        while (my $entry = <$fh>) {
+            chomp($entry);
+            my ($from, $to) = split(m/:/, $entry);
+            $map->{$from} = $to;
+        }
+        close $fh;
+    }
+    return $map;
+}
+
+sub lookup_userpriv {
+    my $input = shift;
+    my $map = shift;
+    if (defined($map->{$input})) { # if we have a mapping for this profile
+        return $map->{$input}; # return value from mapping hash
+    } else {
+        return $input; # return original value
+    }
+}
+
 sub logit {
     my ( $msg, $func, $more_info ) = @_;
     open RESP_DATA, ">>resp_data.txt";
@@ -856,6 +881,12 @@ sub lookupUser {
     $good_until = $patron->expire_date || "unknown";
     $userpriv = $patron->profile->name;
 
+    my $userpriv_map = load_userpriv_map( $conf->{path}->{userpriv_map} );
+
+    if ($userpriv_map) {
+        $userpriv = lookup_userpriv($userpriv);
+    }
+
     #} else {
     #    do_lookup_user_error_stanza("PATRON_NOT_FOUND : $id");
     #    die;
diff --git a/userpriv-example b/userpriv-example
new file mode 100644 (file)
index 0000000..902ab68
--- /dev/null
@@ -0,0 +1,3 @@
+Staff:Patrons
+Catalogers:Patrons
+Circulators:Patrons