diff --git a/octoprint_klipper/__init__.py b/octoprint_klipper/__init__.py index 254a3ce..3018b13 100644 --- a/octoprint_klipper/__init__.py +++ b/octoprint_klipper/__init__.py @@ -53,13 +53,22 @@ class KlipperPlugin( def get_additional_permissions(self, *args, **kwargs): return [ - dict(key="CONFIG", - name="Config Klipper", - description=gettext("Allows to config klipper"), - default_groups=[ADMIN_GROUP], - dangerous=True, - roles=["admin"] - ) + { + "key": "CONFIG", + "name": "Config Klipper", + "description": gettext("Allows to config klipper"), + "default_groups": [ADMIN_GROUP], + "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): @@ -100,7 +109,7 @@ class KlipperPlugin( self._settings.get(["configuration", "configpath"]) ) try: - f = open(filepath, "r") + f = open(filepath, "r", encoding="utf-8") data["config"] = f.read() f.close() except IOError: @@ -116,9 +125,9 @@ class KlipperPlugin( self._settings.get(["configuration", "configpath"]) ) 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.close() self._logger.info( diff --git a/octoprint_klipper/static/css/klipper.css b/octoprint_klipper/static/css/klipper.css index 65938ee..c151695 100644 --- a/octoprint_klipper/static/css/klipper.css +++ b/octoprint_klipper/static/css/klipper.css @@ -80,6 +80,14 @@ ul#klipper-settings { 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 { margin: 0; } diff --git a/octoprint_klipper/static/js/klipper.js b/octoprint_klipper/static/js/klipper.js index 39be777..033243f 100644 --- a/octoprint_klipper/static/js/klipper.js +++ b/octoprint_klipper/static/js/klipper.js @@ -26,6 +26,7 @@ $(function() { self.shortStatus = ko.observable(); self.logMessages = ko.observableArray(); + self.hasRight = ko.observable(false); self.showLevelingDialog = function() { var dialog = $("#klipper_leveling_dialog"); @@ -126,7 +127,12 @@ $(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 diff --git a/octoprint_klipper/templates/klipper_settings.jinja2 b/octoprint_klipper/templates/klipper_settings.jinja2 index e633ead..cade8df 100644 --- a/octoprint_klipper/templates/klipper_settings.jinja2 +++ b/octoprint_klipper/templates/klipper_settings.jinja2 @@ -62,7 +62,7 @@
-
+