Ejemplo n.º 1
0
def actions_to_roles(actions):
    # Keep special values
    if not is_value(actions):
        return actions

    actions = ensure_plural(actions)
    return list(set([role for action in actions for role in ACTIONS[action]]))
Ejemplo n.º 2
0
def roles_to_actions(roles):
    # Keep special values
    if not is_value(roles):
        return roles

    roles = ensure_plural(roles)
    return list(set([action for role in roles for action in ROLES[role]]))
Ejemplo n.º 3
0
def actions_to_roles(actions):
    # Keep special values
    if not is_value(actions):
        return actions

    actions = ensure_plural(actions)
    return list(set([role for action in actions for role in ACTIONS[action]]))
Ejemplo n.º 4
0
def roles_to_actions(roles):
    # Keep special values
    if not is_value(roles):
        return roles

    roles = ensure_plural(roles)
    return list(set([action for role in roles for action in ROLES[role]]))
Ejemplo n.º 5
0
def normalize_agent(agents, infer_agents=True):
    """
    Turn an agent into a list of equivalent agents
    """
    result = []
    for agent in ensure_plural(agents):
        if agent.__class__ not in _agent_registry:
            raise KeyError("%s is not registered." % agent.__class__)

        # Delegate agent calculation to registered function
        if infer_agents:
            result += list(_agent_registry[agent.__class__](agent))
        else:
            result.append(agent)

    return list(set(result))
    def _prefix_actions(self, actions):
        """
        Prepend this model's name as prefix. This enforces more correct
        configuration when registering role/action mappings.
        """
        if not is_value(actions):
            return actions

        result = []
        for action in ensure_plural(actions):
            if "." in action:
                raise ValueError(
                    "Prefixes are inferred. Register this with its own "
                    "actions.")

            result.append("%s.%s" % (get_model_name(self.model), action))

        return result
 def test_ensure_plural(self):
     self.assertEqual([1], ensure_plural(1))
     self.assertEqual([1], ensure_plural([1]))
 def _get_filter(self, key, value):
     return generic_in(key, ensure_plural(value))