Use the existing user object in the case where a user is making changes to their own preferences

This commit is contained in:
Calen Pennington
2017-04-26 13:09:59 -04:00
parent 33fee20c3a
commit 20caf52bea
2 changed files with 9 additions and 4 deletions

View File

@@ -310,7 +310,13 @@ def _get_authorized_user(requesting_user, username=None, allow_staff=False):
If username is not provided, requesting_user.username is assumed.
"""
if username is None:
username = requesting_user.username
# If the user is one that has already been stored to the database, use that
if requesting_user.pk:
return requesting_user
else:
# Otherwise, treat this as a request against a separate user
username = requesting_user.username
try:
existing_user = User.objects.get(username=username)
except ObjectDoesNotExist:

View File

@@ -53,9 +53,8 @@ class TestPreferenceAPI(CacheIsolationTestCase):
super(TestPreferenceAPI, self).setUp()
self.user = UserFactory.create(password=self.password)
self.different_user = UserFactory.create(password=self.password)
self.staff_user = UserFactory(is_staff=True, password=self.password)
self.no_such_user = UserFactory.create(password=self.password)
self.no_such_user.username = "no_such_user"
self.staff_user = UserFactory.create(is_staff=True, password=self.password)
self.no_such_user = UserFactory.build(password=self.password, username="no_such_user")
self.test_preference_key = "test_key"
self.test_preference_value = "test_value"
set_user_preference(self.user, self.test_preference_key, self.test_preference_value)