Bug 25672: Use enable_plugin_browser_upload flag to control plugin upload

This patch adds a enable_plugin_browser_upload flag to koha-conf.xml, which
controls whether or not Koha intranet users can upload Koha plugins via
their browser. Like "enable_plugins", it defaults to 0 for new installs.

This is useful when you want to provide Koha intranet users with plugins
that are pre-installed by administrators (by CLI) or restricting them
to plugins from a Github repo. See the following for more information:
Bug 23975 - Add ability to search and install plugins from GitHub
Bug 23191 - Administrators should be able to install plugins from the command line

To test:
1) Apply the full patchset
2) Confirm <enable_plugins>1</enable_plugins> is present in koha-conf.xml
3) Add <plugins_restricted>1</plugins_restricted> to koha-conf.xml
4) Ensure that the <plugin_repos> block is not commented and contains at
   least one trusted organisation in koha-conf.xml
   If needed get it from: debian/templates/koha-conf-site.xml.in
5) Run restart_all (in koha-testing-docker)
6) Go to /cgi-bin/koha/plugins/plugins-home.pl and note that you don't see
   an option to upload plugins
7) You should however see a search option and upon search you should have
   results returned from the chosen trusted organisations listed in the
   <plugin_repos> block mentioned above.
8) Clicking install on one of the results should work as expected and install
   the plugin.
9) Go directly to /cgi-bin/koha/plugins/plugins-upload.pl and note that it says
   "Plugin upload is restricted to only those plugins listed by your server
   administrator" and gives instructions on how to enable unrestricted browser
   upload.

Signed-off-by: Nicolas Legrand <nicolas.legrand@bulac.fr>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: David Cook <dcook@prosentient.com.au>
Rebased-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
David Cook 2020-07-08 11:53:54 +00:00 committed by Tomas Cohen Arazi
parent 24ee60cb62
commit e2e61ec6ca
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
6 changed files with 17 additions and 3 deletions

View file

@ -266,6 +266,7 @@ __END_SRU_PUBLICSERVER__
<authorityservershadow>1</authorityservershadow>
<pluginsdir>__PLUGINS_DIR__</pluginsdir> <!-- This entry can be repeated to use multiple directories -->
<enable_plugins>0</enable_plugins>
<enable_plugin_browser_upload>0</enable_plugin_browser_upload>
<upload_path>__UPLOAD_PATH__</upload_path>
<tmp_path>__TMP_PATH__</tmp_path>
<intranetdir>/usr/share/koha/intranet/cgi-bin</intranetdir>

View file

@ -79,6 +79,7 @@
<authorityservershadow>1</authorityservershadow>
<pluginsdir>__PLUGINS_DIR__</pluginsdir> <!-- This entry can be repeated to use multiple directories -->
<enable_plugins>0</enable_plugins>
<enable_plugin_browser_upload>0</enable_plugin_browser_upload>
<upload_path></upload_path>
<tmp_path></tmp_path>
<intranetdir>__INTRANET_CGI_DIR__</intranetdir>

View file

@ -29,9 +29,13 @@
<div class="container-fluid">
<div class="row">
<div class="col-sm-6 col-sm-offset-3 col-md-6 col-md-offset-3">
[% IF ( browser_upload_enabled.defined ) && ( browser_upload_enabled == 0 ) %]
<h1>Plugin browser upload disabled</h1>
<p>To enable Koha plugin browser upload, the flag enable_plugin_browser_upload must be set in the Koha configuration file</p>
[% ELSE %]
<h1>Plugins disabled</h1>
<p>To enable Koha plugins, the flag enable_plugins must be set in the Koha configuration file</p>
[% END %]
</div>
</div>

View file

@ -46,7 +46,9 @@
[% IF ( CAN_user_plugins_manage ) %]
<div class="btn-toolbar" id="toolbar">
[% IF ( enable_browser_upload ) %]
<a href="/cgi-bin/koha/plugins/plugins-upload.pl" id="upload_plugin" class="btn btn-default"><i class="fa fa-upload"></i> Upload plugin</a>
[% END %]
<div class="btn-group">
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown"><i class="fa-solid fa-eye"></i> View plugins by class <span class="caret"></span></button>

View file

@ -59,6 +59,7 @@ if ($plugins_enabled) {
);
$template->param( plugins => \@plugins, );
$template->param( enable_browser_upload => C4::Context->config('enable_plugin_browser_upload') );
$template->param( can_search => C4::Context->config('plugin_repos') ? 1 : 0 );
my @results;

View file

@ -31,17 +31,22 @@ use Koha::Logger;
use Koha::Plugins;
my $plugins_enabled = C4::Context->config("enable_plugins");
my $browser_upload_enabled = C4::Context->config('enable_plugin_browser_upload');
my $input = CGI->new;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{ template_name => ($plugins_enabled) ? "plugins/plugins-upload.tt" : "plugins/plugins-disabled.tt",
{ template_name => ($plugins_enabled && $browser_upload_enabled) ? "plugins/plugins-upload.tt" : "plugins/plugins-disabled.tt",
query => $input,
type => "intranet",
flagsrequired => { plugins => 'manage' },
}
);
if ($plugins_enabled){
$template->param( browser_upload_enabled => $browser_upload_enabled );
}
my $uploadfilename = $input->param('uploadfile');
my $uploadfile = $input->upload('uploadfile');
my $uploadlocation = $input->param('uploadlocation');
@ -51,7 +56,7 @@ my ( $tempfile, $tfh );
my %errors;
if ($plugins_enabled) {
if ($plugins_enabled && $browser_upload_enabled) {
if ( ( $op eq 'Upload' ) && ( $uploadfile || $uploadlocation ) ) {
my $plugins_dir = C4::Context->config("pluginsdir");
$plugins_dir = ref($plugins_dir) eq 'ARRAY' ? $plugins_dir->[0] : $plugins_dir;