-
-
Notifications
You must be signed in to change notification settings - Fork 672
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] hr_employee_document: Remove record rules from hr.employee to a…
…void side effects. The purpose of this module is to allow a basic user (without hr permissions) to view the attachments related to his employee (hr.employee). By default a basic user cannot access to hr.employee model and therefore cannot see the attachments (ir.attachment) linked to it. This change overrides some things to allow the user's employee attachments to be displayed. TT44536
- Loading branch information
1 parent
f0b15a6
commit bc586f9
Showing
7 changed files
with
92 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
|
||
from . import hr_employee | ||
from . import hr_employee_public | ||
from . import ir_rule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright 2023 Tecnativa - Víctor Martínez | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
|
||
from odoo import api, models, tools | ||
from odoo.osv import expression | ||
from odoo.tools import config | ||
|
||
|
||
class IrRule(models.Model): | ||
_inherit = "ir.rule" | ||
|
||
def _get_hr_employee_document_group(self): | ||
return "hr.group_hr_user" | ||
|
||
@api.model | ||
@tools.conditional( | ||
"xml" not in config["dev_mode"], | ||
tools.ormcache( | ||
"self.env.uid", | ||
"self.env.su", | ||
"model_name", | ||
"mode", | ||
"tuple(self._compute_domain_context_values())", | ||
), | ||
) | ||
def _compute_domain(self, model_name, mode="read"): | ||
"""We need to add for security purposes an extra domain in the hr.employee | ||
model to restrict only the user's employees when search employee attachments.""" | ||
res = super()._compute_domain(model_name, mode=mode) | ||
user = self.env.user | ||
if ( | ||
model_name == "hr.employee" | ||
and not self.env.su | ||
and not user.has_group(self._get_hr_employee_document_group()) | ||
and self.env.context.get("search_attachments_from_hr_employee") | ||
): | ||
extra_domain = [[("id", "in", user.employee_ids.ids)]] | ||
res = expression.AND(extra_domain + [res]) | ||
return res |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters