Skip to content

Commit

Permalink
[ADD]mute_notification_user_autosubscribe: Do not send notification t…
Browse files Browse the repository at this point in the history
…o users autosubscribed through user_id field
  • Loading branch information
manuelregidor committed Oct 11, 2024
1 parent ed82ad5 commit 05d89e0
Show file tree
Hide file tree
Showing 18 changed files with 931 additions and 0 deletions.
118 changes: 118 additions & 0 deletions mute_notification_user_autosubscribe/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
====================================
Mute Notification User Autosubscribe
====================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:a4066de365398f1629027be5bf5dd6fcc6fdc886eb81465f8f8224f603dd1333
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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/17.0/mute_notification_user_autosubscribe
:alt: OCA/social
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/social-17-0/social-17-0-mute_notification_user_autosubscribe
: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=17.0
:alt: Try me on Runboat

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

This module allows to select users and/or groups whose members do not
have to be sent notifications through the chatter. The models in which
these rules have to be applied can also be selected.

**Table of contents**

.. contents::
:local:

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

To configure this module you need to:

- Go to Settings > Technical > Auto Subscribe Mute
- Create a new instance or edit an exiting one. The following fields
are available:

- **Name**. The name of the rule.
- **Model**. Model in which the rule is applied. Only models with a
user_id field can be selected.
- **Users**. List of users which the rule will be applied to. The
users in this field will be autosubscribed to the document when
they are set in the user_id field but only with the "Muted"
subtype, which notifies nothing. Note that this rule will not be
applied when the user in the list set itself in the user_id field,
as the subscription in this case depends on the creation of the
document, not the autosubscription.
- **Groups**. List of groups which the rule will be applied to. The
users that belong to the groups in this field will be
autosubscribed to the document when they are set in the user_id
field but only with the "Muted" subtype, which notifies nothing.
Note that this rule will not be applied when a user in any of the
groups in the list set itself in the user_id field, as the
subscription in this case depends on the creation of the document,
not the autosubscription.
- **Notes**. Text field.

Usage
=====

In case a user that has been automatically applied the "Mute" message
subtype in a subscription through one of the rules provided in this
module needs to be sent notifications in a specific document, just edit
the subscription and select the subtypes for which the user has to be
sent notifications.

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:%20mute_notification_user_autosubscribe%0Aversion:%2017.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
-------

* Sygel

Contributors
------------

- Manuel Regidor <manuel.regidor@sygel.es>
- Valentín Vinagre <valentin.vinagre@sygel.es>
- Harald Panten <harald.panten@sygel.es>

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/17.0/mute_notification_user_autosubscribe>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions mute_notification_user_autosubscribe/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2024 Manuel Regidor <manuel.regidor@sygel.es>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
21 changes: 21 additions & 0 deletions mute_notification_user_autosubscribe/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 Manuel Regidor <manuel.regidor@sygel.es>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Mute Notification User Autosubscribe",
"summary": "Do not send notifications to users autosubcribed through user_id field",
"version": "17.0.1.0.0",
"category": "Social",
"website": "https://github.com/OCA/social",
"author": "Sygel,Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": [
"mail",
],
"data": [
"data/mail_message_subtype_data.xml",
"security/ir.model.access.csv",
"views/user_autosubscribe_mute_views.xml",
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="muted" model="mail.message.subtype">
<field name="name">Mute</field>
<field name="default" eval="False" />
<field name="sequence">999</field>
</record>
</odoo>
5 changes: 5 additions & 0 deletions mute_notification_user_autosubscribe/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2024 Manuel Regidor <manuel.regidor@sygel.es>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import user_autosubscribe_mute
from . import mail_thread
41 changes: 41 additions & 0 deletions mute_notification_user_autosubscribe/models/mail_thread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2024 Manuel Regidor <manuel.regidor@sygel.es>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models


class MailThread(models.AbstractModel):
_inherit = "mail.thread"

def _mute_user_autosubscribe_vals(self, vals, user):
final_vals = vals
field = self._fields.get("user_id")
if field and user:
model = self.env["ir.model"]._get(self._name)
if self.env["user.autosubscribe.mute"].is_mute_user(model, user):
subtype = self.env.ref("mute_notification_user_autosubscribe.muted")
partner_id = user.partner_id.id
final_vals = [p for p in vals if p[0] != partner_id]
final_vals += [
(p[0], [subtype.id], p[2]) for p in vals if p[0] == partner_id
]
return final_vals

def _message_auto_subscribe_followers(self, updated_values, default_subtype_ids):
vals = super()._message_auto_subscribe_followers(
updated_values, default_subtype_ids
)
if vals:
user_id = updated_values.get("user_id")
if user_id:
user = self.env["res.users"].browse(user_id)
partner_id = user.partner_id.id
# Do nothing in case the user is already subscribe.
# It happes, for example, when it is the user_id who creates
# the document
if (
partner_id not in self.message_partner_ids.ids
and updated_values.get("user_id")
):
vals = self._mute_user_autosubscribe_vals(vals, user)
return vals
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2024 Manuel Regidor <manuel.regidor@sygel.es>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models


class UserAutosubscribeMute(models.Model):
_name = "user.autosubscribe.mute"
_description = "User Autosubscribe Mute"

def _get_user_models_domain(self):
models = (
self.env["ir.model.fields"]
.search([("name", "=", "user_id"), ("relation", "=", "res.users")])
.mapped("model_id")
)
return f"[('id', 'in', {models.ids})]"

name = fields.Char(required=True)
active = fields.Boolean(default=True)
model_id = fields.Many2one(
comodel_name="ir.model",
domain=_get_user_models_domain,
ondelete="cascade",
required=True,
)
user_ids = fields.Many2many(comodel_name="res.users", string="Users")
group_ids = fields.Many2many(comodel_name="res.groups", string="Groups")
notes = fields.Text()

_sql_constraints = [
(
"unique_model_id",
"UNIQUE(model_id)",
_("Model must be unique in User Autosubscribe Mute instances."),
)
]

@api.model
def is_mute_user(self, model, user):
mute = False
user_autosubscribe_mute = self.search([("model_id", "=", model.id)], limit=1)
if user_autosubscribe_mute:
groups = (
",".join(user_autosubscribe_mute.group_ids.get_external_id().values())
or ""
)
if user.id in user_autosubscribe_mute.user_ids.ids or (
groups and user.user_has_groups(groups)
):
mute = True
return mute
3 changes: 3 additions & 0 deletions mute_notification_user_autosubscribe/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
9 changes: 9 additions & 0 deletions mute_notification_user_autosubscribe/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
To configure this module you need to:

- Go to Settings > Technical > Auto Subscribe Mute
- Create a new instance or edit an exiting one. The following fields are available:
- **Name**. The name of the rule.
- **Model**. Model in which the rule is applied. Only models with a user_id field can be selected.
- **Users**. List of users which the rule will be applied to. The users in this field will be autosubscribed to the document when they are set in the user_id field but only with the "Muted" subtype, which notifies nothing. Note that this rule will not be applied when the user in the list set itself in the user_id field, as the subscription in this case depends on the creation of the document, not the autosubscription.
- **Groups**. List of groups which the rule will be applied to. The users that belong to the groups in this field will be autosubscribed to the document when they are set in the user_id field but only with the "Muted" subtype, which notifies nothing. Note that this rule will not be applied when a user in any of the groups in the list set itself in the user_id field, as the subscription in this case depends on the creation of the document, not the autosubscription.
- **Notes**. Text field.
3 changes: 3 additions & 0 deletions mute_notification_user_autosubscribe/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Manuel Regidor \<<manuel.regidor@sygel.es>\>
- Valentín Vinagre \<<valentin.vinagre@sygel.es>\>
- Harald Panten \<<harald.panten@sygel.es>\>
1 change: 1 addition & 0 deletions mute_notification_user_autosubscribe/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module allows to select users and/or groups whose members do not have to be sent notifications through the chatter. The models in which these rules have to be applied can also be selected.
1 change: 1 addition & 0 deletions mute_notification_user_autosubscribe/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In case a user that has been automatically applied the "Mute" message subtype in a subscription through one of the rules provided in this module needs to be sent notifications in a specific document, just edit the subscription and select the subtypes for which the user has to be sent notifications.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
"user_autosubscribe_mute_access","user.autosubscribe.mute.access","model_user_autosubscribe_mute",base.group_user,1,0,0,0
"user_autosubscribe_mute_manage","user.autosubscribe.mute.manage","model_user_autosubscribe_mute",base.group_system,1,1,1,1
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 05d89e0

Please sign in to comment.