luci-compat: disable legacy cbi forms on insufficient ACLs
[oweals/luci.git] / modules / luci-compat / luasrc / view / cbi / map.htm
1 <%- if firstmap and messages then local msg; for _, msg in ipairs(messages) do -%>
2         <div class="alert-message warning"><%=pcdata(msg)%></div>
3 <%- end end -%>
4
5 <%
6   local function has_access(config, level)
7     local rv = luci.util.ubus("session", "access", {
8                 ubus_rpc_session = luci.dispatcher.context.authsession,
9                 scope = "uci",
10                 object = config,
11                 ["function"] = level
12     })
13
14     return (type(rv) == "table" and rv.access == true) or false
15   end
16
17   local is_readable = has_access(self.config, "read")
18   local is_writable = has_access(self.config, "write")
19
20   has_writeable_map = has_writeable_map or is_writable
21 %>
22
23 <% if is_readable then %>
24 <div class="cbi-map" id="cbi-<%=self.config%>"<%=ifattr(not is_writable, "style", "opacity:.6; pointer-events:none")%>>
25         <% if self.title and #self.title > 0 then %>
26                 <h2 name="content"><%=self.title%></h2>
27         <% end %>
28         <% if self.description and #self.description > 0 then %>
29                 <div class="cbi-map-descr"><%=self.description%></div>
30         <% end %>
31         <% if self.tabbed then %>
32                 <div>
33                         <% for i, section in ipairs(self.children) do
34                                tab = section.section or section.sectiontype %>
35                                 <div class="cbi-tabcontainer"<%=
36                                         attr("id", "container.m-%s.%s" %{ self.config, tab }) ..
37                                         attr("data-tab", tab) ..
38                                         attr("data-tab-title", section.title or tab)
39                                 %>>
40                                         <% section:render() %>
41                                 </div>
42                         <% end %>
43                 </div>
44
45                 <% if not self.save then -%>
46                         <div class="cbi-section-error">
47                                 <% for _, section in ipairs(self.children) do %>
48                                         <% if section.error and section.error[section.section] then -%>
49                                                 <ul><li>
50                                                         <%:One or more invalid/required values on tab%>:&nbsp;<%=section.title or section.section or section.sectiontype%>
51                                                 </li></ul>
52                                         <%- end %>
53                                 <% end %>
54                         </div>
55                 <%- end %>
56         <% else %>
57                 <%- self:render_children() %>
58         <% end %>
59 </div>
60 <% else %>
61 <div class="alert-message warning"><%:Insufficient permissions to read UCI configuration.%></div>
62 <% end %>