mirror of
https://github.com/ansible/awx.git
synced 2026-01-09 23:12:08 -03:30
Deal with relations that we cannot resolve
such as due to a lack of permissions. If there is a foreign key to something where we don't have sufficient read permissions, we now drop the parent object from the export.
This commit is contained in:
parent
6387258da1
commit
471dc2babf
@ -129,11 +129,13 @@ class ApiV2(base.Base):
|
||||
continue
|
||||
try:
|
||||
# FIXME: use caching by url
|
||||
fields[key] = asset.related[key].get().get_natural_key()
|
||||
natural_key = asset.related[key].get().get_natural_key()
|
||||
except exc.Forbidden:
|
||||
log.warning("This foreign key cannot be read: %s", asset.related[key])
|
||||
if options[key]['required']:
|
||||
return None # This is a mandatory foreign key
|
||||
return None
|
||||
if natural_key is None:
|
||||
return None # This is an unresolvable foreign key
|
||||
fields[key] = natural_key
|
||||
|
||||
related = {}
|
||||
for key, related_endpoint in asset.related.items():
|
||||
@ -172,7 +174,11 @@ class ApiV2(base.Base):
|
||||
if related:
|
||||
fields['related'] = related
|
||||
|
||||
fields['natural_key'] = asset.get_natural_key()
|
||||
natural_key = asset.get_natural_key()
|
||||
if natural_key is None:
|
||||
return None
|
||||
fields['natural_key'] = natural_key
|
||||
|
||||
return remove_encrypted(fields)
|
||||
|
||||
def _get_assets(self, resource, value):
|
||||
|
||||
@ -331,7 +331,7 @@ class Page(object):
|
||||
# FIXME: use caching by url
|
||||
natural_key[key] = self.related[key].get().get_natural_key()
|
||||
except exc.Forbidden:
|
||||
log.warning("This foreign key cannot be read: %s", getattr(self, 'endpoint', ''))
|
||||
log.warning("This foreign key cannot be read: %s", self.related[key])
|
||||
return None
|
||||
elif key in self:
|
||||
natural_key[key] = self[key]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user