diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 69824258ea..44eabc22d5 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -690,7 +690,7 @@ class UserSerializer(BaseSerializer): class Meta: model = User fields = ('*', '-name', '-description', '-modified', - '-summary_fields', 'username', 'first_name', 'last_name', + 'username', 'first_name', 'last_name', 'email', 'is_superuser', 'is_system_auditor', 'password', 'ldap_dn', 'external_account') def to_representation(self, obj): diff --git a/awx/main/access.py b/awx/main/access.py index f80f3a7865..01eb84eedb 100644 --- a/awx/main/access.py +++ b/awx/main/access.py @@ -228,8 +228,6 @@ class BaseAccess(object): # elif hasattr(obj, 'can_edit'): # user_capabilities['change'] = obj.can_edit - print(type(obj)) - for display_method in ['edit', 'delete', 'start', 'schedule', 'copy']: # Custom ordering of methods used so we can reuse earlier calcs if display_method not in method_list: @@ -251,7 +249,6 @@ class BaseAccess(object): # Preprocessing before the access method is called data = None - sub_obj = None if method == 'add': data = {} @@ -269,10 +266,12 @@ class BaseAccess(object): try: - if method in ['change', 'start', 'delete']: # 3 args + if method in ['change', 'start']: # 3 args user_capabilities[display_method] = self.user.can_access(type(obj), method, obj, data) - elif method == 'add': # 2 args + elif method in ['delete']: # 2 args user_capabilities[display_method] = self.user.can_access(type(obj), method, obj) + elif method in ['add']: # 2 args with data + user_capabilities[display_method] = self.user.can_access(type(obj), method, data) except Exception as exc: diff --git a/awx/main/tests/functional/api/test_adding_options.py b/awx/main/tests/functional/api/test_adding_options.py index 08ecf27a4f..e271c20188 100644 --- a/awx/main/tests/functional/api/test_adding_options.py +++ b/awx/main/tests/functional/api/test_adding_options.py @@ -11,7 +11,6 @@ def test_inventory_group_host_can_add(inventory, alice, options): response = options(reverse('api:inventory_groups_list', args=[inventory.pk]), alice) assert 'POST' in response.data['actions'] - @pytest.mark.django_db def test_inventory_group_host_can_not_add(inventory, bob, options): inventory.read_role.members.add(bob) @@ -20,3 +19,13 @@ def test_inventory_group_host_can_not_add(inventory, bob, options): assert 'POST' not in response.data['actions'] response = options(reverse('api:inventory_groups_list', args=[inventory.pk]), bob) assert 'POST' not in response.data['actions'] + +@pytest.mark.django_db +def test_user_list_can_add(org_member, org_admin, options): + response = options(reverse('api:user_list'), org_admin) + assert 'POST' in response.data['actions'] + +@pytest.mark.django_db +def test_user_list_can_not_add(org_member, org_admin, options): + response = options(reverse('api:user_list'), org_member) + assert 'POST' not in response.data['actions']