Use the existing user object in the case where a user is making changes to their own preferences
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user