luci-base: dispatcher.lua: pass permission state to legacy CBI templates
Ref: https://github.com/openwrt/luci/issues/3937 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
acae1378a8
commit
c48a8d5813
1 changed files with 22 additions and 2 deletions
|
@ -1329,12 +1329,23 @@ function _cbi(self, ...)
|
||||||
local cbi = require "luci.cbi"
|
local cbi = require "luci.cbi"
|
||||||
local tpl = require "luci.template"
|
local tpl = require "luci.template"
|
||||||
local http = require "luci.http"
|
local http = require "luci.http"
|
||||||
|
local util = require "luci.util"
|
||||||
|
|
||||||
local config = self.config or {}
|
local config = self.config or {}
|
||||||
local maps = cbi.load(self.model, ...)
|
local maps = cbi.load(self.model, ...)
|
||||||
|
|
||||||
local state = nil
|
local state = nil
|
||||||
|
|
||||||
|
local function has_uci_access(config, level)
|
||||||
|
local rv = util.ubus("session", "access", {
|
||||||
|
ubus_rpc_session = context.authsession,
|
||||||
|
scope = "uci", object = config,
|
||||||
|
["function"] = level
|
||||||
|
})
|
||||||
|
|
||||||
|
return (type(rv) == "table" and rv.access == true) or false
|
||||||
|
end
|
||||||
|
|
||||||
local i, res
|
local i, res
|
||||||
for i, res in ipairs(maps) do
|
for i, res in ipairs(maps) do
|
||||||
if util.instanceof(res, cbi.SimpleForm) then
|
if util.instanceof(res, cbi.SimpleForm) then
|
||||||
|
@ -1388,6 +1399,7 @@ function _cbi(self, ...)
|
||||||
local applymap = false
|
local applymap = false
|
||||||
local pageaction = true
|
local pageaction = true
|
||||||
local parsechain = { }
|
local parsechain = { }
|
||||||
|
local writable = false
|
||||||
|
|
||||||
for i, res in ipairs(maps) do
|
for i, res in ipairs(maps) do
|
||||||
if res.apply_needed and res.parsechain then
|
if res.apply_needed and res.parsechain then
|
||||||
|
@ -1413,12 +1425,19 @@ function _cbi(self, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
for i, res in ipairs(maps) do
|
for i, res in ipairs(maps) do
|
||||||
|
local is_readable_map = has_uci_access(res.config, "read")
|
||||||
|
local is_writable_map = has_uci_access(res.config, "write")
|
||||||
|
|
||||||
|
writable = writable or is_writable_map
|
||||||
|
|
||||||
res:render({
|
res:render({
|
||||||
firstmap = (i == 1),
|
firstmap = (i == 1),
|
||||||
redirect = redirect,
|
redirect = redirect,
|
||||||
messages = messages,
|
messages = messages,
|
||||||
pageaction = pageaction,
|
pageaction = pageaction,
|
||||||
parsechain = parsechain
|
parsechain = parsechain,
|
||||||
|
readable = is_readable_map,
|
||||||
|
writable = is_writable_map
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1429,7 +1448,8 @@ function _cbi(self, ...)
|
||||||
redirect = redirect,
|
redirect = redirect,
|
||||||
state = state,
|
state = state,
|
||||||
autoapply = config.autoapply,
|
autoapply = config.autoapply,
|
||||||
trigger_apply = applymap
|
trigger_apply = applymap,
|
||||||
|
writable = writable
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue