Bug 8492 [ENH] Restrict OpacSuppression to IP adresses outside of an IP range
authorMirko Tietgen <5p4m@gmx.de>
Mon, 23 Jul 2012 23:31:28 +0000 (01:31 +0200)
committerPaul Poulain <paul.poulain@biblibre.com>
Mon, 3 Sep 2012 09:56:21 +0000 (11:56 +0200)
This enhancement extends the OpacSuppression feature with an optional IP address range within which results are _not_ suppressed.

To test

* turn on OpacSuppression (Administration->System preferences->Cataloging) and enter an IP address range in the OpacSuppressionByIPRange field.
* set at least one bibliographic record to suppress=1 (enter '1' in 942$n)
* fully reindex your data
* do an OPAC search that should bring up your suppressed record
* try with IP ranges that match your IP and ranges that don't

Signed-off-by: Marc Veron <veron@veron.ch>
Tested following the scenario above. Works as expected.

installer/data/mysql/sysprefs.sql
installer/data/mysql/updatedatabase.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/cataloguing.pref
opac/opac-search.pl

index 7219e37..5c1a5b6 100644 (file)
@@ -366,3 +366,4 @@ INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES (
 INSERT INTO systempreferences (variable,value,explanation,type) VALUES('EnableBorrowerFiles','0','If enabled, allows librarians to upload and attach arbitrary files to a borrower record.','YesNo');
 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('UpdateTotalIssuesOnCirc','0','Whether to update the totalissues field in the biblio on each circ.',NULL,'YesNo');
 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('IntranetSlipPrinterJS','','Use this JavaScript for printing slips. Define at least function printThenClose(). For use e.g. with Firefox PlugIn jsPrintSetup, see http://jsprintsetup.mozdev.org/','','Free');
+INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacSuppressionByIPRange','','Restrict the suppression to IP adresses outside of the IP range','','free');
index e58c4c9..99610d7 100755 (executable)
@@ -5657,6 +5657,13 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion ($DBversion);
 }
 
+$DBversion = '3.09.00.033';
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+   $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacSuppressionByIPRange','','Restrict the suppression to IP adresses outside of the IP range','','free');");
+   print "Upgrade to $DBversion done (Add OpacSuppressionByIPRange syspref)\n";
+   SetVersion ($DBversion);
+}
+
 =head1 FUNCTIONS
 
 =head2 TableExists($table)
index c683da7..e4b871b 100644 (file)
@@ -142,4 +142,8 @@ Cataloging:
                   yes: Hide
                   no: "Don't hide"
             - items marked as suppressed from OPAC search results. Note that you must have the <code>Suppress</code> index set up in Zebra and at least one suppressed item, or your searches will be broken.
+            - Restrict the suppression to IP adresses outside of the IP range
+            - pref: OpacSuppressionByIPRange
+              class: short
+            - (Leave blank if not used. Define a range like <code>192.168.</code>.)
 
index 1e5a0d7..82b35d2 100755 (executable)
@@ -449,7 +449,17 @@ my @limit_inputs = $limit_cgi ? _input_cgi_parse($limit_cgi) : ();
 #
 # add OPAC suppression - requires at least one item indexed with Suppress
 if (C4::Context->preference('OpacSuppression')) {
-    $query = "($query) not Suppress=1";
+    # OPAC suppression by IP address
+    if (C4::Context->preference('OpacSuppressionByIPRange')) {
+        my $IPAddress = $ENV{'REMOTE_ADDR'};
+        my $IPRange = C4::Context->preference('OpacSuppressionByIPRange');
+        if ($IPAddress !~ /^$IPRange/)  {
+            $query = "($query) not Suppress=1";
+        }
+    }
+    else {
+        $query = "($query) not Suppress=1";
+    }
 }
 
 $template->param ( LIMIT_INPUTS => \@limit_inputs );