Skip to content

Commit

Permalink
[MIG] mail_restrict_follower_selection: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimkhoi3010 committed Nov 13, 2024
1 parent c1e57ae commit bc04901
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 46 deletions.
16 changes: 8 additions & 8 deletions mail_restrict_follower_selection/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ Restrict follower selection
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github
:target: https://github.com/OCA/social/tree/18.0/mail_restrict_follower_selection
:alt: OCA/social
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmail-lightgray.png?logo=github
:target: https://github.com/OCA/mail/tree/18.0/mail_restrict_follower_selection
:alt: OCA/mail
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/social-18-0/social-18-0-mail_restrict_follower_selection
:target: https://translation.odoo-community.org/projects/mail-18-0/mail-18-0-mail_restrict_follower_selection
: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=18.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/mail&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -61,10 +61,10 @@ Note: This module won't change existing followers!
Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/social/issues>`_.
Bugs are tracked on `GitHub Issues <https://github.com/OCA/mail/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_restrict_follower_selection%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/mail/issues/new?body=module:%20mail_restrict_follower_selection%0Aversion:%2018.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 Down Expand Up @@ -100,6 +100,6 @@ 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.

This module is part of the `OCA/social <https://github.com/OCA/social/tree/18.0/mail_restrict_follower_selection>`_ project on GitHub.
This module is part of the `OCA/mail <https://github.com/OCA/mail/tree/18.0/mail_restrict_follower_selection>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 2 additions & 2 deletions mail_restrict_follower_selection/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

{
"name": "Restrict follower selection",
"version": "17.0.1.0.0",
"version": "18.0.1.0.0",
"author": "Therp BV,Creu Blanca,Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Social Network",
"website": "https://github.com/OCA/social",
"website": "https://github.com/OCA/mail",
"summary": "Define a domain from which followers can be selected",
"depends": ["mail"],
"data": ["data/ir_config_parameter.xml", "data/ir_actions.xml"],
Expand Down
8 changes: 5 additions & 3 deletions mail_restrict_follower_selection/models/mail_followers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ def _add_followers(
check_existing=check_existing,
existing_policy=existing_policy,
)
domain = self.env[
"mail.wizard.invite"
]._mail_restrict_follower_selection_get_domain(res_model=res_model)
domain = str(
self.env["mail.wizard.invite"]._mail_restrict_follower_selection_get_domain(
res_model=res_model
)
)
partners = self.env["res.partner"].search(
[("id", "in", partner_ids)]
+ safe_eval(
Expand Down
26 changes: 13 additions & 13 deletions mail_restrict_follower_selection/models/mail_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ def _message_add_suggested_recipient(
"mail.wizard.invite"
]._mail_restrict_follower_selection_get_domain()
eval_domain = safe_eval(
domain, locals_dict={"ref": lambda str_id: _id_get(self.env, str_id)}
str(domain), locals_dict={"ref": lambda str_id: _id_get(self.env, str_id)}
)
for key in result:
items_to_remove = []
for item in result[key]:
partner_id = item[0]
if partner_id:
partner = self.env["res.partner"].search(
[("id", "=", partner_id)] + eval_domain
)
if not partner:
items_to_remove.append(item)
for item in items_to_remove:
result[key].remove(item)
items_to_remove = []
for item in result:
partner_id = item.get("partner_id", False)
if partner_id:
partner_count = self.env["res.partner"].search_count(
[("id", "=", partner_id)] + eval_domain
)
if not partner_count:
items_to_remove.append(item)
for item in items_to_remove:
result.remove(item)

return result
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def get_view(self, view_id=None, view_type="form", **options):
arch = etree.fromstring(result["arch"])
domain = self._mail_restrict_follower_selection_get_domain()
eval_domain = safe_eval(
domain, locals_dict={"ref": lambda str_id: _id_get(self.env, str_id)}
str(domain), locals_dict={"ref": lambda str_id: _id_get(self.env, str_id)}
)
for field in arch.xpath('//field[@name="partner_ids"]'):
field.attrib["domain"] = str(eval_domain)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ <h1 class="title">Restrict follower selection</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:5afe605fd4213b36044bc3ff7b459c564bbb92a3bbad79765ad83bd596d687ff
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/social/tree/18.0/mail_restrict_follower_selection"><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-18-0/social-18-0-mail_restrict_follower_selection"><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=18.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="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/mail/tree/18.0/mail_restrict_follower_selection"><img alt="OCA/mail" src="https://img.shields.io/badge/github-OCA%2Fmail-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/mail-18-0/mail-18-0-mail_restrict_follower_selection"><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/mail&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module was written to allow you to restrict the selection of
possible followers. For example, if you use the social ERP functions
only internally, it makes sense to filter possible followers for being
Expand Down Expand Up @@ -405,10 +405,10 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/social/issues">GitHub Issues</a>.
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/mail/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_restrict_follower_selection%0Aversion:%2018.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/mail/issues/new?body=module:%20mail_restrict_follower_selection%0Aversion:%2018.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 Down Expand Up @@ -441,7 +441,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<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>This module is part of the <a class="reference external" href="https://github.com/OCA/social/tree/18.0/mail_restrict_follower_selection">OCA/social</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/mail/tree/18.0/mail_restrict_follower_selection">OCA/mail</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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def setUp(self):
def _use_ref_in_domain(self):
"""Change the general domain to test the safe_eval."""
param = self.env.ref("mail_restrict_follower_selection.parameter_domain")
param.value = "[('country_id', '!=', ref('base.ch'))]"
country_id = self.env.ref("base.ch").id
param.value = f"[('country_id', '!=', {country_id})]"

def test_fields_view_get(self):
result = self.env["mail.wizard.invite"].get_view(view_type="form")
Expand Down Expand Up @@ -78,18 +79,18 @@ def test_followers_not_meet(self):
def test_message_add_suggested_recipient(self):
res = self.partner.with_context(
test_restrict_follower=True
)._message_add_suggested_recipient({self.partner.id: []}, partner=self.partner)
self.assertEqual(res[self.partner.id][0][0], self.partner.id)
)._message_add_suggested_recipient([], partner=self.partner)
self.assertEqual(res[0]["partner_id"], self.partner.id)

new_res = self.partner.with_context(
test_restrict_follower=True
)._message_add_suggested_recipient({self.partner.id: []})
self.assertFalse(new_res[self.partner.id][0][0])
)._message_add_suggested_recipient([])
self.assertFalse(new_res[0].get("partner_id"))

def test_fields_view_get_eval(self):
def test_get_view_eval(self):
"""Check using safe_eval in field_view_get."""
self._use_ref_in_domain()
result = self.env["mail.wizard.invite"].fields_view_get(view_type="form")
result = self.env["mail.wizard.invite"].get_view(view_type="form")
for field in etree.fromstring(result["arch"]).xpath(
'//field[@name="partner_ids"]'
):
Expand All @@ -101,13 +102,10 @@ def test_message_add_suggested_recipient_eval(self):
"""Check using safe_eval when adding recipients."""
self._use_ref_in_domain()
partner = self.partner.with_context(test_restrict_follower=True)
res = partner._message_add_suggested_recipient(
{self.partner.id: []}, partner=self.partner
)
self.assertEqual(res[self.partner.id][0][0], self.partner.id)
res = partner._message_add_suggested_recipient([], partner=self.partner)
self.assertEqual(res[0]["partner_id"], self.partner.id)

# Partner from Swizterland should be excluded
partner.country_id = self.switzerland
res = partner._message_add_suggested_recipient(
{self.partner.id: []}, partner=self.partner
)
self.assertFalse(res[self.partner.id])
res = partner._message_add_suggested_recipient([], partner=self.partner)
self.assertFalse(res)

0 comments on commit bc04901

Please sign in to comment.