Skip to content

Commit

Permalink
[IMP] mail_partner_opt_out: add or remove from blacklist in mass.
Browse files Browse the repository at this point in the history
This implementation allows users to add or remove users emails from the blacklist in mass.
  • Loading branch information
MarinaAForgeFlow committed Sep 12, 2024
1 parent c76689c commit 47c61fd
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 6 deletions.
10 changes: 9 additions & 1 deletion mail_partner_opt_out/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ Mail Partner Opt Out

This module adds the capability for a user to add a partner's email address
to the blackmail list so that she will not receive any emails from mass
mailing campaigns
mailing campaigns.
It also allows the users to add or remove emails from the blacklist in mass,
by adding an action on the res.partner list view.

**Table of contents**

Expand All @@ -48,6 +50,11 @@ will be removed from the blacklist.
You can also filter for the Blacklist attribute, to see all the partner's that
their email has been added to the blacklist.

To add or remove emails to the blacklist in mass, go to the partners list view and select
the records of partners that must be added or removed from the blacklist. Press action,
and then "Add To Blacklist" or "Remove From Blacklist". For the remove case, a wizard will
open where you can specify the reason of the removal.

Bug Tracker
===========

Expand All @@ -72,6 +79,7 @@ Contributors
* ForgeFlow, S.L. (contact@forgeflow.com)

* Jordi Ballester Alomar (jordi.ballester@forgeflow.com)
* Marina Alapont (marina.alapont@forgeflow.com)

Maintainers
~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions mail_partner_opt_out/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from . import wizard
3 changes: 2 additions & 1 deletion mail_partner_opt_out/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
{
"name": "Mail Partner Opt Out",
"summary": "Add the partner's email to the blackmailed list",
"summary": "Add the partner's email to the blackmailed list. "
"Allow also removing or adding partners emails to the backlist in mass.",
"version": "16.0.1.0.0",
"development_status": "Beta",
"category": "Social Network",
Expand Down
13 changes: 12 additions & 1 deletion mail_partner_opt_out/models/mail_thread_blacklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,15 @@ class MailBlackListMixin(models.AbstractModel):
def mail_blacklist_add(self):
for rec in self:
if not rec.is_blacklisted and rec.email:
self.env["mail.blacklist"].sudo()._add(self.email)
self.env["mail.blacklist"].sudo()._add(rec.email)

Check warning on line 10 in mail_partner_opt_out/models/mail_thread_blacklist.py

View check run for this annotation

Codecov / codecov/patch

mail_partner_opt_out/models/mail_thread_blacklist.py#L10

Added line #L10 was not covered by tests

def mail_action_blacklist_remove(self):
emails_list = [
record.email for record in self if record.email and record.is_blacklisted
]
emails_str = ",".join(emails_list)
context = self.env.context.copy()
context["default_email"] = emails_str
res = super(MailBlackListMixin, self).mail_action_blacklist_remove()
res["context"] = context
return res

Check warning on line 21 in mail_partner_opt_out/models/mail_thread_blacklist.py

View check run for this annotation

Codecov / codecov/patch

mail_partner_opt_out/models/mail_thread_blacklist.py#L16-L21

Added lines #L16 - L21 were not covered by tests
1 change: 1 addition & 0 deletions mail_partner_opt_out/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* ForgeFlow, S.L. (contact@forgeflow.com)

* Jordi Ballester Alomar (jordi.ballester@forgeflow.com)
* Marina Alapont (marina.alapont@forgeflow.com)
4 changes: 3 additions & 1 deletion mail_partner_opt_out/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
This module adds the capability for a user to add a partner's email address
to the blackmail list so that she will not receive any emails from mass
mailing campaigns
mailing campaigns.
It also allows the users to add or remove emails from the blacklist in mass,
by adding an action on the res.partner list view.
5 changes: 5 additions & 0 deletions mail_partner_opt_out/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ will be removed from the blacklist.

You can also filter for the Blacklist attribute, to see all the partner's that
their email has been added to the blacklist.

To add or remove emails to the blacklist in mass, go to the partners list view and select
the records of partners that must be added or removed from the blacklist. Press action,
and then "Add To Blacklist" or "Remove From Blacklist". For the remove case, a wizard will
open where you can specify the reason of the removal.
10 changes: 8 additions & 2 deletions mail_partner_opt_out/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 Down Expand Up @@ -372,7 +371,9 @@ <h1 class="title">Mail Partner Opt Out</h1>
<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/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_partner_opt_out"><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_partner_opt_out"><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>This module adds the capability for a user to add a partner’s email address
to the blackmail list so that she will not receive any emails from mass
mailing campaigns</p>
mailing campaigns.
It also allows the users to add or remove emails from the blacklist in mass,
by adding an action on the res.partner list view.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand All @@ -394,6 +395,10 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
will be removed from the blacklist.</p>
<p>You can also filter for the Blacklist attribute, to see all the partner’s that
their email has been added to the blacklist.</p>
<p>To add or remove emails to the blacklist in mass, go to the partners list view and select
the records of partners that must be added or removed from the blacklist. Press action,
and then “Add To Blacklist” or “Remove From Blacklist”. For the remove case, a wizard will
open where you can specify the reason of the removal.</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
Expand All @@ -418,6 +423,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<blockquote>
<ul class="simple">
<li>Jordi Ballester Alomar (<a class="reference external" href="mailto:jordi.ballester&#64;forgeflow.com">jordi.ballester&#64;forgeflow.com</a>)</li>
<li>Marina Alapont (<a class="reference external" href="mailto:marina.alapont&#64;forgeflow.com">marina.alapont&#64;forgeflow.com</a>)</li>
</ul>
</blockquote>
</li>
Expand Down
18 changes: 18 additions & 0 deletions mail_partner_opt_out/views/res_partner_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,22 @@
</field>
</field>
</record>
<record model="ir.actions.server" id="action_mail_blacklist_add">
<field name="name">Add To Blacklist</field>
<field name="model_id" ref="base.model_res_partner" />
<field name="binding_model_id" ref="base.model_res_partner" />
<field name="state">code</field>
<field name="code">
action = records.mail_blacklist_add()
</field>
</record>
<record model="ir.actions.server" id="action_mail_blacklist_remove">
<field name="name">Remove From Blacklist</field>
<field name="model_id" ref="base.model_res_partner" />
<field name="binding_model_id" ref="base.model_res_partner" />
<field name="state">code</field>
<field name="code">
action = records.mail_action_blacklist_remove()
</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions mail_partner_opt_out/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import mail_blacklist_remove
11 changes: 11 additions & 0 deletions mail_partner_opt_out/wizard/mail_blacklist_remove.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from odoo import models


class MailBlacklistRemove(models.TransientModel):
_inherit = "mail.blacklist.remove"

def action_unblacklist_apply(self):
email_list = [email.strip() for email in self.email.split(",")]
for email in email_list:
self.env["mail.blacklist"].action_remove_with_reason(email, self.reason)
return {"type": "ir.actions.act_window_close"}

Check warning on line 11 in mail_partner_opt_out/wizard/mail_blacklist_remove.py

View check run for this annotation

Codecov / codecov/patch

mail_partner_opt_out/wizard/mail_blacklist_remove.py#L10-L11

Added lines #L10 - L11 were not covered by tests

0 comments on commit 47c61fd

Please sign in to comment.