Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions mail_message_restrict/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
=====================
Mail Message Restrict
=====================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:7a2c5066d19ba0def08c1512dd8d44f66d1d844d2db78258a8ba35bbe72392a2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |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/15.0/mail_message_restrict
:alt: OCA/social
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/social-15-0/social-15-0-mail_message_restrict
: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=15.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module limits the creation of non-internal messages in the chatter to certain "allowed" models.
This means that, upon installation of the module, users will get an error message when they try to create
a message in the chatter, unless the model of the chatter is part of the "allowed" models.

**Table of contents**

.. contents::
:local:

Configuration
=============

#. Navigate to *Settings > Technical > Email > Subtypes*.
#. In the "Allow Send Model" field, select the models for which you want to allow sending mail.

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_message_restrict%0Aversion:%2015.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.

Credits
=======

Authors
~~~~~~~

* Quartile Limited

Contributors
~~~~~~~~~~~~

* `Quartile <https://www.quartile.co>`__:

* Aung Ko Ko Lin

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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/15.0/mail_message_restrict>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions mail_message_restrict/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
13 changes: 13 additions & 0 deletions mail_message_restrict/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2023 Quartile Limited
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Mail Message Restrict",
"category": "Mail",
"license": "AGPL-3",
"author": "Quartile Limited, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/social",
"version": "15.0.1.0.0",
"depends": ["mail"],
"data": ["views/mail_message_subtype_views.xml"],
"installable": True,
}
45 changes: 45 additions & 0 deletions mail_message_restrict/i18n/ja.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mail_message_restrict
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-06-27 04:46+0000\n"
"PO-Revision-Date: 2023-06-27 04:46+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: mail_message_restrict
#: model:ir.model.fields,field_description:mail_message_restrict.field_mail_message_subtype__allow_send_model_ids
msgid "Allow Send Model"
msgstr "メール送信可モデル"

#. module: mail_message_restrict
#: code:addons/mail_message_restrict/models/mail_message.py:0
#, python-format
msgid ""
"Creating a message in this model is blocked.Please contact the system "
"administrator as necessary."
msgstr "こちらのモデルよりメッセージを作成するには許可されません。"
"必要に応じて、システム管理者にお問い合わせください。"

#. module: mail_message_restrict
#: model:ir.model.fields,field_description:mail_message_restrict.field_mail_message_subtype__hide_allow_send_model
msgid "Hide Allow Send Model"
msgstr "メール送信可モデル非表示"

#. module: mail_message_restrict
#: model:ir.model,name:mail_message_restrict.model_mail_message
msgid "Message"
msgstr "メッセージ"

#. module: mail_message_restrict
#: model:ir.model,name:mail_message_restrict.model_mail_message_subtype
msgid "Message subtypes"
msgstr "メッセージのサブタイプ"
2 changes: 2 additions & 0 deletions mail_message_restrict/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import mail_message_subtype
from . import mail_message
31 changes: 31 additions & 0 deletions mail_message_restrict/models/mail_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2023 Quartile Limited
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, models
from odoo.exceptions import UserError
from odoo.tools import config


class MailMessage(models.Model):
_inherit = "mail.message"

@api.model
def create(self, vals):
"""Ignore blocking for other tests"""
if config["test_enable"] and not self.env.context.get(
"test_mail_message_restrict"
):
return super(MailMessage, self).create(vals)
if vals.get("message_type") == "comment":
subtype = self.env["mail.message.subtype"].browse(vals.get("subtype_id"))
if (
vals.get("model") not in subtype.allow_send_model_ids.mapped("model")
and not subtype.internal
):
raise UserError(
_(
"Creating a message in this model is blocked."
"Please contact the system administrator as necessary."
)
)
return super(MailMessage, self).create(vals)
15 changes: 15 additions & 0 deletions mail_message_restrict/models/mail_message_subtype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2023 Quartile Limited
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class MailMessageSubtype(models.Model):
_inherit = "mail.message.subtype"

allow_send_model_ids = fields.Many2many("ir.model")
hide_allow_send_model = fields.Boolean(compute="_compute_hide_allow_send_model")

def _compute_hide_allow_send_model(self):
for rec in self:
rec.hide_allow_send_model = rec != self.env.ref("mail.mt_comment")

Check warning on line 15 in mail_message_restrict/models/mail_message_subtype.py

View check run for this annotation

Codecov / codecov/patch

mail_message_restrict/models/mail_message_subtype.py#L15

Added line #L15 was not covered by tests
2 changes: 2 additions & 0 deletions mail_message_restrict/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#. Navigate to *Settings > Technical > Email > Subtypes*.
#. In the "Allow Send Model" field, select the models for which you want to allow sending mail.
3 changes: 3 additions & 0 deletions mail_message_restrict/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Quartile <https://www.quartile.co>`__:

* Aung Ko Ko Lin
3 changes: 3 additions & 0 deletions mail_message_restrict/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module limits the creation of non-internal messages in the chatter to certain "allowed" models.
This means that, upon installation of the module, users will get an error message when they try to create
a message in the chatter, unless the model of the chatter is part of the "allowed" models.
Loading