Fix an issue in user settings
* UserSettings: crashed if overwrite an existing key with primitive value by same key with complex value. Also reduced number of calls to user.get_setting() * Updated tests
This commit is contained in:
1 parent
30e962b447
commit
b75b53d05a
3 files changed
+8
-6
No files matched your search
@@ -78,6 +78,7 @@ date of first contribution):
|
||||
* [Noah Martin](https://github.com/noahsmartin)
|
||||
* [Eyal Soha](https://github.com/eyal0)
|
||||
* [Greg Hulands](https://github.com/ghulands)
|
||||
* [Andreas Werner](https://github.com/gallore)
|
||||
|
||||
OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by
|
||||
[Daid Braam](https://github.com/daid). Parts of its communication layer and
|
||||
|
||||
@@ -310,9 +310,8 @@ class FilebasedUserManager(UserManager):
|
||||
raise UnknownUser(username)
|
||||
|
||||
user = self._users[username]
|
||||
current = user.get_setting(key)
|
||||
if not current or current != value:
|
||||
old_value = user.get_setting(key)
|
||||
old_value = user.get_setting(key)
|
||||
if not old_value or old_value != value:
|
||||
user.set_setting(key, value)
|
||||
self._dirty = self._dirty or old_value != value
|
||||
self._save()
|
||||
@@ -548,7 +547,7 @@ class User(UserMixin):
|
||||
def _get_setting(self, path):
|
||||
s = self._settings
|
||||
for p in path:
|
||||
if p in s:
|
||||
if isinstance(s, dict) and p in s:
|
||||
s = s[p]
|
||||
else:
|
||||
return None
|
||||
@@ -561,7 +560,7 @@ class User(UserMixin):
|
||||
s[p] = dict()
|
||||
|
||||
if not isinstance(s[p], dict):
|
||||
return False
|
||||
s[p] = dict()
|
||||
|
||||
s = s[p]
|
||||
|
||||
|
||||
@@ -63,7 +63,9 @@ class UserTestCase(unittest.TestCase):
|
||||
(["sub", "othersubkey"], "othersubvalue", dict(sub=dict(othersubkey="othersubvalue")), True),
|
||||
("booleankey", True, dict(booleankey=True), True),
|
||||
(["newsub", "newsubkey"], "newsubvalue", dict(newsub=dict(newsubkey="newsubvalue")), True),
|
||||
(["sub", "subkey", "wontwork"], "wontwork", dict(), False)
|
||||
# ["sub", "subkey"] is already existing and gets overwritten
|
||||
(["sub", "subkey", "subsubkey"], "42", dict(sub=dict(subkey=dict(subsubkey="42"))), True),
|
||||
(["sub"], "overwrite", dict(sub="overwrite"), True)
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_set_setting_string(self, key, value, update, expected_returnvalue):
|
||||
|
||||
Reference in new issue
Block a user