Beispiel #1
0
    def test_execode_list(self):
        excdes = ExecodeManager.get_queued_execodes(self.__class__.TEST_ROOT_UID)

        self.assertFalse(excdes.empty)

        found = False
        for excde in excdes:
            if excde.execode == self.__class__.TEST_EXCDE_TOKEN and excde.action_type == Execode.SYS_TEST:
                found = True
                break

        self.assertTrue(found)
Beispiel #2
0
def issue_execode(e: TextMessageEventObject):
    result = ExecodeManager.enqueue_execode(e.root_oid,
                                            Execode.INTEGRATE_USER_DATA)
    if result.success:
        return _(
            "User Data Integration process started.\nExecode: `{}`\nExpiry: `{}`\n\n"
            "Please record the Execode and go to {}{} to complete the integration."
        ).format(result.execode, result.expiry.strftime("%Y-%m-%d %H:%M:%S"),
                 HostUrl, reverse("account.integrate"))
    else:
        return _(
            "User Data Integration process failed to start.\nResult: {}\nException: {}"
        ).format(result.outcome, result.exception)
Beispiel #3
0
    def get(self, request, *args, **kwargs):
        u_data = RootUserManager.get_root_data_api_token(
            self.request.COOKIES[keys.Cookies.USER_TOKEN])
        excde_list = ExecodeManager.get_queued_execodes(u_data.model.id)

        return render_template(
            self.request, _("Account Home"), "account/main.html", {
                "root_data":
                u_data.model,
                "api_user_data":
                u_data.model_api,
                "execode_list":
                excde_list,
                "onplat_user_data_list":
                u_data.model_onplat_list,
                "reg_time_str":
                t_delta_str(now_utc_aware() - u_data.model.id.generation_time)
            })
Beispiel #4
0
 def test_enqueue_test_action(self):
     self.__class__.TEST_EXCDE_TOKEN = \
         ExecodeManager.enqueue_execode(self.__class__.TEST_ROOT_UID, Execode.SYS_TEST).execode
Beispiel #5
0
 def process_pass(self):
     self._result = ExecodeManager.enqueue_execode(
         self._sender_oid, Execode.AR_ADD, AutoReplyModuleExecodeModel,
         Keyword=AutoReplyContentModel(Content=self._keyword, ContentType=self._keyword_type),
         Responses=self._responses, Pinned=self._pinned, Private=self._pinned, TagIds=self._tags,
         CooldownSec=self._cooldown)
Beispiel #6
0
 def process_pass(self):
     self._result = list(
         ExecodeManager.get_queued_execodes(self._sender_oid))
Beispiel #7
0
 def pre_process(self):
     self._handle_execode_()
     self._handle_action_type_()
     self._result = ExecodeManager.complete_execode(
         self._execode, self.param_dict, action=self._action_type)
Beispiel #8
0
 def process_pass(self):
     self._result = ExecodeManager.enqueue_execode(self._sender_oid,
                                                   Execode.REGISTER_CHANNEL)
Beispiel #9
0
def add_auto_reply_module_execode(
        e: TextMessageEventObject,
        execode: str) -> List[HandledMessageEventText]:
    get_excde_result = ExecodeManager.get_execode_entry(
        execode, Execode.AR_ADD)

    if not get_excde_result.success:
        return [
            HandledMessageEventText(content=_(
                "Failed to get the Execode data using the Execode `{}`. Code: `{}`"
            ).format(execode, get_excde_result.outcome))
        ]

    excde_entry = get_excde_result.model

    if e.user_model.id != excde_entry.creator_oid:
        return [
            HandledMessageEventText(content=_(
                "The ID of the creator of this Execode: `{}` does not match your ID: `{}`.\n"
                "Only the creator of this Execode can complete this action."
            ).format(excde_entry.creator_oid, e.user_model.id))
        ]

    try:
        ar_model = AutoReplyModuleExecodeModel(**excde_entry.data,
                                               from_db=True).to_actual_model(
                                                   e.channel_oid,
                                                   excde_entry.creator_oid)
    except Exception as ex:
        MailSender.send_email_async(
            "Failed to construct an Auto-reply module using Execode.<br>"
            f"User ID: {e.user_model.id}<br>"
            f"Channel ID: {e.channel_oid}<br>"
            f"Execode: {excde_entry.execode}<br>"
            f"Exception: <pre>{traceback.format_exception(None, ex, ex.__traceback__)}</pre>",
            subject="Failed to construct AR module")

        return [
            HandledMessageEventText(content=_(
                "Failed to create auto-reply module. An error report was sent for investigation."
            ))
        ]

    add_result = AutoReplyManager.add_conn_by_model(ar_model)

    if not add_result.success:
        MailSender.send_email_async(
            "Failed to register an Auto-reply module using model.\n"
            f"User ID: {e.user_model.id}\n"
            f"Channel ID: {e.channel_oid}\n"
            f"Execode: {excde_entry.execode}\n"
            f"Add result json: {add_result.serialize()}",
            subject="Failed to construct AR module")

        return [
            HandledMessageEventText(content=_(
                "Failed to register the auto-reply module. Code: `{}`").format(
                    add_result.outcome))
        ]

    ExecodeManager.remove_execode(execode)

    return [
        HandledMessageEventText(content=_("Auto-reply module registered."))
    ]