mirror of
https://github.com/inventree/InvenTree.git
synced 2025-09-13 22:21:37 +00:00
Fix api_url for 'user' type (#10182)
* Fix api_url for 'user' type * Added regression test
This commit is contained in:
@@ -396,7 +396,7 @@ class InvenTreeMetadata(SimpleMetadata):
|
|||||||
|
|
||||||
# Special case for special models
|
# Special case for special models
|
||||||
if field_info['model'] == 'user':
|
if field_info['model'] == 'user':
|
||||||
field_info['api_url'] = (reverse('api-user-list'),)
|
field_info['api_url'] = reverse('api-user-list')
|
||||||
elif field_info['model'] == 'group':
|
elif field_info['model'] == 'group':
|
||||||
field_info['api_url'] = reverse('api-group-list')
|
field_info['api_url'] = reverse('api-group-list')
|
||||||
elif field_info['model'] == 'contenttype':
|
elif field_info['model'] == 'contenttype':
|
||||||
|
@@ -42,6 +42,24 @@ class UserAPITests(InvenTreeAPITestCase):
|
|||||||
fields['is_staff']['help_text'], 'Does this user have staff permissions'
|
fields['is_staff']['help_text'], 'Does this user have staff permissions'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_api_url(self):
|
||||||
|
"""Test the 'api_url attribute in related API endpoints.
|
||||||
|
|
||||||
|
Ref: https://github.com/inventree/InvenTree/pull/10182
|
||||||
|
"""
|
||||||
|
self.user.is_superuser = True
|
||||||
|
self.user.save()
|
||||||
|
|
||||||
|
url = reverse('api-build-list')
|
||||||
|
response = self.options(url)
|
||||||
|
actions = response.data['actions']['POST']
|
||||||
|
issued_by = actions['issued_by']
|
||||||
|
|
||||||
|
self.assertEqual(issued_by['pk_field'], 'pk')
|
||||||
|
self.assertEqual(issued_by['model'], 'user')
|
||||||
|
self.assertEqual(issued_by['api_url'], reverse('api-user-list'))
|
||||||
|
self.assertEqual(issued_by['default'], self.user.pk)
|
||||||
|
|
||||||
def test_user_api(self):
|
def test_user_api(self):
|
||||||
"""Tests for User API endpoints."""
|
"""Tests for User API endpoints."""
|
||||||
url = reverse('api-user-list')
|
url = reverse('api-user-list')
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
|
import { Badge, Group, Text } from '@mantine/core';
|
||||||
import { IconUser, IconUsersGroup } from '@tabler/icons-react';
|
import { IconUser, IconUsersGroup } from '@tabler/icons-react';
|
||||||
import type { ReactNode } from 'react';
|
import type { ReactNode } from 'react';
|
||||||
|
|
||||||
|
import { t } from '@lingui/core/macro';
|
||||||
import { type InstanceRenderInterface, RenderInlineModel } from './Instance';
|
import { type InstanceRenderInterface, RenderInlineModel } from './Instance';
|
||||||
|
|
||||||
export function RenderOwner({
|
export function RenderOwner({
|
||||||
@@ -29,7 +31,21 @@ export function RenderUser({
|
|||||||
instance && (
|
instance && (
|
||||||
<RenderInlineModel
|
<RenderInlineModel
|
||||||
primary={instance.username}
|
primary={instance.username}
|
||||||
secondary={`${instance.first_name} ${instance.last_name}`}
|
secondary={
|
||||||
|
<Group gap='xs'>
|
||||||
|
{!instance.is_active && (
|
||||||
|
<Badge autoContrast color='red'>{t`Inactive`}</Badge>
|
||||||
|
)}
|
||||||
|
</Group>
|
||||||
|
}
|
||||||
|
suffix={
|
||||||
|
<Group gap='xs'>
|
||||||
|
<Text size='sm'>
|
||||||
|
{instance.first_name} {instance.last_name}
|
||||||
|
</Text>
|
||||||
|
<IconUser size={16} />
|
||||||
|
</Group>
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user