mirror of
https://github.com/ansible/awx.git
synced 2026-05-15 05:17:36 -02:30
Renamed some API files/classes to mimic REST framework names, moved queryset filtering for permissions alongside other permissions/access checks, cleaned up base views to handle get_queryset based on class attributes, cleaned up post to sublist to create/attach/unattach.
This commit is contained in:
@@ -33,6 +33,10 @@ from djcelery.models import TaskMeta
|
||||
# Django-REST-Framework
|
||||
from rest_framework.authtoken.models import Token
|
||||
|
||||
__all__ = ['Organization', 'Team', 'Project', 'Credential', 'Inventory',
|
||||
'Host', 'Group', 'Permission', 'JobTemplate', 'Job',
|
||||
'JobHostSummary', 'JobEvent']
|
||||
|
||||
# TODO: reporting model TBD
|
||||
|
||||
PERM_INVENTORY_ADMIN = 'admin'
|
||||
@@ -1213,6 +1217,21 @@ class JobEvent(models.Model):
|
||||
|
||||
# TODO: reporting (MPD)
|
||||
|
||||
# Add mark_inactive method to User model.
|
||||
def user_mark_inactive(user, save=True):
|
||||
'''Use instead of delete to rename and mark users inactive.'''
|
||||
if user.is_active:
|
||||
user.username = "_deleted_%s_%s" % (now().isoformat(), user.username)
|
||||
user.is_active = False
|
||||
if save:
|
||||
user.save()
|
||||
User.add_to_class('mark_inactive', user_mark_inactive)
|
||||
|
||||
# Add custom methods to User model for permissions checks.
|
||||
from awx.main.access import *
|
||||
User.add_to_class('get_queryset', get_user_queryset)
|
||||
User.add_to_class('can_access', check_user_access)
|
||||
|
||||
@receiver(post_save, sender=User)
|
||||
def create_auth_token_for_user(sender, **kwargs):
|
||||
instance = kwargs.get('instance', None)
|
||||
|
||||
Reference in New Issue
Block a user