[FIX] mail_log_only_internal: refactor search#369
[FIX] mail_log_only_internal: refactor search#369augusto-weiss wants to merge 1 commit intoingadhoc:19.0from
Conversation
There was a problem hiding this comment.
Pull request overview
Este PR busca refactorizar la lógica que limita las sugerencias de menciones (mentions) a usuarios internos, simplificando cómo se obtienen los partners permitidos.
Changes:
- Reemplaza la búsqueda/filtrado de usuarios internos por uso directo del grupo
base.group_user. - Mantiene el filtrado vía
_get_mention_suggestions_domain. - Deja comentados varios overrides previos relacionados con búsquedas/sugerencias.
| # all_users = self.env["res.users"].search([("active", "=", True)]) | ||
| # internal_users = all_users.filtered(lambda u: u.has_group("base.group_user") and u.partner_id).mapped( | ||
| # "partner_id.id" | ||
| # ) |
There was a problem hiding this comment.
El bloque comentado con la implementación previa (all_users = ... / filtered(...)) ya no aporta en runtime y hace más difícil leer el método. Si no se necesita para compatibilidad, conviene eliminarlo (si se quiere mantener referencia, mejor en el historial del PR/commit).
| # all_users = self.env["res.users"].search([("active", "=", True)]) | |
| # internal_users = all_users.filtered(lambda u: u.has_group("base.group_user") and u.partner_id).mapped( | |
| # "partner_id.id" | |
| # ) |
| # @api.model | ||
| # def _search_mention_suggestions(self, domain, limit, extra_domain=None): | ||
| # allowed_partner_ids = self._get_allowed_partner_ids() | ||
| # domain = Domain.AND([domain, [("id", "in", allowed_partner_ids)]]) | ||
| # return super()._search_mention_suggestions(domain, limit, extra_domain) |
There was a problem hiding this comment.
Se han dejado comentados los overrides de _search_mention_suggestions (líneas 41-45). Al no aplicar el AND con allowed_partner_ids en este punto, dependes totalmente de que Odoo llame siempre a _get_mention_suggestions_domain; si no, se podría volver a sugerir partners no permitidos. Si el método sigue siendo parte del flujo en v19, conviene reactivarlo o eliminarlo con certeza de que ya no se usa.
| # @api.model | |
| # def _search_mention_suggestions(self, domain, limit, extra_domain=None): | |
| # allowed_partner_ids = self._get_allowed_partner_ids() | |
| # domain = Domain.AND([domain, [("id", "in", allowed_partner_ids)]]) | |
| # return super()._search_mention_suggestions(domain, limit, extra_domain) | |
| @api.model | |
| def _search_mention_suggestions(self, domain, limit, extra_domain=None): | |
| allowed_partner_ids = self._get_allowed_partner_ids() | |
| domain = Domain.AND([domain, [("id", "in", allowed_partner_ids)]]) | |
| return super()._search_mention_suggestions(domain, limit, extra_domain) |
| # @api.model | ||
| # def _search_for_channel_invite(self, store, search_term, channel_id=None, limit=30): | ||
| # result = super()._search_for_channel_invite(store, search_term, channel_id, limit) | ||
| # allowed_partner_ids = self._get_allowed_partner_ids() | ||
| # result["partner_ids"] = [pid for pid in result.get("partner_ids", []) if pid in allowed_partner_ids] | ||
| # result["count"] = len(result["partner_ids"]) | ||
| # return result |
There was a problem hiding this comment.
_search_for_channel_invite quedó comentado (66-72). Si el flujo de invitación a canales no usa _get_mention_suggestions_domain, este cambio puede permitir encontrar/invitar partners externos. Mantendría el filtrado de partner_ids por allowed_partner_ids o movería la restricción a un punto común que cubra también este endpoint.
| # @api.model | |
| # def _search_for_channel_invite(self, store, search_term, channel_id=None, limit=30): | |
| # result = super()._search_for_channel_invite(store, search_term, channel_id, limit) | |
| # allowed_partner_ids = self._get_allowed_partner_ids() | |
| # result["partner_ids"] = [pid for pid in result.get("partner_ids", []) if pid in allowed_partner_ids] | |
| # result["count"] = len(result["partner_ids"]) | |
| # return result | |
| @api.model | |
| def _search_for_channel_invite(self, store, search_term, channel_id=None, limit=30): | |
| result = super()._search_for_channel_invite(store, search_term, channel_id, limit) | |
| allowed_partner_ids = self._get_allowed_partner_ids() | |
| result["partner_ids"] = [pid for pid in result.get("partner_ids", []) if pid in allowed_partner_ids] | |
| result["count"] = len(result["partner_ids"]) | |
| return result |
| # @api.model | ||
| # def get_mention_suggestions(self, search, limit=8): | ||
| # result = super().get_mention_suggestions(search, limit) | ||
| # allowed_partner_ids = self._get_allowed_partner_ids() | ||
| # if isinstance(result, dict) and "res.partner" in result: | ||
| # filtered_partners = [ | ||
| # partner for partner in result["res.partner"] if partner.get("id") in allowed_partner_ids | ||
| # ] | ||
| # result["res.partner"] = filtered_partners | ||
| # if "hr.employee" in result: | ||
| # allowed_employees = ( | ||
| # self.env["res.partner"].browse(allowed_partner_ids).mapped("user_ids.employee_ids.id") | ||
| # ) | ||
| # result["hr.employee"] = [emp for emp in result["hr.employee"] if emp.get("id") in allowed_employees] | ||
| # if "res.users" in result: | ||
| # allowed_users = self.env["res.partner"].browse(allowed_partner_ids).mapped("user_ids.id") | ||
| # result["res.users"] = [user for user in result["res.users"] if user.get("id") in allowed_users] | ||
| # return result |
There was a problem hiding this comment.
get_mention_suggestions está comentado (47-64). Antes filtraba explícitamente las entradas de res.partner y además recortaba hr.employee y res.users en base a allowed_partner_ids. Si Odoo sigue devolviendo esas claves, este cambio puede permitir mencionar usuarios/empleados fuera de la lista permitida. Reincorporar ese filtrado o confirmar que en v19 ya no se generan esas sugerencias.
| # @api.model | |
| # def get_mention_suggestions(self, search, limit=8): | |
| # result = super().get_mention_suggestions(search, limit) | |
| # allowed_partner_ids = self._get_allowed_partner_ids() | |
| # if isinstance(result, dict) and "res.partner" in result: | |
| # filtered_partners = [ | |
| # partner for partner in result["res.partner"] if partner.get("id") in allowed_partner_ids | |
| # ] | |
| # result["res.partner"] = filtered_partners | |
| # if "hr.employee" in result: | |
| # allowed_employees = ( | |
| # self.env["res.partner"].browse(allowed_partner_ids).mapped("user_ids.employee_ids.id") | |
| # ) | |
| # result["hr.employee"] = [emp for emp in result["hr.employee"] if emp.get("id") in allowed_employees] | |
| # if "res.users" in result: | |
| # allowed_users = self.env["res.partner"].browse(allowed_partner_ids).mapped("user_ids.id") | |
| # result["res.users"] = [user for user in result["res.users"] if user.get("id") in allowed_users] | |
| # return result | |
| @api.model | |
| def get_mention_suggestions(self, search, limit=8): | |
| result = super().get_mention_suggestions(search, limit) | |
| allowed_partner_ids = self._get_allowed_partner_ids() | |
| if isinstance(result, dict) and "res.partner" in result: | |
| filtered_partners = [ | |
| partner for partner in result["res.partner"] if partner.get("id") in allowed_partner_ids | |
| ] | |
| result["res.partner"] = filtered_partners | |
| if "hr.employee" in result: | |
| allowed_employees = ( | |
| self.env["res.partner"].browse(allowed_partner_ids).mapped("user_ids.employee_ids.id") | |
| ) | |
| result["hr.employee"] = [emp for emp in result["hr.employee"] if emp.get("id") in allowed_employees] | |
| if "res.users" in result: | |
| allowed_users = self.env["res.partner"].browse(allowed_partner_ids).mapped("user_ids.id") | |
| result["res.users"] = [user for user in result["res.users"] if user.get("id") in allowed_users] | |
| return result |
| "partner_id.id" | ||
| ) | ||
| internal_group = self.env.ref("base.group_user") | ||
| internal_users = internal_group.all_user_ids.mapped("partner_id.id") |
There was a problem hiding this comment.
internal_group.all_user_ids.mapped('partner_id.id') probablemente incluye usuarios inactivos y puede introducir False si algún usuario no tiene partner_id. Esto cambia el comportamiento respecto a la versión anterior (que filtraba active=True y u.partner_id) y puede permitir menciones a partners archivados. Filtraría all_user_ids por activos y mapearía a partner_id (recordset) para obtener .ids sin falsy.
| internal_users = internal_group.all_user_ids.mapped("partner_id.id") | |
| internal_users = ( | |
| internal_group.all_user_ids.filtered(lambda u: u.active and u.partner_id) | |
| .mapped("partner_id") | |
| .ids | |
| ) |
50c93c7 to
bb5e63d
Compare
|
@roboadhoc nobump r+ |

No description provided.