def user_assigned_policies(user):
key = user_cache_key(user)<EOL>cached = cache.get(key)<EOL>if cached is not None:<EOL><INDENT>return cached<EOL><DEDENT>if user is None:<EOL><INDENT>pset = PermissionSet.objects.filter(anonymous_user=True).first()<EOL><DEDENT>else:<EOL><INDENT>pset = user.permissionset.first()<EOL><DEDENT>if pset is None:<EOL><INDENT>return []<EOL><DEDENT>res = []<EOL>skip_role_policies = False<EOL>skip_role = None<EOL>skip_role_variables = None<EOL>for pi in pset.policyinstance_set.select_related('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>if skip_role_policies:<EOL><INDENT>if pi.role == skip_role and pi.variables == skip_role_variables:<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>skip_role_policies = False<EOL><DEDENT><DEDENT>if pi.role:<EOL><INDENT>res.append(pi.role)<EOL>skip_role = pi.role<EOL>skip_role_variables = pi.variables<EOL>skip_role_policies = True<EOL><DEDENT>else:<EOL><INDENT>if pi.variables != '<STR_LIT:{}>':<EOL><INDENT>res.append((pi.policy, json.loads(pi.variables)))<EOL><DEDENT>else:<EOL><INDENT>res.append(pi.policy)<EOL><DEDENT><DEDENT><DEDENT>cache.set(key, res)<EOL>return res<EOL>
Return sequence of policies assigned to a user (or the anonymous
    user is ``user`` is ``None``).  (Also installed as
    ``assigned_policies`` method on ``User`` model.