From a610d9116fadf33fceb09bbc54428f1430371267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BD=A9=E8=99=B9=E5=B7=A5=E4=BD=9C=E5=AE=A4?= Date: Sun, 30 Jan 2022 20:03:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=A7=8B=E9=87=8D=E6=9E=84=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- wecom_api/models/res_config_settings.py | 2 - wecom_api/views/res_config_settings_views.xml | 4 +- wecom_auth_oauth/__manifest__.py | 2 - wecom_auth_oauth/models/res_users.py | 150 +-- wecom_auth_oauth/views/res_users_views.xml | 28 - wecom_contacts/__init__.py | 6 + wecom_contacts/__manifest__.py | 22 + wecom_contacts/static/description/icon.png | Bin 0 -> 13681 bytes wecom_message/__manifest__.py | 13 +- wecom_message/data/auth_signup_data.xml | 96 ++ wecom_message/i18n/zh_CN.po | 914 ++++-------------- wecom_message/models/__init__.py | 12 +- wecom_message/models/mail_mail.py | 415 ++------ wecom_message/models/mail_message.py | 2 + wecom_message/models/mail_template.py | 35 +- wecom_message/models/res_config_settings.py | 4 +- wecom_message/models/res_users.py | 147 +++ .../security/ir.model.access copy.csv | 2 + wecom_message/security/ir.model.access.csv | 3 +- .../views/mail_template_views copy.xml | 147 +++ wecom_message/views/mail_template_views.xml | 75 +- wecom_message/views/menu.xml | 2 +- .../views/res_config_settings_views.xml | 2 +- wecom_message/views/res_users_views.xml | 21 +- wecom_portal/__manifest__.py | 4 +- wecom_portal/data/wecom_portal_data.xml | 14 +- 27 files changed, 788 insertions(+), 1336 deletions(-) delete mode 100644 wecom_auth_oauth/views/res_users_views.xml create mode 100644 wecom_contacts/__init__.py create mode 100644 wecom_contacts/__manifest__.py create mode 100644 wecom_contacts/static/description/icon.png create mode 100644 wecom_message/data/auth_signup_data.xml create mode 100644 wecom_message/models/res_users.py create mode 100644 wecom_message/views/mail_template_views copy.xml diff --git a/README.md b/README.md index 73c47dac..3d415258 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ - [路径](/docker) > TODO : -- 重构企业微信消息功能 +- 重构企业微信消息功能,在继承mail和不继承mail反复横跳,最终决定还是继承mail - 使用ReadtheDocs上线文档 ## 功能模块介绍 diff --git a/wecom_api/models/res_config_settings.py b/wecom_api/models/res_config_settings.py index 65bea008..8873dbda 100644 --- a/wecom_api/models/res_config_settings.py +++ b/wecom_api/models/res_config_settings.py @@ -42,8 +42,6 @@ class ResConfigSettings(models.TransientModel): module_wecom_material = fields.Boolean("WeCom media material library") module_wecom_message = fields.Boolean("WeCom send message") module_wecom_auth_oauth = fields.Boolean("WeCom Authentication") - - # 专业版模块 module_wecom_msgaudit = fields.Boolean("Manage Session Content Archive") # contacts_auto_sync_hr_enabled = fields.Boolean( diff --git a/wecom_api/views/res_config_settings_views.xml b/wecom_api/views/res_config_settings_views.xml index a2d10b57..f4f26642 100644 --- a/wecom_api/views/res_config_settings_views.xml +++ b/wecom_api/views/res_config_settings_views.xml @@ -170,7 +170,7 @@ -
+
@@ -200,7 +200,7 @@ -
+
diff --git a/wecom_auth_oauth/__manifest__.py b/wecom_auth_oauth/__manifest__.py index 75b826eb..4d5b4115 100644 --- a/wecom_auth_oauth/__manifest__.py +++ b/wecom_auth_oauth/__manifest__.py @@ -20,10 +20,8 @@ "data/wecom_apps_data.xml", "data/wecom_app_config_data.xml", "data/wecom_oauth_data.xml", - # "data/auth_signup_data.xml", "views/assets_templates.xml", "views/res_config_settings_views.xml", - "views/res_users_views.xml", "views/wecom_apps_views.xml", "views/menu_views.xml", ], diff --git a/wecom_auth_oauth/models/res_users.py b/wecom_auth_oauth/models/res_users.py index 6cea0b91..d0b2c990 100644 --- a/wecom_auth_oauth/models/res_users.py +++ b/wecom_auth_oauth/models/res_users.py @@ -1,23 +1,9 @@ # -*- coding: utf-8 -*- -import logging -import json -import requests - -from collections import defaultdict -from dateutil.relativedelta import relativedelta -from odoo import models, fields, api, _ -from odoo.exceptions import UserError -from odoo.addons.base.models.ir_mail_server import MailDeliveryException -from odoo.addons.auth_signup.models.res_partner import SignupError, now +from odoo import models, api, _ from odoo.exceptions import AccessDenied -_logger = logging.getLogger(__name__) - -from odoo.http import request - - class ResUsers(models.Model): _inherit = "res.users" @@ -71,137 +57,3 @@ def _check_credentials(self, password, env): if not res: raise - # --------------------- - # 发送消息 - # --------------------- - def action_reset_password(self): - """ - 为每个用户创建注册令牌,并通过电子邮件发送他们的注册url - 增加判断模板对象为企业微信用户,使用企业微信发送模板消息的方法 - """ - if self.env.context.get("install_mode", False): - return - if self.filtered(lambda user: not user.active): - raise UserError(_("You cannot perform this action on an archived user.")) - # prepare reset password signup - create_mode = bool(self.env.context.get("create_user")) - - # no time limit for initial invitation, only for reset password - expiration = False if create_mode else now(days=+1) - - self.mapped("partner_id").signup_prepare( - signup_type="reset", expiration=expiration - ) - - # send email to users with their signup url - template = False - if create_mode: - try: - template = self.env.ref( - "auth_signup.set_password_email", raise_if_not_found=False - ) - except ValueError: - pass - if not template: - template = self.env.ref("auth_signup.reset_password_email") - assert template._name == "mail.template" - template_values = { - "email_to": "${object.email|safe}", - "email_cc": False, - "auto_delete": True, - "partner_to": False, - "scheduled_date": False, - } - template.write(template_values) - for user in self: - if user.wecom_userid: - return self.action_reset_password_by_wecom(user, create_mode) - elif not user.email: - raise UserError( - _("Cannot send email: user %s has no email address.", user.name) - ) - # TDE FIXME: make this template technical (qweb) - with self.env.cr.savepoint(): - force_send = not (self.env.context.get("import_file", False)) - template.send_mail(user.id, force_send=force_send, raise_exception=True) - _logger.info( - "Password reset email sent for user <%s> to <%s>", - user.login, - user.email, - ) - return super(ResUsers, self).action_reset_password() - - def action_reset_password_by_wecom(self, user, create_mode): - """ - 通过企业微信的方式发送模板消息 - """ - create_mode = bool(self.env.context.get("create_user")) - if create_mode: - template = self.env.ref("wecom_auth_oauth.set_password_message") - else: - template = self.env.ref("wecom_auth_oauth.reset_password_message") - assert template._name == "wecom.message.template" - template_values = { - "message_to_user": "${object.wecom_userid|safe}", - "auto_delete": True, - "partner_to": False, - "scheduled_date": False, - } - template.write(template_values) - with self.env.cr.savepoint(): - force_send = not (self.env.context.get("import_file", False)) - template.send_message( - user.id, force_send=force_send, raise_exception=True, - ) - _logger.info( - _("Password reset message sent to user: <%s>,<%s>, <%s>"), - user.name, - user.login, - user.wecom_userid, - ) - - def send_unregistered_user_reminder(self, after_days=5): - """ - 发送未注册的用户提醒 消息 - """ - datetime_min = fields.Datetime.today() - relativedelta(days=after_days) - datetime_max = datetime_min + relativedelta(hours=23, minutes=59, seconds=59) - - res_users_with_details = self.env["res.users"].search_read( - [ - ("share", "=", False), - ("create_uid.email", "!=", False), - ("create_date", ">=", datetime_min), - ("create_date", "<=", datetime_max), - ("log_ids", "=", False), - ], - ["create_uid", "name", "login"], - ) - - # 分组邀请 - invited_users = defaultdict(list) - for user in res_users_with_details: - invited_users[user.get("create_uid")[0]].append( - "%s (%s)" % (user.get("name"), user.get("login")) - ) - - # 用于向所有邀请者发送有关其邀请用户的邮件 - for user in invited_users: - if user.wecom_userid: - return self.send_unregistered_user_reminder_by_wecom( - user, invited_users - ) - template = self.env.ref( - "auth_signup.mail_template_data_unregistered_users" - ).with_context(dbname=self._cr.dbname, invited_users=invited_users[user]) - template.send_mail( - user, notif_layout="mail.mail_notification_light", force_send=False - ) - - def send_unregistered_user_reminder_by_wecom(self, user, invited_users): - message_template = self.env.ref( - "wecom_auth_oauth.message_template_data_unregistered_users" - ).with_context(dbname=self._cr.dbname, invited_users=invited_users[user]) - message_template.send_message( - user, notif_layout="mail.mail_notification_light", force_send=False - ) diff --git a/wecom_auth_oauth/views/res_users_views.xml b/wecom_auth_oauth/views/res_users_views.xml deleted file mode 100644 index 85828fbb..00000000 --- a/wecom_auth_oauth/views/res_users_views.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - res.users.form.inherit - res.users - - - - - - - -
-
-
- +