Skip to content

[FIX] helpdesk_mgmt: do not auto-assign tickets to portal users - #1086

Open
nericervin wants to merge 1 commit into
OCA:18.0from
nericervin:18.0-fix-helpdesk_mgmt-portal-auto-assign
Open

[FIX] helpdesk_mgmt: do not auto-assign tickets to portal users#1086
nericervin wants to merge 1 commit into
OCA:18.0from
nericervin:18.0-fix-helpdesk_mgmt-portal-auto-assign

Conversation

@nericervin

Copy link
Copy Markdown

Problem

When Auto assign User is enabled on the company, a ticket submitted by a
portal user ends up assigned to that portal user. The customer who filed the
ticket becomes its assignee, which also means the ticket counts as assigned
and never shows up as unassigned, so nobody picks it up.

How to reproduce

  1. Enable Auto assign User on the company.
  2. Reproduce what a portal controller does:
env["helpdesk.ticket"].with_user(portal_user).sudo().create({
    "name": "Portal ticket",
    "description": "<p>...</p>",
    "team_id": team.id,
})

The ticket is created with user_id set to the portal user.

Note that sudo() does not change env.uid, it only elevates privileges, so
self.env.user inside default_get() is still the portal user.

Cause

helpdesk_mgmt/models/helpdesk_ticket.py, default_get():

if "user_id" in fields and not defaults.get("user_id"):
    company = self.env["res.company"].browse(company_id)
    if company.helpdesk_mgmt_ticket_auto_assign:
        if defaults.get("team_id"):
            team = ...
            if self.env.user in team.user_ids:
                defaults["user_id"] = self.env.user.id
        else:
            defaults["user_id"] = self.env.user.id

The branch with a team is safe by accident: a portal user is not a member of
the team, so the membership check rejects it. The branch without a team
assigns unconditionally.

Portal controllers hit that second branch, because they pass the team in the
values of create() and not in the defaults: team_id is therefore not a
missing field, default_get() is not called for it, and
defaults.get("team_id") is falsy.

helpdesk_mgmt's own portal controller happens to escape the issue, because
_prepare_submit_ticket_vals() sets "user_id": False explicitly. Any other
controller that does not set it — a custom website form, an API import — hits
the bug. A website form with auth="public" runs as base.public_user, so
in that case tickets end up assigned to the public user, which is even less
useful than being assigned to the customer.

Fix

Skip the auto-assignment when the current user is a shared user
(share == True, i.e. portal or public). This is consistent with the domain
of user_id itself, which already excludes shared users:

domain="team_id and [('share', '=', False),('id', 'in', user_ids)] or [('share', '=', False)]"

Internal users are unaffected: the existing behaviour (creator becomes the
assignee) is preserved, and a regression test covers it.

Tests

Four tests added to helpdesk_mgmt/tests/test_helpdesk_portal.py, reusing the
existing TestHelpdeskPortalBase fixtures: portal user with and without a
team, base.public_user, and an internal user to make sure the current
behaviour does not change.

Other branches

The same code is present in 17.0. 16.0 is not affected: the
helpdesk_mgmt_ticket_auto_assign field does not exist there. Happy to
backport to 17.0 if you want it in the same PR or in a separate one.

@pedrobaeza pedrobaeza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please don't include slop tests generated by AI. You just need to check the new case, not all the variants.

"summary": """
Helpdesk""",
"version": "18.0.1.17.1",
"version": "18.0.1.17.2",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't modify module version. It will be done by the bot.

When "Auto assign User" is enabled on the company, a ticket submitted by a
portal user ends up assigned to that portal user: the customer who filed the
ticket becomes its assignee, so it never shows up as unassigned and nobody
picks it up.

sudo() does not change env.uid, it only elevates privileges, so self.env.user
inside default_get() is still the portal user. The branch with a team is safe
by accident (a portal user is not a member of the team), but the branch
without a team assigns unconditionally. Portal controllers hit that second
branch, because they pass the team in the values of create() and not in the
defaults.

Skip the auto-assignment when the current user is a shared user. This is
consistent with the domain of user_id itself, which already excludes them.
@nericervin
nericervin force-pushed the 18.0-fix-helpdesk_mgmt-portal-auto-assign branch from 23160f5 to bd5ef25 Compare August 15, 2026 22:26
@nericervin

Copy link
Copy Markdown
Author

Fair point. Reduced to a single test for the new case.

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.

4 participants