def has_role(user, roles):
if user and user.is_superuser:<EOL><INDENT>return True<EOL><DEDENT>if not isinstance(roles, list):<EOL><INDENT>roles = [roles]<EOL><DEDENT>normalized_roles = []<EOL>for role in roles:<EOL><INDENT>if not inspect.isclass(role):<EOL><INDENT>role = RolesManager.retrieve_role(role)<EOL><DEDENT>normalized_roles.append(role)<EOL><DEDENT>user_roles = get_user_roles(user)<EOL>return any([role in user_roles for role in normalized_roles])<EOL>
Check if a user has any of the given roles.