Skip to content

Commit

Permalink
[MIG] mail_server_by_user: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteMeAsap committed Jul 23, 2024
1 parent 89fb261 commit 4bbed15
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 40 deletions.
11 changes: 6 additions & 5 deletions mail_server_by_user/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Email Server By User
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github
:target: https://github.com/OCA/social/tree/14.0/mail_server_by_user
:target: https://github.com/OCA/social/tree/16.0/mail_server_by_user
:alt: OCA/social
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/social-14-0/social-14-0-mail_server_by_user
:target: https://translation.odoo-community.org/projects/social-16-0/social-16-0-mail_server_by_user
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/social&target_branch=14.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/social&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand All @@ -47,7 +47,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/social/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/social/issues/new?body=module:%20mail_server_by_user%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/social/issues/new?body=module:%20mail_server_by_user%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand All @@ -63,6 +63,7 @@ Contributors
~~~~~~~~~~~~

* Christopher Ormaza <[email protected]>
* `Onestein <https://www.onestein.eu>`__

Maintainers
~~~~~~~~~~~
Expand All @@ -85,6 +86,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-ChrisOForgeFlow|

This module is part of the `OCA/social <https://github.com/OCA/social/tree/14.0/mail_server_by_user>`_ project on GitHub.
This module is part of the `OCA/social <https://github.com/OCA/social/tree/16.0/mail_server_by_user>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion mail_server_by_user/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Email Server By User",
"summary": "Email Server By User",
"version": "14.0.1.0.0",
"version": "16.0.1.0.0",
"category": "Social Network",
"website": "https://github.com/OCA/social",
"author": ("ForgeFlow, " "Odoo Community Association (OCA)"),
Expand Down
5 changes: 4 additions & 1 deletion mail_server_by_user/models/ir_mail_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class IrMailServer(models.Model):

_inherit = "ir.mail_server"

@api.model
Expand All @@ -18,6 +17,8 @@ def send_email(
smtp_user=None,
smtp_password=None,
smtp_encryption=None,
smtp_ssl_certificate=None,
smtp_ssl_private_key=None,
smtp_debug=False,
smtp_session=None,
):
Expand All @@ -36,6 +37,8 @@ def send_email(
smtp_user,
smtp_password,
smtp_encryption,
smtp_ssl_certificate,
smtp_ssl_private_key,
smtp_debug,
smtp_session,
)
1 change: 0 additions & 1 deletion mail_server_by_user/models/mail_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class MailMail(models.Model):

_inherit = "mail.mail"

def _send(self, auto_commit=False, raise_exception=False, smtp_session=None):
Expand Down
19 changes: 12 additions & 7 deletions mail_server_by_user/models/mail_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@


class MailThread(models.AbstractModel):

_inherit = "mail.thread"

def _notify_record_by_email(
def _notify_thread_by_email(
self,
message,
recipients_data,
msg_vals=False,
model_description=False,
mail_auto_delete=True,
check_existing=False,
model_description=False,
force_email_company=False,
force_email_lang=False,
resend_existing=False,
force_send=True,
send_after_commit=True,
subtitles=None,
**kwargs
):
mail_server_model = self.env["ir.mail_server"].sudo()
Expand All @@ -31,14 +33,17 @@ def _notify_record_by_email(
and message.mail_server_id.id != mail_server_suggested.id
):
message.mail_server_id = mail_server_suggested.id
return super(MailThread, self)._notify_record_by_email(
return super(MailThread, self)._notify_thread_by_email(
message,
recipients_data,
msg_vals,
model_description,
mail_auto_delete,
check_existing,
model_description,
force_email_company,
force_email_lang,
resend_existing,
force_send,
send_after_commit,
subtitles,
**kwargs
)
1 change: 1 addition & 0 deletions mail_server_by_user/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* Christopher Ormaza <[email protected]>
* `Onestein <https://www.onestein.eu>`__
19 changes: 11 additions & 8 deletions mail_server_by_user/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand All @@ -9,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -369,7 +369,7 @@ <h1 class="title">Email Server By User</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:9313575d1d36133e0993e203d53247a3beb4122f34e111c8418dfb07f57733c8
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/social/tree/14.0/mail_server_by_user"><img alt="OCA/social" src="https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/social-14-0/social-14-0-mail_server_by_user"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/social&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/social/tree/16.0/mail_server_by_user"><img alt="OCA/social" src="https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/social-16-0/social-16-0-mail_server_by_user"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/social&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Change SMTP server with smtp_user equal email of
user perform mail actions, like message_post, mail.mail send, and base email sending</p>
<div class="admonition important">
Expand All @@ -395,7 +395,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/social/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/social/issues/new?body=module:%20mail_server_by_user%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/social/issues/new?body=module:%20mail_server_by_user%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -410,18 +410,21 @@ <h2><a class="toc-backref" href="#toc-entry-3">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<ul class="simple">
<li>Christopher Ormaza &lt;<a class="reference external" href="mailto:chris.ormaza&#64;forgeflow.com">chris.ormaza&#64;forgeflow.com</a>&gt;</li>
<li><a class="reference external" href="https://www.onestein.eu">Onestein</a></li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/ChrisOForgeFlow"><img alt="ChrisOForgeFlow" src="https://github.com/ChrisOForgeFlow.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/social/tree/14.0/mail_server_by_user">OCA/social</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/social/tree/16.0/mail_server_by_user">OCA/social</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
37 changes: 20 additions & 17 deletions mail_server_by_user/tests/test_mail_server_by_user.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# Copyright 2022 ForgeFlow S.L.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

import logging
import os
import threading
from email import message_from_string

from mock import MagicMock
from unittest.mock import MagicMock

from odoo import _
from odoo.tests.common import TransactionCase

_logger = logging.getLogger(__name__)


class TestIrMailServer(TransactionCase):
def setUp(self):
super(TestIrMailServer, self).setUp()
self.smtp_server_model = self.env["ir.mail_server"]
self.parameter_model = self.env["ir.config_parameter"]
self.default_template = self.env.ref("mail.message_notification_email")
self.paynow_template = self.env.ref("mail.mail_notification_paynow")
# self.default_template = self.env.ref("mail.message_notification_email")
# self.paynow_template = self.env.ref("mail.mail_notification_paynow")
self.server_1 = self.smtp_server_model.create(
{
"name": "localhost",
Expand Down Expand Up @@ -95,16 +95,13 @@ def _send_mail(self, message=None, mail_server_id=None, smtp_server=None):
if message is None:
message = self.message
connect = MagicMock()
thread = threading.currentThread()
thread.testing = False
self.smtp_server_model._patch_method("connect", connect)
try:
self.smtp_server_model._patch_method("connect", connect)
try:
self.smtp_server_model.send_email(message, mail_server_id, smtp_server)
finally:
self.smtp_server_model._revert_method("connect")
self.smtp_server_model.send_email(message, mail_server_id, smtp_server)
except Exception as e:
_logger.debug(str(e))
finally:
thread.testing = True
self.smtp_server_model._revert_method("connect")
call_args = connect.call_args
return call_args

Expand All @@ -131,15 +128,21 @@ def test_send_email_change_smtp_server(self):

def test_message_thread_send(self):
mail_message_1 = self.partner.with_user(self.user1).message_post(
body=_("Test"), subtype_xmlid="mail.mt_comment"
body=_("Test"),
subtype_xmlid="mail.mt_comment",
partner_ids=self.partner.ids,
)
self.assertEqual(mail_message_1.mail_server_id.id, self.server_1.id)
mail_message_2 = self.partner.with_user(self.user2).message_post(
body=_("Test"), subtype_xmlid="mail.mt_comment"
body=_("Test"),
subtype_xmlid="mail.mt_comment",
partner_ids=self.partner.ids,
)
self.assertEqual(mail_message_2.mail_server_id.id, self.server_2.id)
mail_message_3 = self.partner.with_user(self.user3).message_post(
body=_("Test"), subtype_xmlid="mail.mt_comment"
body=_("Test"),
subtype_xmlid="mail.mt_comment",
partner_ids=self.partner.ids,
)
self.assertFalse(mail_message_3.mail_server_id.id)

Expand Down

0 comments on commit 4bbed15

Please sign in to comment.