Bugzilla – Attachment 157122 Details for
Bug 31503
Allow several consent types on the consents tab of OPAC account page
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31503: (follow-up) Add 'feature_enabled' to Koha::Plugins
Bug-31503-follow-up-Add-featureenabled-to-KohaPlug.patch (text/plain), 4.39 KB, created by
Marcel de Rooy
on 2023-10-13 15:37:15 UTC
(
hide
)
Description:
Bug 31503: (follow-up) Add 'feature_enabled' to Koha::Plugins
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2023-10-13 15:37:15 UTC
Size:
4.39 KB
patch
obsolete
>From 4bb54677355185467fb84c19afb3a2371200c08f Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Fri, 15 Sep 2023 16:09:56 +0100 >Subject: [PATCH] Bug 31503: (follow-up) Add 'feature_enabled' to Koha::Plugins >Content-Type: text/plain; charset=utf-8 > >This patch adds a 'feature_enabled' accessor to the Koha::Plugins class. >Passing the plugin method name for the plugin feature you're looking for >will return a boolean denoting whether any enabled plugins carry said >method. > >Included in the patch is an addition to the TT KohaPlugins plugin to >enable quick access to this function. > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> > >[EDIT] Tidied t/db_dependent/Koha/Plugins/Plugins.t >[EDIT] Tidied Koha/Template/Plugin/KohaPlugins.pm > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > Koha/Plugins.pm | 24 +++++++++++++++++++ > Koha/Template/Plugin/KohaPlugins.pm | 17 ++++++++++++++ > t/db_dependent/Koha/Plugins/Plugins.t | 34 ++++++++++++++++++++++++++- > 3 files changed, 74 insertions(+), 1 deletion(-) > >diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm >index a3c47006b5..520f2febf2 100644 >--- a/Koha/Plugins.pm >+++ b/Koha/Plugins.pm >@@ -139,6 +139,30 @@ sub get_enabled_plugins { > return @$enabled_plugins; > } > >+ >+=head2 feature_enabled >+ >+Returns a boolean denoting whether a plugin based feature is enabled or not. >+ >+ $enabled = Koha::Plugins->feature_enabled('method_name'); >+ >+=cut >+ >+sub feature_enabled { >+ my ( $class, $method ) = @_; >+ >+ return 0 unless C4::Context->config('enable_plugins'); >+ >+ my $key = "ENABLED_PLUGIN_FEATURE_" . $method; >+ my $feature = Koha::Cache::Memory::Lite->get_from_cache($key); >+ unless ( defined($feature) ) { >+ my @plugins = $class->get_enabled_plugins(); >+ my $enabled = any { $_->can($method) } @plugins; >+ Koha::Cache::Memory::Lite->set_in_cache( $key, $enabled ); >+ } >+ return $feature; >+} >+ > =head2 GetPlugins > > This will return a list of all available plugins, optionally limited by >diff --git a/Koha/Template/Plugin/KohaPlugins.pm b/Koha/Template/Plugin/KohaPlugins.pm >index 7d527b34e3..9b2adb7d72 100644 >--- a/Koha/Template/Plugin/KohaPlugins.pm >+++ b/Koha/Template/Plugin/KohaPlugins.pm >@@ -282,4 +282,21 @@ sub get_plugins_opac_cover_images { > return join( "\n", @data ); > } > >+=head3 feature_enabled >+ >+ [% KohaPlugins.feature_enabled('method_name') %] >+ >+This method returns true if the passed plugin hook method name is found to be installed and enabled as part of a plugin. >+ >+=cut >+ >+sub feature_enabled { >+ my ( $self, $method ) = @_; >+ >+ my $p = Koha::Plugins->new; >+ return 0 unless $p; >+ >+ return $p->feature_enabled($method); >+} >+ > 1; >diff --git a/t/db_dependent/Koha/Plugins/Plugins.t b/t/db_dependent/Koha/Plugins/Plugins.t >index db68b9d195..a629bf0123 100755 >--- a/t/db_dependent/Koha/Plugins/Plugins.t >+++ b/t/db_dependent/Koha/Plugins/Plugins.t >@@ -25,7 +25,7 @@ use File::Temp qw( tempdir tempfile ); > use FindBin qw($Bin); > use Module::Load::Conditional qw(can_load); > use Test::MockModule; >-use Test::More tests => 61; >+use Test::More tests => 62; > use Test::Warn; > > use C4::Context; >@@ -129,6 +129,38 @@ subtest 'more call() tests' => sub { > $schema->storage->txn_rollback; > }; > >+subtest 'feature_enabled tests' => sub { >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ # Temporarily remove any installed plugins data >+ Koha::Plugins::Methods->delete; >+ $schema->resultset('PluginData')->delete(); >+ >+ t::lib::Mocks::mock_config( 'enable_plugins', 0 ); >+ my $enabled = Koha::Plugins->feature_enabled('check_password'); >+ ok( !$enabled, "check_password not available when plugins are disabled" ); >+ >+ t::lib::Mocks::mock_config( 'enable_plugins', 1 ); >+ my $plugins = Koha::Plugins->new( { enable_plugins => 1 } ); >+ >+ my @plugins; >+ warning_is { @plugins = $plugins->InstallPlugins; } undef; >+ >+ $enabled = Koha::Plugins->feature_enabled('check_password'); >+ ok( !$enabled, "check_password not available when plugins are installed but not enabled" ); >+ >+ foreach my $plugin (@plugins) { >+ $plugin->enable(); >+ } >+ >+ $enabled = Koha::Plugins->feature_enabled('check_password'); >+ ok( $enabled, "check_password is available when at least one enabled plugin supports it" ); >+ >+ $schema->storage->txn_rollback; >+}; >+ > subtest 'GetPlugins() tests' => sub { > > plan tests => 3; >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 31503
:
140047
|
140048
|
140049
|
140050
|
140080
|
140081
|
140082
|
140083
|
140084
|
140085
|
140087
|
140088
|
140089
|
140090
|
140666
|
140667
|
140668
|
140669
|
140670
|
140671
|
140672
|
141216
|
141217
|
141218
|
141219
|
141220
|
141221
|
141222
|
141263
|
141264
|
141265
|
141266
|
141267
|
141268
|
141269
|
141302
|
141570
|
155000
|
155001
|
155002
|
155003
|
155177
|
155178
|
155179
|
155180
|
155189
|
155190
|
155191
|
155656
|
155657
|
155658
|
155659
|
155660
|
155661
|
155691
|
155694
|
155783
|
155784
|
155785
|
155786
|
155787
|
155788
|
155789
|
155790
|
155791
|
157117
|
157118
|
157119
|
157120
|
157121
|
157122
|
157123
|
157124
|
157125
|
157126
|
157773
|
157774
|
157775
|
157776
|
157777
|
157778
|
157779
|
157780
|
157781
|
157782
|
157783