mirror of
https://github.com/ansible/awx.git
synced 2026-03-27 22:05:07 -02:30
Support creating system auditors through all 4 of our user creation endpoints
This commit is contained in:
@@ -720,24 +720,31 @@ class OrganizationInventoriesList(SubListAPIView):
|
|||||||
parent_model = Organization
|
parent_model = Organization
|
||||||
relationship = 'inventories'
|
relationship = 'inventories'
|
||||||
|
|
||||||
class OrganizationUsersList(SubListCreateAttachDetachAPIView):
|
|
||||||
|
class BaseUsersList(SubListCreateAttachDetachAPIView):
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
ret = super(BaseUsersList, self).post( request, *args, **kwargs)
|
||||||
|
try:
|
||||||
|
if request.data.get('is_system_auditor', False):
|
||||||
|
# This is a faux-field that just maps to checking the system
|
||||||
|
# auditor role member list.. unfortunately this means we can't
|
||||||
|
# set it on creation, and thus needs to be set here.
|
||||||
|
user = User.objects.get(id=ret.data['id'])
|
||||||
|
user.is_system_auditor = request.data['is_system_auditor']
|
||||||
|
ret.data['is_system_auditor'] = request.data['is_system_auditor']
|
||||||
|
except AttributeError as exc:
|
||||||
|
print(exc)
|
||||||
|
pass
|
||||||
|
return ret
|
||||||
|
|
||||||
|
class OrganizationUsersList(BaseUsersList):
|
||||||
|
|
||||||
model = User
|
model = User
|
||||||
serializer_class = UserSerializer
|
serializer_class = UserSerializer
|
||||||
parent_model = Organization
|
parent_model = Organization
|
||||||
relationship = 'member_role.members'
|
relationship = 'member_role.members'
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
class OrganizationAdminsList(BaseUsersList):
|
||||||
ret = super(OrganizationUsersList, self).post( request, *args, **kwargs)
|
|
||||||
if type(request.data) is dict and request.data.get('is_system_auditor', False):
|
|
||||||
# This is a faux-field that just maps to checking the system
|
|
||||||
# auditor role member list.. unfortunately this means we can't
|
|
||||||
# set it on creation, and thus needs to be set here.
|
|
||||||
user = User.objects.get(id=ret.data['id'])
|
|
||||||
user.is_system_auditor = request.data['is_system_auditor']
|
|
||||||
return ret
|
|
||||||
|
|
||||||
class OrganizationAdminsList(SubListCreateAttachDetachAPIView):
|
|
||||||
|
|
||||||
model = User
|
model = User
|
||||||
serializer_class = UserSerializer
|
serializer_class = UserSerializer
|
||||||
@@ -840,7 +847,7 @@ class TeamDetail(RetrieveUpdateDestroyAPIView):
|
|||||||
model = Team
|
model = Team
|
||||||
serializer_class = TeamSerializer
|
serializer_class = TeamSerializer
|
||||||
|
|
||||||
class TeamUsersList(SubListCreateAttachDetachAPIView):
|
class TeamUsersList(BaseUsersList):
|
||||||
|
|
||||||
model = User
|
model = User
|
||||||
serializer_class = UserSerializer
|
serializer_class = UserSerializer
|
||||||
@@ -1109,12 +1116,17 @@ class UserList(ListCreateAPIView):
|
|||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
ret = super(UserList, self).post( request, *args, **kwargs)
|
ret = super(UserList, self).post( request, *args, **kwargs)
|
||||||
if type(request.data) is dict and request.data.get('is_system_auditor', False):
|
try:
|
||||||
# This is a faux-field that just maps to checking the system
|
if request.data.get('is_system_auditor', False):
|
||||||
# auditor role member list.. unfortunately this means we can't
|
# This is a faux-field that just maps to checking the system
|
||||||
# set it on creation, and thus needs to be set here.
|
# auditor role member list.. unfortunately this means we can't
|
||||||
user = User.objects.get(id=ret.data['id'])
|
# set it on creation, and thus needs to be set here.
|
||||||
user.is_system_auditor = request.data['is_system_auditor']
|
user = User.objects.get(id=ret.data['id'])
|
||||||
|
user.is_system_auditor = request.data['is_system_auditor']
|
||||||
|
ret.data['is_system_auditor'] = request.data['is_system_auditor']
|
||||||
|
except AttributeError as exc:
|
||||||
|
print(exc)
|
||||||
|
pass
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
class UserMeList(ListAPIView):
|
class UserMeList(ListAPIView):
|
||||||
|
|||||||
Reference in New Issue
Block a user