luci-base, luci-lua-runtime: adjust Lua template environment

To maintain full compatibility with the old Lua runtime, templates
rendered from a menu `template()` action must implicitly inherit the
`luci.dispatcher` namespace as scope while other indirectly included
templates must not.

Fixes: #6105
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2022-11-21 12:27:28 +01:00
parent 08ae8d40a9
commit fa17c1573f
3 changed files with 10 additions and 2 deletions

View file

@ -774,7 +774,9 @@ function render_action(fn) {
function run_action(request_path, lang, tree, resolved, action) {
switch (action?.type) {
case 'template':
runtime.render(action.path, {});
render_action(() => {
runtime.call('luci.dispatcher', 'render_lua_template', action.path);
});
break;
case 'view':

View file

@ -354,6 +354,12 @@ function invoke_form_action(model, ...)
_G.L.include("footer")
end
function render_lua_template(path)
local tpl = require "luci.template"
tpl.render(path, getfenv(1))
end
function call(name, ...)
return {

View file

@ -121,7 +121,7 @@ context.viewns = setmetatable({
elseif key == "resource" then
return L.config.main.resourcebase
else
return rawget(tbl, key) or disp[key] or _G[key] or L[key]
return rawget(tbl, key) or _G[key] or L[key]
end
end})