mirror of
https://github.com/ansible/awx.git
synced 2026-02-24 06:26:00 -03:30
Merge pull request #9558 from jainnikhil30/fix_tower_user
fix the tower_user module to update the fields properly Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -149,19 +149,19 @@ def main():
|
|||||||
|
|
||||||
# Create the data that gets sent for create and update
|
# Create the data that gets sent for create and update
|
||||||
new_fields = {}
|
new_fields = {}
|
||||||
if username:
|
if username is not None:
|
||||||
new_fields['username'] = module.get_item_name(existing_item) if existing_item else username
|
new_fields['username'] = module.get_item_name(existing_item) if existing_item else username
|
||||||
if first_name:
|
if first_name is not None:
|
||||||
new_fields['first_name'] = first_name
|
new_fields['first_name'] = first_name
|
||||||
if last_name:
|
if last_name is not None:
|
||||||
new_fields['last_name'] = last_name
|
new_fields['last_name'] = last_name
|
||||||
if email:
|
if email is not None:
|
||||||
new_fields['email'] = email
|
new_fields['email'] = email
|
||||||
if is_superuser:
|
if is_superuser is not None:
|
||||||
new_fields['is_superuser'] = is_superuser
|
new_fields['is_superuser'] = is_superuser
|
||||||
if is_system_auditor:
|
if is_system_auditor is not None:
|
||||||
new_fields['is_system_auditor'] = is_system_auditor
|
new_fields['is_system_auditor'] = is_system_auditor
|
||||||
if password:
|
if password is not None:
|
||||||
new_fields['password'] = password
|
new_fields['password'] = password
|
||||||
|
|
||||||
# If the state was present and we can let the module build or update the existing item, this will return on its own
|
# If the state was present and we can let the module build or update the existing item, this will return on its own
|
||||||
|
|||||||
@@ -57,3 +57,23 @@ def test_update_password_on_create(run_module, admin_user, mock_auth_stuff):
|
|||||||
assert not result.get('failed', False), result.get('msg', result)
|
assert not result.get('failed', False), result.get('msg', result)
|
||||||
|
|
||||||
assert not result.get('changed')
|
assert not result.get('changed')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_update_user(run_module, admin_user, mock_auth_stuff):
|
||||||
|
result = run_module('tower_user', dict(
|
||||||
|
username='Bob',
|
||||||
|
password='pass4word',
|
||||||
|
is_system_auditor=True
|
||||||
|
), admin_user)
|
||||||
|
assert not result.get('failed', False), result.get('msg', result)
|
||||||
|
assert result.get('changed'), result
|
||||||
|
|
||||||
|
update_result = run_module('tower_user', dict(
|
||||||
|
username='Bob',
|
||||||
|
is_system_auditor=False
|
||||||
|
), admin_user)
|
||||||
|
|
||||||
|
assert update_result.get('changed')
|
||||||
|
user = User.objects.get(id=result['id'])
|
||||||
|
assert not user.is_system_auditor
|
||||||
|
|||||||
Reference in New Issue
Block a user