Skip to content

Commit c97ea27

Browse files
[MIG] attachment_delete_restrict: Migration to 19.0
- Remove the self.env.su condition in unlink, since it is always called with sudo() in Odoo 19. https://github.com/odoo/odoo/blob/98bae80f57733162c67593539ef47dfd0c6d8797/addons/mail/controllers/attachment.py#L98
1 parent b8482c9 commit c97ea27

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

attachment_delete_restrict/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33
{
44
"name": "Restrict Deletion of Attachments",
5-
"version": "18.0.1.0.0",
5+
"version": "19.0.1.0.0",
66
"depends": [
77
"base",
88
"base_setup",

attachment_delete_restrict/models/ir_attachment.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Copyright 2021 Quartile (https://www.quartile.co)
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33

4-
5-
from odoo import _, models
4+
from odoo import SUPERUSER_ID, models
65
from odoo.exceptions import ValidationError
76

87

@@ -29,7 +28,7 @@ def _check_delete_attachment(self, model=None):
2928

3029
def _raise_delete_attachment_error(self, allowed_users):
3130
raise ValidationError(
32-
_(
31+
self.env._(
3332
"You are not allowed to delete this attachment.\n\nUsers with "
3433
"the delete permission:\n%s"
3534
)
@@ -42,7 +41,7 @@ def _check_owner_delete_attachment(self):
4241
or self.env.user.has_group("base.group_system")
4342
):
4443
return self._raise_delete_attachment_error(
45-
self.create_uid | self.env.ref("base.group_system").users
44+
self.create_uid | self.env.ref("base.group_system").user_ids
4645
)
4746

4847
def _check_custom_delete_attachment(self, model=None, allow_owner_and_admin=False):
@@ -59,12 +58,12 @@ def _check_custom_delete_attachment(self, model=None, allow_owner_and_admin=Fals
5958
if allow_owner_and_admin:
6059
users += self.create_uid
6160
groups += self.env.ref("base.group_system")
62-
allowed_users = groups.users | users
61+
allowed_users = groups.user_ids | users
6362
if self.env.user not in allowed_users:
6463
return self._raise_delete_attachment_error(allowed_users)
6564

6665
def unlink(self):
67-
if self.env.su:
66+
if self.env.uid == SUPERUSER_ID:
6867
return super().unlink()
6968
res_models = list(set(self.filtered("res_model").mapped("res_model")))
7069
if res_models:

attachment_delete_restrict/models/ir_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2021 Quartile (https://www.quartile.co)
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33

4-
from odoo import fields, models
4+
from odoo import api, fields, models
55

66
RESTRICT_DELETE_ATTACH = [
77
("default", "Use global configuration"),
@@ -43,6 +43,7 @@ class IrModel(models.Model):
4343
"model.",
4444
)
4545

46+
@api.onchange("restrict_delete_attachment")
4647
def _onchange_restrict_delete_attachment(self):
4748
if self.restrict_delete_attachment not in ["custom", "owner_custom"]:
4849
self.delete_attachment_group_ids = False

attachment_delete_restrict/tests/test_attachment_delete_restrict.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def setUpClass(cls):
8585
{
8686
"name": "test owner user",
8787
"login": "[email protected]",
88-
"groups_id": [
88+
"group_ids": [
8989
Command.set(
9090
[
9191
cls.env.ref("base.group_user").id,
@@ -99,7 +99,7 @@ def setUpClass(cls):
9999
{
100100
"name": "test user",
101101
"login": "[email protected]",
102-
"groups_id": [
102+
"group_ids": [
103103
Command.set(
104104
[
105105
cls.env.ref("base.group_user").id,
@@ -113,7 +113,7 @@ def setUpClass(cls):
113113
{
114114
"name": "User admin",
115115
"login": "[email protected]",
116-
"groups_id": [
116+
"group_ids": [
117117
Command.set(
118118
[
119119
cls.env.ref("base.group_system").id,

0 commit comments

Comments
 (0)