Bug 23237

Summary: Add support for [% INCLUDE %] in plugin templates
Product: Koha Reporter: Frédéric Demians <f.demians>
Component: Plugin architectureAssignee: Frédéric Demians <f.demians>
Status: CLOSED FIXED QA Contact: Nick Clemens <nick>
Severity: new feature    
Priority: P5 - low CC: dcook, fridolin.somers, jonathan.druart, katrin.fischer, lucas, martin.renvoize, maryse.simard, nick, tomascohen
Version: master   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
The new feature allows plugin authors to use template `[% INCLUDE %]` directives in their templates. It does so by introducing a new variable, `PLUGIN_DIR`, allowing the template engine to locate the includes. **Usage**: `[% INCLUDE "$PLUGIN_DIR/header.tt" %]` **Warning**: Care should be taken when installing any plugins and only plugins you trust should be used.
Version(s) released in:
19.11.00,19.05.03
Bug Depends on:    
Bug Blocks: 26803    
Attachments: Bug 23237 Plugin allow [% INCLUDE %] from template
Bug 23237 Plugin allow [% INCLUDE %] from template
Bug 23237: Plugin allow [% INCLUDE %] from template
Bug 23237: Fix POD and typos
Bug 23237: Fix PLUGIN_DIR parameter in master/19.11

Description Frédéric Demians 2019-06-29 06:54:58 UTC
From a plugin template it is useful to be able to include other templates with [% INCLUDE %] directives. But TT module is used by Koha with absolute paths. Relative paths are forbidden for security reasons. A new param [% PLUGIN_DIR %] allow plugin templates to know where to find plugin home directory.
Comment 1 Frédéric Demians 2019-06-29 07:10:31 UTC
Created attachment 91128 [details] [review]
Bug 23237 Plugin allow [% INCLUDE %] from template

From a plugin template it is useful to be able to include other templates with
[% INCLUDE %] directives. But TT module is used by Koha with absolute paths.
Relative paths are forbidden for security reasons. A new param [% PLUGIN_DIR %]
allow plugin templates to know where to find plugin home directory.

How to test:

1. Install kitchen-sink plugin.

2. Find tool-step1.tt file, and add this at the begining of the file:
   [% INCLUDE "$PLUGIN_DIR/header.tt" %]
   It ask to include a template header.tt which doesn't exit.

3. Run kitchen-sink plugin tool. You must have this error message:

   Template process failed: file error - _path to plugin
   directory_/Koha/Plugin/Com/ByWaterSolutions/KitchenSink/header.tt: not found

   quod erat demonstrandum
Comment 2 Maryse Simard 2019-07-05 20:11:24 UTC
Created attachment 91374 [details] [review]
Bug 23237 Plugin allow [% INCLUDE %] from template

From a plugin template it is useful to be able to include other templates with
[% INCLUDE %] directives. But TT module is used by Koha with absolute paths.
Relative paths are forbidden for security reasons. A new param [% PLUGIN_DIR %]
allow plugin templates to know where to find plugin home directory.

How to test:

1. Install kitchen-sink plugin.

2. Find tool-step1.tt file, and add this at the begining of the file:
   [% INCLUDE "$PLUGIN_DIR/header.tt" %]
   It ask to include a template header.tt which doesn't exit.

3. Run kitchen-sink plugin tool. You must have this error message:

   Template process failed: file error - _path to plugin
   directory_/Koha/Plugin/Com/ByWaterSolutions/KitchenSink/header.tt: not found

   quod erat demonstrandum

Signed-off-by: Maryse Simard <maryse.simard@inlibro.com>
Comment 3 Nick Clemens 2019-07-30 13:52:44 UTC
Created attachment 91875 [details] [review]
Bug 23237: Plugin allow [% INCLUDE %] from template

From a plugin template it is useful to be able to include other templates with
[% INCLUDE %] directives. But TT module is used by Koha with absolute paths.
Relative paths are forbidden for security reasons. A new param [% PLUGIN_DIR %]
allow plugin templates to know where to find plugin home directory.

How to test:

1. Install kitchen-sink plugin.

2. Find tool-step1.tt file, and add this at the begining of the file:
   [% INCLUDE "$PLUGIN_DIR/header.tt" %]
   It ask to include a template header.tt which doesn't exit.

3. Run kitchen-sink plugin tool. You must have this error message:

   Template process failed: file error - _path to plugin
   directory_/Koha/Plugin/Com/ByWaterSolutions/KitchenSink/header.tt: not found

   quod erat demonstrandum

Signed-off-by: Maryse Simard <maryse.simard@inlibro.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 4 Nick Clemens 2019-07-30 13:52:47 UTC
Created attachment 91876 [details] [review]
Bug 23237: Fix POD and typos

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Comment 5 Martin Renvoize 2019-08-05 14:47:55 UTC
Nice work!

Pushed to master for 19.11.00
Comment 6 Martin Renvoize 2019-08-05 14:51:19 UTC
Nice work!

Pushed to master for 19.11.00
Comment 7 Fridolin Somers 2019-08-09 13:45:56 UTC
Nice enhancement.
I choose to backport so than Koha Plugins can already be developed/updated with this.

Pushed to 19.05.x for 19.05.03
Comment 8 Lucas Gass 2019-09-17 19:25:49 UTC
following Fridolin's lead and backporting this enhancement to 18.11.x for 18.11.10
Comment 9 Lucas Gass 2019-09-20 22:02:20 UTC
this patchset made me unable to prove t/db_dependent/Koha/REST/Plugin/PluginRoutes.t in 18.11.x, since this is an enhancement i am choosing to revert the patch set in 18.11.x
Comment 10 Tomás Cohen Arazi 2019-11-27 19:37:24 UTC
I think the get_plugin_dir method is not quite correct as there can be more than one plugins_dir entry. bundle_dir should be used instead.
Comment 11 Martin Renvoize 2020-01-21 17:06:20 UTC
Any further thoughts regarding Tomas's comment Frederic?
Comment 12 Frédéric Demians 2020-01-24 09:13:47 UTC
(In reply to Martin Renvoize from comment #11)
> Any further thoughts regarding Tomas's comment Frederic?

Thomas is right. I implemented this before Thomas added bundle_dir() method. I
will submit a patch to use Thomas method instead of mine get_plugin_dir()
method.

bundle_dir() is available in 19.11 and after. So the new patch must not be
backported to 19.05 and 18.11. As it is the usage of new template parameter
PLUGIN_DIR will be OK in 18.11 and 19.05 as soon as plugins_dir parameter is
unique in koha-conf.xml.
Comment 13 Frédéric Demians 2020-01-24 09:22:25 UTC
Created attachment 97862 [details] [review]
Bug 23237: Fix PLUGIN_DIR parameter in master/19.11

Method get_plugin_dir() is not correct when plugin_dirs parameter is repeated
in koha-conf.xml. A new method bundle_path() must be used instead.

bundle_dir() is available in 19.11 and after. So the new patch must not be
backported to 19.05 and 18.11. As it is the usage of the new template parameter
PLUGIN_DIR will be OK in 18.11 and 19.05 as soon as plugins_dir parameter is
unique in koha-conf.xml.

Thanks Thomas
Comment 14 Frédéric Demians 2020-10-23 16:20:26 UTC
See bug 26803