Bug 41674: Add template plugin for linking to system preferences based on user permission

This patch adds a new template plugin, LinkPref, for displaying system
preference names as links depending on the logged-in user's permission.

Syntax:

  [% "SYSTEM_PREFERENCE_NAME" | html | $LinkPref %]

For a user with 'CAN_user_parameters_manage_sysprefs' permission it
outputs:

  <a class="link_preference" href="admin/preferences.pl?op=search&amp;ok=Search&amp;searchfield=SYSTEM_PREFERENCE_NAME">SYSTEM_PREFERENCE_NAME</a>

For a user without permission it outputs:

  <span class="link_preference">SYSTEM_PREFERENCE_NAME</span>

Sponsored-by: Athens County Public Libraries
Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
Owen Leonard 2026-01-21 09:19:08 -05:00 committed by Pedro Amorim
parent 106fabbf9a
commit 797c1b352e
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
1 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,69 @@
package Koha::Template::Plugin::LinkPref;
# Copyright Athens County Public Libraries 2026
# Author: Owen Leonard <oleonard@myacpl.org>
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <https://www.gnu.org/licenses>.
use Modern::Perl;
use Koha::Patrons;
use Template::Plugin::Filter;
use base qw( Template::Plugin::Filter );
our $DYNAMIC = 1;
sub filter {
my ( $self, $text ) = @_;
return "" unless $text;
my $span;
if ( $self->{_CONTEXT}->stash->{'CAN_user_parameters_manage_sysprefs'} ) {
$span .= '<a class="link_preference" href="/cgi-bin/koha/admin/preferences.pl?op=search&ok=Search&searchfield=';
$span .= $text;
$span .= '">';
$span .= $text;
$span .= '</a>';
} else {
$span .= '<span class="link_preference">';
$span .= $text;
$span .= '</span>';
}
return $span;
}
1;
=head1 NAME
Koha::Template::Plugin::LinkPref - TT plugin for wrapping a system preference name in a link to that preference if the user has permission
=head1 SYNOPSIS
[% USE LinkPref %]
[% "SYSTEM_PREFERENCE_NAME" | html | $LinkPref %]
This filter scrubs HTML using profiles predefined in C4::Scrubber
=head1 METHODS
=head2 filter
Returns the system preference variable name as an HTML link or plain text based on the logged-in user's permissions
=cut