mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Merge pull request #3579 from paperless-ngx/fix/issue-3578
Fix: return user first / last name from backend
This commit is contained in:
commit
9b50a1b7a6
@ -2594,11 +2594,25 @@ class TestApiUiSettings(DirectoriesMixin, APITestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.test_user = User.objects.create_superuser(username="test")
|
||||
self.test_user.first_name = "Test"
|
||||
self.test_user.last_name = "User"
|
||||
self.test_user.save()
|
||||
self.client.force_authenticate(user=self.test_user)
|
||||
|
||||
def test_api_get_ui_settings(self):
|
||||
response = self.client.get(self.ENDPOINT, format="json")
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertDictEqual(
|
||||
response.data["user"],
|
||||
{
|
||||
"id": self.test_user.id,
|
||||
"username": self.test_user.username,
|
||||
"is_superuser": True,
|
||||
"groups": [],
|
||||
"first_name": self.test_user.first_name,
|
||||
"last_name": self.test_user.last_name,
|
||||
},
|
||||
)
|
||||
self.assertDictEqual(
|
||||
response.data["settings"],
|
||||
{
|
||||
|
@ -1028,16 +1028,23 @@ class UiSettingsView(GenericAPIView):
|
||||
ui_settings["update_checking"] = {
|
||||
"backend_setting": settings.ENABLE_UPDATE_CHECK,
|
||||
}
|
||||
user_resp = {
|
||||
"id": user.id,
|
||||
"username": user.username,
|
||||
"is_superuser": user.is_superuser,
|
||||
"groups": list(user.groups.values_list("id", flat=True)),
|
||||
}
|
||||
|
||||
if len(user.first_name) > 0:
|
||||
user_resp["first_name"] = user.first_name
|
||||
if len(user.last_name) > 0:
|
||||
user_resp["last_name"] = user.last_name
|
||||
|
||||
# strip <app_label>.
|
||||
roles = map(lambda perm: re.sub(r"^\w+.", "", perm), user.get_all_permissions())
|
||||
return Response(
|
||||
{
|
||||
"user": {
|
||||
"id": user.id,
|
||||
"username": user.username,
|
||||
"is_superuser": user.is_superuser,
|
||||
"groups": user.groups.values_list("id", flat=True),
|
||||
},
|
||||
"user": user_resp,
|
||||
"settings": ui_settings,
|
||||
"permissions": roles,
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user