mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 01:57:35 -03:30
Exposes the User.created attribute via API
Signed-off-by: Marcelo Moreira de Mello <tchello.mello@gmail.com>
This commit is contained in:
parent
f0aec0d444
commit
3803763c53
@ -257,6 +257,11 @@ class FieldLookupBackend(BaseFilterBackend):
|
||||
if key in self.RESERVED_NAMES:
|
||||
continue
|
||||
|
||||
# HACK: make `created` available via API for the Django User ORM model
|
||||
# so it keep compatiblity with other objects which exposes the `created` attr.
|
||||
if queryset.model._meta.object_name == 'User' and key.startswith('created'):
|
||||
key = key.replace('created', 'date_joined')
|
||||
|
||||
# HACK: Make job event filtering by host name mostly work even
|
||||
# when not capturing job event hosts M2M.
|
||||
if queryset.model._meta.object_name == 'JobEvent' and key.startswith('hosts__name'):
|
||||
|
||||
@ -127,9 +127,15 @@ def user_get_auditor_of_organizations(user):
|
||||
return Organization.objects.filter(auditor_role__members=user)
|
||||
|
||||
|
||||
@property
|
||||
def created(user):
|
||||
return user.date_joined
|
||||
|
||||
|
||||
User.add_to_class('organizations', user_get_organizations)
|
||||
User.add_to_class('admin_of_organizations', user_get_admin_of_organizations)
|
||||
User.add_to_class('auditor_of_organizations', user_get_auditor_of_organizations)
|
||||
User.add_to_class('created', created)
|
||||
|
||||
|
||||
@property
|
||||
|
||||
@ -61,3 +61,9 @@ def test_user_cannot_update_last_login(patch, admin):
|
||||
middleware=SessionMiddleware()
|
||||
)
|
||||
assert User.objects.get(pk=admin.pk).last_login is None
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_user_verify_attribute_created(admin):
|
||||
assert admin.created == admin.date_joined
|
||||
User.objects.get(pk=admin.pk).created == User.objects.get(pk=admin.pk).date_joined
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user