From 23fcdc036554a98e520daf20c4ff651039fcbd88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 2 Nov 2017 16:38:27 +0100 Subject: [PATCH] Refactor SettingsPlugin.on_settings_load Use current_user.has_permission instead of current_user.is_admin. --- src/octoprint/plugin/types.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/octoprint/plugin/types.py b/src/octoprint/plugin/types.py index 735b30dc7..c5bbaecab 100644 --- a/src/octoprint/plugin/types.py +++ b/src/octoprint/plugin/types.py @@ -1420,6 +1420,8 @@ class SettingsPlugin(OctoPrintPlugin): """ from flask_login import current_user import copy + + from octoprint.access.permissions import Permissions data = copy.deepcopy(self._settings.get_all_data(merged=True)) if self.config_version_key in data: @@ -1464,7 +1466,7 @@ class SettingsPlugin(OctoPrintPlugin): node[key] = None conditions = dict(user=lambda: current_user is not None and not current_user.is_anonymous, - admin=lambda: current_user is not None and not current_user.is_anonymous and current_user.is_admin, + admin=lambda: current_user is not None and current_user.has_permission(Permissions.SETTINGS), never=lambda: False) for level, condition in conditions.items(): @@ -1538,8 +1540,8 @@ class SettingsPlugin(OctoPrintPlugin): """ Retrieves the list of paths in the plugin's settings which be restricted on the REST API. - Override this in your plugin's implementation to restrict whether a path should only be returned to logged in - users & admins, only to admins, or never on the REST API. + Override this in your plugin's implementation to restrict whether a path should only be returned to users with + the SETTINGS permission, any logged in users, or never on the REST API. Return a ``dict`` with the keys ``admin``, ``user``, ``never`` mapping to a list of paths (as tuples or lists of the path elements) for which to restrict access via the REST API accordingly. Paths returned for the ``admin``