Skip to content

Commit

Permalink
as1.is_public: bug fix for d802de2
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed May 7, 2024
1 parent 2f10630 commit d9f97ac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
26 changes: 17 additions & 9 deletions granary/as1.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,19 +220,27 @@ def is_public(obj, unlisted=True):
obj (dict): AS2 activity or object
unlisted (bool): whether `@unlisted` counts as public or not
"""
if obj is None:
return None

inner_obj = get_object(obj)
to = get_objects(obj, 'to') or get_objects(inner_obj, 'to') or []
aliases = util.trim_nulls([t.get('alias') for t in to])
object_types = util.trim_nulls([t.get('objectType') for t in to])
if '@public' in aliases or ('@unlisted' in aliases and unlisted):
return True
elif 'unknown' in object_types:
return None
elif aliases:
return False
elif 'to' in obj or 'to' in inner_obj:
# it does at least have some audience that doesn't include public
return False

try:
if '@public' in aliases or ('@unlisted' in aliases and unlisted):
return True
elif 'unknown' in object_types:
return None
elif aliases:
return False
elif 'to' in obj or 'to' in inner_obj:
# it does at least have some audience that doesn't include public
return False
except BaseException as e:
util.d(obj)
raise

return True

Expand Down
2 changes: 2 additions & 0 deletions granary/tests/test_as1.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@
class As1Test(testutil.TestCase):

def test_is_public(self):
self.assertIsNone(as1.is_public(None))

for obj in (
{'to': [{'objectType': 'unknown'}]},
{'to': [{'objectType': 'unknown'},
Expand Down

0 comments on commit d9f97ac

Please sign in to comment.