Skip to content

[FIX] mail_log_only_internal: refactor search#369

Closed
augusto-weiss wants to merge 1 commit intoingadhoc:19.0from
adhoc-dev:19.0-h-110396-awe
Closed

[FIX] mail_log_only_internal: refactor search#369
augusto-weiss wants to merge 1 commit intoingadhoc:19.0from
adhoc-dev:19.0-h-110396-awe

Conversation

@augusto-weiss
Copy link
Contributor

No description provided.

Copilot AI review requested due to automatic review settings February 11, 2026 19:13
@roboadhoc
Copy link
Contributor

Pull request status dashboard

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 17 to 20
# 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"
# )
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
# 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"
# )

Copilot uses AI. Check for mistakes.
Comment on lines 41 to 45
# @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)
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
# @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)

Copilot uses AI. Check for mistakes.
Comment on lines 66 to 72
# @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
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_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.

Suggested change
# @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

Copilot uses AI. Check for mistakes.
Comment on lines 47 to 64
# @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
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
# @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

Copilot uses AI. Check for mistakes.
"partner_id.id"
)
internal_group = self.env.ref("base.group_user")
internal_users = internal_group.all_user_ids.mapped("partner_id.id")
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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
)

Copilot uses AI. Check for mistakes.
@matiasperalta1
Copy link
Contributor

@roboadhoc nobump r+

@roboadhoc roboadhoc closed this in 2065adf Feb 12, 2026
@roboadhoc roboadhoc added the 18.1 label Feb 12, 2026
@roboadhoc roboadhoc deleted the 19.0-h-110396-awe branch February 12, 2026 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments