Skip to content

Commit

Permalink
Merge pull request #343 from ctfliblime/PT26875895-patroncats_4.10
Browse files Browse the repository at this point in the history
[#26875895] Fixes related to ConstrainPatronsDeeply
  • Loading branch information
ctfliblime committed Apr 3, 2012
2 parents 10dd9f9 + df3c979 commit 6c1610f
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 15 deletions.
1 change: 1 addition & 0 deletions cgi/admin/systempreferences.pl
Expand Up @@ -274,6 +274,7 @@ =head1 systempreferences.pl
$tabsysprefs{MaxShelfHoldsPerDay} = "Patrons";
$tabsysprefs{EnableOwedNotification} = "Patrons";
$tabsysprefs{UsePatronBranchForPatronInfo} = "Patrons";
$tabsysprefs{ConstrainPatronsDeeply} = "Patrons";

# I18N/L10N
$tabsysprefs{dateformat} = "I18N/L10N";
Expand Down
17 changes: 16 additions & 1 deletion cgi/circ/circulation.pl
Expand Up @@ -339,10 +339,25 @@ sub FormatFinesSummary {
}

$borrower = GetMemberDetails( $borrowernumber, 0, $circ_session );

if ( $borrower
&& C4::Branch::CategoryTypeIsUsed('patrons')
&& C4::Members::ConstrainPatronSearch())
{
my $agent = C4::Members::GetMember($loggedinuser);
$borrower = undef
unless C4::Branch::BranchesAreSiblings(
$borrower->{branchcode}, $agent->{branchcode}, 'patrons');
}
unless (defined $borrower) {
output_html_with_http_headers $query, $cookie, $template->output;
exit;
}

if ( $circ_session->{'override_user'} ) {
$template->param( flagged => 1 );
}

## Store data for last scanned borrower in cookies for future use.
my $lbb = $query->cookie(-name=>'last_borrower_borrowernumber', -value=>"$borrowernumber", -expires=>'+1y');
my $lbc = $query->cookie(-name=>'last_borrower_cardnumber', -value=>"$borrower->{'cardnumber'}", -expires=>'+1y');
Expand Down
14 changes: 14 additions & 0 deletions cgi/members/holdhistory.pl
Expand Up @@ -47,6 +47,20 @@

#get borrower details
my $data=GetMember($borrowernumber,'borrowernumber');
if ( $data
&& C4::Branch::CategoryTypeIsUsed('patrons')
&& C4::Members::ConstrainPatronSearch())
{
my $agent = C4::Members::GetMember($loggedinuser);
$data = undef
unless C4::Branch::BranchesAreSiblings(
$data->{branchcode}, $agent->{branchcode}, 'patrons');
}
unless (defined $data) {
output_html_with_http_headers $input, $cookie, $template->output;
exit;
}

$template->param(
borrowernumber => $data->{'borrowernumber'},
firstname => $data->{'firstname'},
Expand Down
22 changes: 15 additions & 7 deletions cgi/members/moremember.pl
Expand Up @@ -89,17 +89,25 @@ BEGIN
);
my $borrowernumber = $input->param('borrowernumber');

#start the page and read in includes
my $data = GetMember( $borrowernumber ,'borrowernumber');
my $roaddetails = GetRoadTypeDetails( $data->{'streettype'} );
my $reregistration = $input->param('reregistration');

if ( not defined $data ) {
my $data = GetMember( $borrowernumber ,'borrowernumber');
if ( $data
&& C4::Branch::CategoryTypeIsUsed('patrons')
&& C4::Members::ConstrainPatronSearch())
{
my $agent = C4::Members::GetMember($loggedinuser);
$data = undef
unless C4::Branch::BranchesAreSiblings(
$data->{branchcode}, $agent->{branchcode}, 'patrons');
}
unless (defined $data) {
$template->param (unknowuser => 1);
output_html_with_http_headers $input, $cookie, $template->output;
output_html_with_http_headers $input, $cookie, $template->output;
exit;
}

my $roaddetails = GetRoadTypeDetails( $data->{'streettype'} );
my $reregistration = $input->param('reregistration');

# re-reregistration function to automatic calcul of date expiry
if ( $reregistration && $reregistration eq 'y' ) {
$data->{'dateexpiry'} = ExtendMemberSubscriptionTo( $borrowernumber );
Expand Down
14 changes: 14 additions & 0 deletions cgi/members/readingrec.pl
Expand Up @@ -43,6 +43,20 @@
my $borrowernumber=$input->param('borrowernumber');
#get borrower details
my $data=GetMember($borrowernumber,'borrowernumber');
if ( $data
&& C4::Branch::CategoryTypeIsUsed('patrons')
&& C4::Members::ConstrainPatronSearch())
{
my $agent = C4::Members::GetMember($loggedinuser);
$data = undef
unless C4::Branch::BranchesAreSiblings(
$data->{branchcode}, $agent->{branchcode}, 'patrons');
}
unless (defined $data) {
output_html_with_http_headers $input, $cookie, $template->output;
exit;
}

my $order=$input->param('order') || '';
my $order2=$order;
if ($order2 eq ''){
Expand Down
6 changes: 6 additions & 0 deletions installer/data/syspref_defaults.json
@@ -1,4 +1,10 @@
{
"ConstrainPatronsDeeply" : {
"explanation" : "When using patron categories, hide non-local patrons not only from search but from access within Koha modules. Has no effect unless patron groups are enabled.",
"options" : null,
"value" : "1",
"type" : "YesNo"
},
"KeepPreviousBorrowerInterval" : {
"explanation" : "Number of days that must pass before the previous borrower is expunged from old issues if that item has not since been checked out.",
"options" : null,
Expand Down
6 changes: 6 additions & 0 deletions lib/C4/Branch.pm
Expand Up @@ -428,6 +428,12 @@ sub GetSiblingBranchesOfType {
return @branchcodes;
}

sub BranchesAreSiblings {
my ($b1code, $b2code, $categorytype) = @_;
my @b1_group = GetSiblingBranchesOfType($b1code, $categorytype);
return $b2code ~~ @b1_group;
}

=head2 GetBranch
$branch = GetBranch( $query, $branches );
Expand Down
19 changes: 12 additions & 7 deletions lib/C4/Members.pm
Expand Up @@ -175,13 +175,16 @@ C<$count> is the number of elements in C<$borrowers>.
=cut

sub ConstrainPatronSearch {
return (C4::Branch::CategoryTypeIsUsed('patrons')
&& $ENV{REQUEST_METHOD} # need a nicer way to do this, but check if we're command line vs. CGI
&& !C4::Auth::haspermission(undef, {superlibrarian => 1})) ? 1 : 0;
}

sub _constrain_sql_by_branchcategory {
my ($query, @bind) = @_;

if ( C4::Branch::CategoryTypeIsUsed('patrons')
&& $ENV{REQUEST_METHOD} # need a nicer way to do this, but check if we're command line vs. CGI
&& !C4::Auth::haspermission(undef, {superlibrarian => 1})
)
if (ConstrainPatronSearch())
{
my $mybranch = (C4::Context->userenv) ? C4::Context->userenv->{branch} : undef;
confess 'Unable to determine selected branch' if not $mybranch;
Expand Down Expand Up @@ -377,8 +380,9 @@ sub GetMemberDetails {
else {
return;
}
($sql, @params) = _constrain_sql_by_branchcategory($sql, @params);

($sql, @params) = _constrain_sql_by_branchcategory($sql, @params)
if C4::Context->preference('ConstrainPatronsDeeply');

my $borrower = $dbh->selectrow_hashref($sql, undef, @params);
return if !$borrower;

Expand Down Expand Up @@ -581,7 +585,8 @@ sub GetMember {
WHERE $type = ?
};
my @params = ($information);
($select, @params) = _constrain_sql_by_branchcategory($select, @params);
($select, @params) = _constrain_sql_by_branchcategory($select, @params)
if C4::Context->preference('ConstrainPatronsDeeply');
my $borrower = C4::Context->dbh->selectrow_hashref($select, undef, @params);
return undef if !$borrower;

Expand Down

0 comments on commit 6c1610f

Please sign in to comment.