Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 9 additions & 5 deletions announcement/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

============
Announcement
============
Expand All @@ -17,7 +13,7 @@ Announcement
.. |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/license-AGPL--3-blue.png
.. |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%2Fserver--ux-lightgray.png?logo=github
Expand Down Expand Up @@ -54,6 +50,10 @@ When your user has such permissions, this is the way to create an announcement:
- Specific users: manually select which users will see the announcement.
- User groups: users from the selected groups will be the ones to see the
announcement.
- Excluded users: excluded users won't see the announcement even it is a general
announcement or belongs to selected groups.
- Excluded groups: users from the excluded groups won't see the announcement even it
is a general announcement or belongs to selected groups.
#. Define the announcement body. You can use rich formatting and event paste your
own html (editor in debug mode).
#. By default, the announcement will be archived. This is to prevent the announcement
Expand Down Expand Up @@ -111,6 +111,10 @@ Contributors
* David Vidal
* Carlos Roca

* `Dixmit <https://www.dixmit.com>`__:

* Luis David Rodríguez

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

Expand Down
20 changes: 18 additions & 2 deletions announcement/models/announcement.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ class Announcement(models.Model):
comodel_name="announcement.log",
inverse_name="announcement_id",
)
excluded_users_ids = fields.Many2many(
comodel_name="res.users",
relation="announcement_res_users_excluded_rel",
)
excluded_groups_ids = fields.Many2many(
comodel_name="res.groups",
relation="announcement_res_groups_excluded_rel",
)

def _inverse_specific_user_ids(self):
"""Used to set users unread announcements when they're set in the announcement
Expand All @@ -101,7 +109,12 @@ def _inverse_specific_user_ids(self):
):
user.unread_announcement_ids |= announcement

@api.depends("specific_user_ids", "user_group_ids")
@api.depends(
"specific_user_ids",
"user_group_ids",
"excluded_users_ids",
"excluded_groups_ids",
)
def _compute_allowed_user_ids(self):
self.allowed_user_ids = False
self.allowed_users_count = False
Expand All @@ -112,7 +125,10 @@ def _compute_allowed_user_ids(self):
announcement.allowed_user_ids = announcement.specific_user_ids
announcement.allowed_users_count = len(announcement.specific_user_ids)
for announcement in self - specific_user_announcements:
announcement.allowed_user_ids = announcement.user_group_ids.users
announcement.allowed_user_ids = announcement.user_group_ids.users.filtered(
lambda u: u not in announcement.excluded_users_ids
and not (u.groups_id & announcement.excluded_groups_ids)
)
announcement.allowed_users_count = len(announcement.user_group_ids.users)

@api.depends("is_general_announcement")
Expand Down
4 changes: 4 additions & 0 deletions announcement/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ When your user has such permissions, this is the way to create an announcement:
- Specific users: manually select which users will see the announcement.
- User groups: users from the selected groups will be the ones to see the
announcement.
- Excluded users: excluded users won't see the announcement even it is a general
announcement or belongs to selected groups.
- Excluded groups: users from the excluded groups won't see the announcement even it
is a general announcement or belongs to selected groups.
#. Define the announcement body. You can use rich formatting and event paste your
own html (editor in debug mode).
#. By default, the announcement will be archived. This is to prevent the announcement
Expand Down
4 changes: 4 additions & 0 deletions announcement/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
* Pedro M. Baeza
* David Vidal
* Carlos Roca

* `Dixmit <https://www.dixmit.com>`__:

* Luis David Rodríguez
38 changes: 20 additions & 18 deletions announcement/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>README.rst</title>
<title>Announcement</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,21 +360,16 @@
</style>
</head>
<body>
<div class="document">
<div class="document" id="announcement">
<h1 class="title">Announcement</h1>


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="announcement">
<h1>Announcement</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:48d1221c737c96b3f325fbcb04fc59606a12ab8b41a75a64691e458324e47424
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-ux/tree/16.0/announcement"><img alt="OCA/server-ux" src="https://img.shields.io/badge/github-OCA%2Fserver--ux-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-ux-16-0/server-ux-16-0-announcement"><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/server-ux&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><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/server-ux/tree/16.0/announcement"><img alt="OCA/server-ux" src="https://img.shields.io/badge/github-OCA%2Fserver--ux-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-ux-16-0/server-ux-16-0-announcement"><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/server-ux&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 popup announcements in the backend for targeted internal users. Those
announcements can contain rich format and a user read log is kept for everyone.</p>
<p><strong>Table of contents</strong></p>
Expand All @@ -393,7 +388,7 @@ <h1>Announcement</h1>
</ul>
</div>
<div class="section" id="configuration">
<h2><a class="toc-backref" href="#toc-entry-1">Configuration</a></h2>
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<p>To create new announcements a user should be in the <em>Announcements Managers</em> group.
When your user has such permissions, this is the way to create an announcement:</p>
<ol class="arabic simple">
Expand All @@ -404,6 +399,10 @@ <h2><a class="toc-backref" href="#toc-entry-1">Configuration</a></h2>
<li>Specific users: manually select which users will see the announcement.</li>
<li>User groups: users from the selected groups will be the ones to see the
announcement.</li>
<li>Excluded users: excluded users won’t see the announcement even it is a general
announcement or belongs to selected groups.</li>
<li>Excluded groups: users from the excluded groups won’t see the announcement even it
is a general announcement or belongs to selected groups.</li>
</ul>
</li>
<li>Define the announcement body. You can use rich formatting and event paste your
Expand All @@ -419,7 +418,7 @@ <h2><a class="toc-backref" href="#toc-entry-1">Configuration</a></h2>
</ol>
</div>
<div class="section" id="usage">
<h2><a class="toc-backref" href="#toc-entry-2">Usage</a></h2>
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<p>When a user in the scope of active announcements logs in, those will popup. The user
has to mark them as read to continue working. If the announcement is set during the
user session, the announcement will be eventually prompted in the top bar on the right
Expand All @@ -429,42 +428,46 @@ <h2><a class="toc-backref" href="#toc-entry-2">Usage</a></h2>
Announcement managers can also track which users have read the announcement.</p>
</div>
<div class="section" id="known-issues-roadmap">
<h2><a class="toc-backref" href="#toc-entry-3">Known issues / Roadmap</a></h2>
<h1><a class="toc-backref" href="#toc-entry-3">Known issues / Roadmap</a></h1>
<ul class="simple">
<li>It could be integrated in Discuss app to review past announcements.</li>
<li>Log other information like geolocation, IP, browser agent, etc when marking
announcement as read.</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h2>
<h1><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-ux/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/server-ux/issues/new?body=module:%20announcement%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">
<h2><a class="toc-backref" href="#toc-entry-5">Credits</a></h2>
<h1><a class="toc-backref" href="#toc-entry-5">Credits</a></h1>
<div class="section" id="authors">
<h3><a class="toc-backref" href="#toc-entry-6">Authors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-6">Authors</a></h2>
<ul class="simple">
<li>Tecnativa</li>
</ul>
</div>
<div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-7">Contributors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<ul class="simple">
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Pedro M. Baeza</li>
<li>David Vidal</li>
<li>Carlos Roca</li>
</ul>
</li>
<li><a class="reference external" href="https://www.dixmit.com">Dixmit</a>:<ul>
<li>Luis David Rodríguez</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h3>
<h2><a class="toc-backref" href="#toc-entry-8">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" />
Expand All @@ -477,6 +480,5 @@ <h3><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h3>
</div>
</div>
</div>
</div>
</body>
</html>
36 changes: 36 additions & 0 deletions announcement/tests/test_announcement.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ def setUpClass(cls):
"active": True,
}
)
cls.test_group = cls.env["res.groups"].create(
{"name": "Test Group for Exclusion", "users": [Command.link(cls.user.id)]}
)

@users("test-user-system")
def test_announcements_user_system(self):
Expand Down Expand Up @@ -92,3 +95,36 @@ def test_custom_anouncement_write(self):
{"specific_user_ids": [Command.link(self.user.id)]}
)
self.assertIn(self.custom_announcement, self.user.unread_announcement_ids)

def test_excluded_user(self):
"""If a general announcement has excluded users, those users should not see it."""
self.env.invalidate_all()
self.general_announcement._compute_allowed_user_ids()
self.assertIn(self.user, self.general_announcement.allowed_user_ids)

self.general_announcement.write(
{
"excluded_users_ids": [Command.link(self.user.id)],
}
)

self.env.invalidate_all()
self.general_announcement._compute_allowed_user_ids()
self.assertNotIn(self.user, self.general_announcement.allowed_user_ids)

def test_excluded_group(self):
"""If a general announcement has excluded groups, users in those groups
should not see it."""
self.env.invalidate_all()
self.general_announcement._compute_allowed_user_ids()
self.assertIn(self.user, self.general_announcement.allowed_user_ids)

self.general_announcement.write(
{
"excluded_groups_ids": [Command.link(self.test_group.id)],
}
)

self.env.invalidate_all()
self.general_announcement._compute_allowed_user_ids()
self.assertNotIn(self.user, self.general_announcement.allowed_user_ids)
13 changes: 13 additions & 0 deletions announcement/views/announcement_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
options="{'color_field': 'color'}"
placeholder="Tags..."
/>
<field name="excluded_users_ids" widget="many2many_tags" />
<field name="excluded_groups_ids" widget="many2many_tags" />
</group>
</group>
<group>
Expand All @@ -107,6 +109,17 @@
/>
</group>
</page>
<page name="users_scope" string="Users Scope">
<field
name="allowed_user_ids"
options="{'no_create': True}"
nolabel="1"
>
<tree>
<field name="name" />
</tree>
</field>
</page>
</notebook>
</sheet>
</form>
Expand Down