Tested with python3

+borders around macro
+macro permission role
+hide macros then one has no permission
This commit is contained in:
thelastWallE 2021-01-19 21:19:17 +01:00
parent 2984f072ba
commit 297554536c
4 changed files with 35 additions and 12 deletions

View File

@ -53,13 +53,22 @@ class KlipperPlugin(
def get_additional_permissions(self, *args, **kwargs): def get_additional_permissions(self, *args, **kwargs):
return [ return [
dict(key="CONFIG", {
name="Config Klipper", "key": "CONFIG",
description=gettext("Allows to config klipper"), "name": "Config Klipper",
default_groups=[ADMIN_GROUP], "description": gettext("Allows to config klipper"),
dangerous=True, "default_groups": [ADMIN_GROUP],
roles=["admin"] "dangerous": True,
) "roles": ["admin"],
},
{
"key": "MACRO",
"name": "Use Klipper Macros",
"description": gettext("Allows to use klipper macros"),
"default_groups": [ADMIN_GROUP],
"dangerous": True,
"roles": ["admin"],
},
] ]
def get_settings_defaults(self): def get_settings_defaults(self):
@ -100,7 +109,7 @@ class KlipperPlugin(
self._settings.get(["configuration", "configpath"]) self._settings.get(["configuration", "configpath"])
) )
try: try:
f = open(filepath, "r") f = open(filepath, "r", encoding="utf-8")
data["config"] = f.read() data["config"] = f.read()
f.close() f.close()
except IOError: except IOError:
@ -116,9 +125,9 @@ class KlipperPlugin(
self._settings.get(["configuration", "configpath"]) self._settings.get(["configuration", "configpath"])
) )
if sys.version_info[0] < 3: if sys.version_info[0] < 3:
data["config"] = data["config"].encode('utf-8') data["config"] = data["config"].encode('utf-8')
f = open(filepath, "w") f = open(filepath, "w", encoding="utf-8")
f.write(data["config"]) f.write(data["config"])
f.close() f.close()
self._logger.info( self._logger.info(

View File

@ -80,6 +80,14 @@ ul#klipper-settings {
height: 99%; height: 99%;
} }
#macros #item.control-group {
margin-bottom: 5px;
border: 1px solid #ddd;
border-radius: 3px;
background-color: #eeeeef;
color: #333;
}
#klipper_graph_dialog form { #klipper_graph_dialog form {
margin: 0; margin: 0;
} }

View File

@ -26,6 +26,7 @@ $(function() {
self.shortStatus = ko.observable(); self.shortStatus = ko.observable();
self.logMessages = ko.observableArray(); self.logMessages = ko.observableArray();
self.hasRight = ko.observable(false);
self.showLevelingDialog = function() { self.showLevelingDialog = function() {
var dialog = $("#klipper_leveling_dialog"); var dialog = $("#klipper_leveling_dialog");
@ -126,7 +127,12 @@ $(function() {
}; };
self.isActive = function() { self.isActive = function() {
return self.connectionState.isOperational() && self.loginState.isUser(); return self.connectionState.isOperational() && self.loginState.hasPermission(self.access.permissions.PLUGIN_KLIPPER_CONFIG); //was: && self.loginState.isUser();
}
self.hasRight = function (right_role) {
var arg = eval("access.permissions.PLUGIN_KLIPPER_"+right_role);
return self.loginState.hasPermissionKo(arg);
} }
// OctoKlipper settings link // OctoKlipper settings link

View File

@ -62,7 +62,7 @@
</div> </div>
</div> </div>
<div data-bind="foreach: settings.settings.plugins.klipper.macros"> <div data-bind="foreach: settings.settings.plugins.klipper.macros">
<div class="control-group"> <div class="control-group" id="item">
<label class="control-label">{{ _('Name') }}</label> <label class="control-label">{{ _('Name') }}</label>
<div class="controls"> <div class="controls">
<div class="row-fluid"> <div class="row-fluid">