luci-mod-status: disable "Set static" lease action on readonly view
authorJo-Philipp Wich <jo@mein.io>
Wed, 7 Jul 2021 15:14:15 +0000 (17:14 +0200)
committerJo-Philipp Wich <jo@mein.io>
Wed, 7 Jul 2021 15:17:16 +0000 (17:17 +0200)
Fixes: f6b6a12927 ("luci-mod-status: add support for one-click static lease")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit a6d957d6f59329cc16c838afe3c88c6072fad236)

modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/40_dhcp.js
modules/luci-mod-status/root/usr/share/rpcd/acl.d/luci-mod-status.json

index 69305a2a9c1374cf02d45a0dd1ac44d6c6d7a720..b93f26875d8603064b21912f9542fce1d2abc5f6 100644 (file)
@@ -21,7 +21,7 @@ return baseclass.extend({
                return Promise.all([
                        callLuciDHCPLeases(),
                        network.getHostHints(),
-                       uci.load('dhcp')
+                       L.resolveDefault(uci.load('dhcp'))
                ]);
        },
 
@@ -63,7 +63,8 @@ return baseclass.extend({
                var leases = Array.isArray(data[0].dhcp_leases) ? data[0].dhcp_leases : [],
                    leases6 = Array.isArray(data[0].dhcp6_leases) ? data[0].dhcp6_leases : [],
                    machints = data[1].getMACHints(false),
-                   hosts = uci.sections('dhcp', 'host');
+                   hosts = uci.sections('dhcp', 'host'),
+                   isReadonlyView = !L.hasViewPermission();
 
                for (var i = 0; i < hosts.length; i++) {
                        var host = hosts[i];
@@ -87,7 +88,7 @@ return baseclass.extend({
                                E('th', { 'class': 'th' }, _('IPv4 address')),
                                E('th', { 'class': 'th' }, _('MAC address')),
                                E('th', { 'class': 'th' }, _('Lease time remaining')),
-                               E('th', { 'class': 'th cbi-section-actions' }, _('Static Lease'))
+                               isReadonlyView ? E([]) : E('th', { 'class': 'th cbi-section-actions' }, _('Static Lease'))
                        ])
                ]);
 
@@ -108,7 +109,7 @@ return baseclass.extend({
                                exp
                        ];
 
-                       if (lease.macaddr != null) {
+                       if (!isReadonlyView && lease.macaddr != null) {
                                var mac = lease.macaddr.toUpperCase();
                                rows.push(E('button', {
                                        'class': 'cbi-button cbi-button-apply',
@@ -126,7 +127,7 @@ return baseclass.extend({
                                E('th', { 'class': 'th' }, _('IPv6 address')),
                                E('th', { 'class': 'th' }, _('DUID')),
                                E('th', { 'class': 'th' }, _('Lease time remaining')),
-                               E('th', { 'class': 'th cbi-section-actions' }, _('Static Lease'))
+                               isReadonlyView ? E([]) : E('th', { 'class': 'th cbi-section-actions' }, _('Static Lease'))
                        ])
                ]);
 
@@ -157,7 +158,7 @@ return baseclass.extend({
                                exp
                        ];
 
-                       if (lease.duid != null) {
+                       if (!isReadonlyView && lease.duid != null) {
                                var duid = lease.duid.toUpperCase();
                                rows.push(E('button', {
                                        'class': 'cbi-button cbi-button-apply',
index e23a0ae6b48b6ea2b4893954a45bb528b4d07ce0..3e7d823014361b97ad962c299f190a61947c7f5a 100644 (file)
                                "file": [ "list", "read" ],
                                "system": [ "board", "info" ]
                        }
+               },
+               "write": {
+                       "uci": [ "dhcp" ]
                }
        },