actor_matches_allow utility function, refs #800

This commit is contained in:
Simon Willison 2020-06-06 11:39:11 -07:00
commit 14f6b4d200
3 changed files with 62 additions and 2 deletions

View file

@ -854,3 +854,22 @@ def call_with_supported_arguments(fn, **kwargs):
)
call_with.append(kwargs[parameter])
return fn(*call_with)
def actor_matches_allow(actor, allow):
if allow is None:
return True
for key, values in allow.items():
if values == "*" and key in actor:
return True
if isinstance(values, str):
values = [values]
actor_values = actor.get(key)
if actor_values is None:
return False
if isinstance(actor_values, str):
actor_values = [actor_values]
actor_values = set(actor_values)
if actor_values.intersection(values):
return True
return False