Exemple #1
0
    def execute(self, message, option):
        if "acl" in option.context:
            acl = option.context["acl"]
            if type(acl) == type("test"):
                acl = [acl]

            allowed = True
            if len(acl) > 0:
                allowed = verify_acl(message, acl)

            if not allowed:
                acl_list = ""
                more_than_one_s = ""
                if len(acl) > 1:
                    more_than_one_s = "s"
                for i in range(0, len(acl)):
                    if i == 0:
                        acl_list = "%s" % acl[i]
                    elif i == len(acl) - 1:
                        acl_list = "%s or %s" % (acl_list, acl[i])
                    else:
                        acl_list = "%s, %s" % (acl_list, acl[i])
                explanation = "Sorry, but I don't have you listed in the %s group%s, which is required to do what you asked." % (
                    acl_list, more_than_one_s)

                self.not_allowed(message, explanation)
                return

        if "say_content" in option.context:
            # We're coming from a generation engine like a chatterbot, which doesn't *do* things.
            self.bot.pubsub.publish(
                "message.outgoing.%s" % message.data.backend,
                Event(
                    type="reply",
                    content=option.context["say_content"],
                    source_message=message,
                ),
                reference_message=message.data.original_incoming_event)
        else:
            module = imp.load_source(option.context.plugin_info["parent_name"],
                                     option.context.plugin_info["parent_path"])
            cls = getattr(module, option.context.plugin_info["name"])

            instantiated_module = cls(message=message)
            method = getattr(instantiated_module, option.context.function_name)

            thread_args = [
                message,
            ] + option.context["args"]

            self.run_execute(method, *thread_args,
                             **option.context.search_matches)
Exemple #2
0
def test_verify_acl_is_disabled(not_allowed_message_with_acls):
    """DISABLE_ACL True, means everyone can execute, so not allowed messages are allowed"""
    settings.DISABLE_ACL = True
    message, acls = not_allowed_message_with_acls
    assert verify_acl(message, acls)
Exemple #3
0
def test_verify_acl_no_backend_support(not_allowed_message_with_acls):
    settings.DISABLE_ACL = False
    message, acls = not_allowed_message_with_acls
    message.data.backend_supports_acl = False
    assert verify_acl(message, acls)
Exemple #4
0
def test_verify_acl_is_not_allowed(not_allowed_message_with_acls):
    settings.DISABLE_ACL = False
    message, acls = not_allowed_message_with_acls
    assert not verify_acl(message, acls)