From cf8a30cc4e8a8050f7af9f2b1de9b87218f0da6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 28 Nov 2017 12:20:14 +0100 Subject: [PATCH] Reordering: Put settings related things together --- src/octoprint/access/users.py | 62 +++++++++++++++++------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/octoprint/access/users.py b/src/octoprint/access/users.py index 0db369245..6a437fdd3 100644 --- a/src/octoprint/access/users.py +++ b/src/octoprint/access/users.py @@ -931,6 +931,37 @@ class User(UserMixin): return self._get_setting(path) + def set_setting(self, key, value): + if not isinstance(key, (tuple, list)): + path = [key] + else: + path = key + return self._set_setting(path, value) + + def _get_setting(self, path): + s = self._settings + for p in path: + if isinstance(s, dict) and p in s: + s = s[p] + else: + return None + return s + + def _set_setting(self, path, value): + s = self._settings + for p in path[:-1]: + if p not in s: + s[p] = dict() + + if not isinstance(s[p], dict): + s[p] = dict() + + s = s[p] + + key = path[-1] + s[key] = value + return True + def add_permissions_to_user(self, permissions): # Make sure the permissions variable is of type list if not isinstance(permissions, list): @@ -1024,37 +1055,6 @@ class User(UserMixin): return True return permission.needs.issubset(self.needs) - def set_setting(self, key, value): - if not isinstance(key, (tuple, list)): - path = [key] - else: - path = key - return self._set_setting(path, value) - - def _get_setting(self, path): - s = self._settings - for p in path: - if isinstance(s, dict) and p in s: - s = s[p] - else: - return None - return s - - def _set_setting(self, path, value): - s = self._settings - for p in path[:-1]: - if p not in s: - s[p] = dict() - - if not isinstance(s[p], dict): - s[p] = dict() - - s = s[p] - - key = path[-1] - s[key] = value - return True - def __repr__(self): return "User(id=%s,name=%s,active=%r,user=True,admin=%r,permissions=%s,groups=%s)" % (self.get_id(), self.get_name(), bool(self.is_active), self.has_permission(Permissions.ADMIN), self._permissions, self._groups)