luci-mod-system: sshkeys.js: make readonly on insufficient ACLs
authorJo-Philipp Wich <jo@mein.io>
Thu, 16 Apr 2020 13:38:09 +0000 (15:38 +0200)
committerJo-Philipp Wich <jo@mein.io>
Thu, 16 Apr 2020 13:38:09 +0000 (15:38 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-mod-system/htdocs/luci-static/resources/view/system/sshkeys.js

index 487621daa32de40e3419c90d8113a3d920b5c8f9..4740b8c9dd0ee8327b7852d1ab9b99347da3e280 100644 (file)
@@ -1,9 +1,12 @@
 'use strict';
+'require baseclass';
 'require view';
 'require fs';
 'require ui';
 
-var SSHPubkeyDecoder = L.Class.singleton({
+var isReadonlyView = !L.hasViewPermission() || null;
+
+var SSHPubkeyDecoder = baseclass.singleton({
        lengthDecode: function(s, off)
        {
                var l = (s.charCodeAt(off++) << 24) |
@@ -224,17 +227,23 @@ return view.extend({
        },
 
        render: function(keys) {
-               var list = E('div', { 'class': 'cbi-dynlist', 'dragover': dragKey, 'drop': dropKey }, [
+               var list = E('div', {
+                       'class': 'cbi-dynlist',
+                       'dragover': isReadonlyView ? null : dragKey,
+                       'drop': isReadonlyView ? null : dropKey
+               }, [
                        E('div', { 'class': 'add-item' }, [
                                E('input', {
                                        'class': 'cbi-input-text',
                                        'type': 'text',
                                        'placeholder': _('Paste or drag SSH key fileā€¦') ,
-                                       'keydown': function(ev) { if (ev.keyCode === 13) addKey(ev) }
+                                       'keydown': function(ev) { if (ev.keyCode === 13) addKey(ev) },
+                                       'disabled': isReadonlyView
                                }),
                                E('button', {
                                        'class': 'cbi-button',
-                                       'click': ui.createHandlerFn(this, addKey)
+                                       'click': ui.createHandlerFn(this, addKey),
+                                       'disabled': isReadonlyView
                                }, _('Add key'))
                        ])
                ]);
@@ -244,7 +253,7 @@ return view.extend({
                        if (pubkey)
                                list.insertBefore(E('div', {
                                        class: 'item',
-                                       click: ui.createHandlerFn(this, removeKey),
+                                       click: isReadonlyView ? null : ui.createHandlerFn(this, removeKey),
                                        'data-key': key
                                }, [
                                        E('strong', pubkey.comment || _('Unnamed key')), E('br'),