Skip to content

Commit 2db4e6d

Browse files
committed
[ADD] mail_activity_team_restrict: Implement team-based access for restricted activities
1 parent 8d3d69a commit 2db4e6d

13 files changed

Lines changed: 800 additions & 4 deletions

File tree

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ jobs:
3636
matrix:
3737
include:
3838
- container: ghcr.io/oca/oca-ci/py3.10-odoo18.0:latest
39-
include: "mail_post_defer"
39+
include: "mail_post_defer,mail_activity_done"
4040
name: test with Odoo
4141
- container: ghcr.io/oca/oca-ci/py3.10-ocb18.0:latest
42-
include: "mail_post_defer"
42+
include: "mail_post_defer,mail_activity_done"
4343
name: test with OCB
4444
makepot: "true"
4545
- container: ghcr.io/oca/oca-ci/py3.10-odoo18.0:latest
46-
exclude: "mail_post_defer"
46+
exclude: "mail_post_defer,mail_activity_done"
4747
name: test with Odoo
4848
- container: ghcr.io/oca/oca-ci/py3.10-ocb18.0:latest
49-
exclude: "mail_post_defer"
49+
exclude: "mail_post_defer,mail_activity_done"
5050
name: test with OCB
5151
makepot: "true"
5252
services:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Mail Activity Team Restrict
2+
3+
This module extends `mail_activity_restrict` together with `mail_activity_team`.
4+
5+
When `can_write_restrict` is enabled on an activity type, the base module limits edits
6+
to the assigned user. This addon extends that rule so members of the activity `team_id`
7+
may also edit the activity and mark it as done.
8+
9+
No additional configuration is introduced. The module reuses:
10+
11+
- `mail.activity.type.can_write_restrict` from `mail_activity_restrict`
12+
- `mail.activity.team_id` and `mail.activity.team.member_ids` from `mail_activity_team`
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
===========================
2+
Mail Activity Team Restrict
3+
===========================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:27bbf7124e8cdebe4a13cf7235c541c23fb2d244c3f4b192e3c849cf15b871f8
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmail-lightgray.png?logo=github
20+
:target: https://github.com/OCA/mail/tree/18.0/mail_activity_team_restrict
21+
:alt: OCA/mail
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/mail-18-0/mail-18-0-mail_activity_team_restrict
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/mail&target_branch=18.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module extends mail_activity_restrict with team support.
32+
33+
For activity types with "Restrict Write to Assigned User" enabled,
34+
activity team members are also allowed to edit and complete the
35+
activity.
36+
37+
No extra configuration field is added on the activity type. It reuses
38+
the same restriction option from mail_activity_restrict and the team
39+
membership from mail_activity_team.
40+
41+
**Table of contents**
42+
43+
.. contents::
44+
:local:
45+
46+
Usage
47+
=====
48+
49+
To use this module:
50+
51+
1. Enable "Restrict Write to Assigned User" on the activity type.
52+
2. Assign a team on the activity.
53+
3. Make sure users are members of that team.
54+
55+
Allowed users for restricted activities are:
56+
57+
- The assigned user.
58+
- Members of the assigned team.
59+
60+
Users outside that scope cannot edit or complete the activity.
61+
62+
Bug Tracker
63+
===========
64+
65+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/mail/issues>`_.
66+
In case of trouble, please check there if your issue has already been reported.
67+
If you spotted it first, help us to smash it by providing a detailed and welcomed
68+
`feedback <https://github.com/OCA/mail/issues/new?body=module:%20mail_activity_team_restrict%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
69+
70+
Do not contact contributors directly about support or help with technical issues.
71+
72+
Credits
73+
=======
74+
75+
Maintainers
76+
-----------
77+
78+
This module is maintained by the OCA.
79+
80+
.. image:: https://odoo-community.org/logo.png
81+
:alt: Odoo Community Association
82+
:target: https://odoo-community.org
83+
84+
OCA, or the Odoo Community Association, is a nonprofit organization whose
85+
mission is to support the collaborative development of Odoo features and
86+
promote its widespread use.
87+
88+
This module is part of the `OCA/mail <https://github.com/OCA/mail/tree/18.0/mail_activity_team_restrict>`_ project on GitHub.
89+
90+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "Mail Activity Team Restrict",
3+
"version": "18.0.1.0.0",
4+
"category": "Productivity/Mail",
5+
"license": "AGPL-3",
6+
"author": "Odoo Community Association (OCA)",
7+
"website": "https://github.com/OCA/mail",
8+
"depends": [
9+
"mail_activity_restrict",
10+
"mail_activity_team",
11+
],
12+
"installable": True,
13+
"application": False,
14+
"auto_install": True,
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import mail_activity
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""Extend restricted activities to members of the assigned team."""
2+
3+
from odoo import models
4+
from odoo.exceptions import AccessError
5+
6+
7+
class MailActivity(models.Model):
8+
"""Allow team members to modify restricted activities."""
9+
10+
_inherit = "mail.activity"
11+
12+
def _get_can_write_restrict_allowed_activities(self):
13+
"""Allow the assignee and members of the assigned team."""
14+
return (
15+
super()._get_can_write_restrict_allowed_activities()
16+
| self.sudo().filtered_domain([("team_id.member_ids", "in", self.env.uid)])
17+
)
18+
19+
def _make_can_write_restrict_error(self, operation: str) -> AccessError:
20+
"""Build the access error raised for restricted team activities."""
21+
if len(self) == 1:
22+
return AccessError(
23+
self.env._(
24+
"You cannot %(operation)s this activity because only the assigned "
25+
"user or members of the assigned team can modify activities of this"
26+
" type.",
27+
operation=operation,
28+
)
29+
)
30+
return AccessError(
31+
self.env._(
32+
"You cannot %(operation)s some activities because only their assigned "
33+
"user or members of the assigned team can modify activities of this "
34+
"type.",
35+
operation=operation,
36+
)
37+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
This module extends mail_activity_restrict with team support.
2+
3+
For activity types with "Restrict Write to Assigned User" enabled, activity
4+
team members are also allowed to edit and complete the activity.
5+
6+
No extra configuration field is added on the activity type. It reuses the
7+
same restriction option from mail_activity_restrict and the team membership
8+
from mail_activity_team.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
To use this module:
2+
3+
1. Enable "Restrict Write to Assigned User" on the activity type.
4+
2. Assign a team on the activity.
5+
3. Make sure users are members of that team.
6+
7+
Allowed users for restricted activities are:
8+
- The assigned user.
9+
- Members of the assigned team.
10+
11+
Users outside that scope cannot edit or complete the activity.

0 commit comments

Comments
 (0)