Group V1 serializer fixes from QE feedback

Straightforward bug fixes and edits to be more consistent with
the 3.1 v1 API structure
 - remove `inventory_source` as a field from group
 - add inventory source as a group summary field
 - fix user_capabilities bug for group start permission
 - fix 500 error on /inventory_sources/N/update/
This commit is contained in:
AlanCoding 2017-04-17 14:43:17 -04:00
parent 880f4a77a4
commit 29de1056e7
2 changed files with 16 additions and 19 deletions

View File

@ -1238,20 +1238,12 @@ class HostSerializer(BaseSerializerWithVariables):
class GroupSerializer(BaseSerializerWithVariables):
inventory_source = serializers.SerializerMethodField(
help_text=_('Dedicated inventory source for the group, will be removed in 3.3.'))
class Meta:
model = Group
fields = ('*', 'inventory', 'variables', 'has_active_failures',
'total_hosts', 'hosts_with_active_failures', 'total_groups',
'groups_with_active_failures', 'has_inventory_sources', 'inventory_source')
def get_fields(self): # TODO: remove in 3.3
fields = super(GroupSerializer, self).get_fields()
if not self.V1:
fields.pop('inventory_source')
return fields
'groups_with_active_failures', 'has_inventory_sources')
@property
def V1(self):
@ -1268,12 +1260,6 @@ class GroupSerializer(BaseSerializerWithVariables):
else:
return ['copy', 'edit', 'delete']
def get_inventory_source(self, obj): # TODO: remove in 3.3
try:
return obj.deprecated_inventory_source.id
except Group.deprecated_inventory_source.RelatedObjectDoesNotExist:
return None
def build_relational_field(self, field_name, relation_info):
field_class, field_kwargs = super(GroupSerializer, self).build_relational_field(field_name, relation_info)
# Inventory is read-only unless creating a new group.
@ -1282,6 +1268,20 @@ class GroupSerializer(BaseSerializerWithVariables):
field_kwargs.pop('queryset', None)
return field_class, field_kwargs
def get_summary_fields(self, obj): # TODO: remove in 3.3
summary_fields = super(GroupSerializer, self).get_summary_fields(obj)
if self.V1:
try:
inv_src = obj.deprecated_inventory_source
summary_fields['inventory_source'] = {}
for field in SUMMARIZABLE_FK_FIELDS['inventory_source']:
fval = getattr(inv_src, field, None)
if fval is not None:
summary_fields['inventory_source'][field] = fval
except Group.deprecated_inventory_source.RelatedObjectDoesNotExist:
pass
return summary_fields
def get_related(self, obj):
res = super(GroupSerializer, self).get_related(obj)
res.update(dict(
@ -1507,7 +1507,7 @@ class InventorySourceSerializer(UnifiedJobTemplateSerializer, InventorySourceOpt
def get_fields(self): # TODO: remove in 3.3
fields = super(InventorySourceSerializer, self).get_fields()
if not self.V1:
fields.pop('group')
fields.pop('group', None)
return fields
def get_group(self, obj): # TODO: remove in 3.3

View File

@ -354,9 +354,6 @@ class BaseAccess(object):
except Group.deprecated_inventory_source.RelatedObjectDoesNotExist:
user_capabilities[display_method] = False
continue
if obj.inventory_source and not obj.inventory_source._can_update():
user_capabilities[display_method] = False
continue
elif display_method in ['start', 'schedule'] and isinstance(obj, (Project)):
if obj.scm_type == '':
user_capabilities[display_method] = False