mirror of
https://github.com/ansible/awx.git
synced 2026-03-05 10:41:05 -03:30
introduce summary_fields for users, showing user_capabilities
This commit is contained in:
@@ -690,7 +690,7 @@ class UserSerializer(BaseSerializer):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
fields = ('*', '-name', '-description', '-modified',
|
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')
|
'email', 'is_superuser', 'is_system_auditor', 'password', 'ldap_dn', 'external_account')
|
||||||
|
|
||||||
def to_representation(self, obj):
|
def to_representation(self, obj):
|
||||||
|
|||||||
@@ -228,8 +228,6 @@ class BaseAccess(object):
|
|||||||
# elif hasattr(obj, 'can_edit'):
|
# elif hasattr(obj, 'can_edit'):
|
||||||
# user_capabilities['change'] = obj.can_edit
|
# user_capabilities['change'] = obj.can_edit
|
||||||
|
|
||||||
print(type(obj))
|
|
||||||
|
|
||||||
for display_method in ['edit', 'delete', 'start', 'schedule', 'copy']:
|
for display_method in ['edit', 'delete', 'start', 'schedule', 'copy']:
|
||||||
# Custom ordering of methods used so we can reuse earlier calcs
|
# Custom ordering of methods used so we can reuse earlier calcs
|
||||||
if display_method not in method_list:
|
if display_method not in method_list:
|
||||||
@@ -251,7 +249,6 @@ class BaseAccess(object):
|
|||||||
|
|
||||||
# Preprocessing before the access method is called
|
# Preprocessing before the access method is called
|
||||||
data = None
|
data = None
|
||||||
sub_obj = None
|
|
||||||
if method == 'add':
|
if method == 'add':
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
@@ -269,10 +266,12 @@ class BaseAccess(object):
|
|||||||
|
|
||||||
try:
|
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)
|
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)
|
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:
|
except Exception as exc:
|
||||||
|
|||||||
@@ -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)
|
response = options(reverse('api:inventory_groups_list', args=[inventory.pk]), alice)
|
||||||
assert 'POST' in response.data['actions']
|
assert 'POST' in response.data['actions']
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_inventory_group_host_can_not_add(inventory, bob, options):
|
def test_inventory_group_host_can_not_add(inventory, bob, options):
|
||||||
inventory.read_role.members.add(bob)
|
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']
|
assert 'POST' not in response.data['actions']
|
||||||
response = options(reverse('api:inventory_groups_list', args=[inventory.pk]), bob)
|
response = options(reverse('api:inventory_groups_list', args=[inventory.pk]), bob)
|
||||||
assert 'POST' not in response.data['actions']
|
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']
|
||||||
|
|||||||
Reference in New Issue
Block a user