Commit 20caf52b by Calen Pennington

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

parent 33fee20c
...@@ -310,7 +310,13 @@ def _get_authorized_user(requesting_user, username=None, allow_staff=False): ...@@ -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 not provided, requesting_user.username is assumed.
""" """
if username is None: 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: try:
existing_user = User.objects.get(username=username) existing_user = User.objects.get(username=username)
except ObjectDoesNotExist: except ObjectDoesNotExist:
......
...@@ -53,9 +53,8 @@ class TestPreferenceAPI(CacheIsolationTestCase): ...@@ -53,9 +53,8 @@ class TestPreferenceAPI(CacheIsolationTestCase):
super(TestPreferenceAPI, self).setUp() super(TestPreferenceAPI, self).setUp()
self.user = UserFactory.create(password=self.password) self.user = UserFactory.create(password=self.password)
self.different_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.staff_user = UserFactory.create(is_staff=True, password=self.password)
self.no_such_user = UserFactory.create(password=self.password) self.no_such_user = UserFactory.build(password=self.password, username="no_such_user")
self.no_such_user.username = "no_such_user"
self.test_preference_key = "test_key" self.test_preference_key = "test_key"
self.test_preference_value = "test_value" self.test_preference_value = "test_value"
set_user_preference(self.user, self.test_preference_key, self.test_preference_value) set_user_preference(self.user, self.test_preference_key, self.test_preference_value)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment