Skip to content

[19.0][IMP] partner_email_check: clearer duplicate-email message + multi-company scope option#2374

Open
cliffkujala wants to merge 1 commit into
OCA:19.0from
purekarting:19.0-partner_email_check-access-aware-error
Open

[19.0][IMP] partner_email_check: clearer duplicate-email message + multi-company scope option#2374
cliffkujala wants to merge 1 commit into
OCA:19.0from
purekarting:19.0-partner_email_check-access-aware-error

Conversation

@cliffkujala
Copy link
Copy Markdown

Summary

This improves the duplicate-email handling of partner_email_check in two ways: a clearer, access-aware error message, and a new option to scope uniqueness per company instead of globally.

Clearer, access-aware duplicate message

The duplicate check is an @api.constrains, which always runs as superuser, so uniqueness was (and still is) enforced across all records regardless of the acting user's record rules. Previously a collision raised a generic Email 'x@y.com' is already in use., which is confusing when the user cannot see the conflicting partner (record rules / multi-company): they are blocked from using an address that appears nowhere they can look.

After detecting a conflict, the constraint now re-checks whether the acting user can actually read the conflicting record (self.sudo(False)) and tailors the message:

  • Readable → identifies the record so the user can reuse it:
    Email address x@y.com is already in use by <name> (ID: 123). Please input another email address or use the existing record.
  • Not readable → explains the block without disclosing the record:
    Email address x@y.com is already in use by a record you do not have access to. Please input a different email address, or contact your system administrator to request access.

Multi-company duplicate scope option

New company setting partner_email_check_duplicate_scope (exposed in Settings, shown only when duplicate filtering is enabled):

  • Across all companies (global, default) — unchanged behavior: an address may be used only once in the whole database.
  • Within the same company (company) — the same address may be reused by a partner of another company, but must stay unique inside each company (company_id = False is treated as its own bucket).

Compatibility notes

  • The new setting defaults to global, preserving the previous behavior.
  • The success-path message is now more verbose and, for readable records, discloses the conflicting partner's name and ID (previously a generic string). This is intentional and is the point of the change.

Tests

Adds coverage for: per-company scope allowing the same address in another company, per-company scope still blocking within one company, global scope blocking across companies, and the access-restricted message path (duplicate hidden by a record rule is still blocked, without leaking the record).

@OCA-git-bot OCA-git-bot added series:19.0 mod:partner_email_check Module partner_email_check labels May 31, 2026
@cliffkujala cliffkujala force-pushed the 19.0-partner_email_check-access-aware-error branch 2 times, most recently from c3458f3 to 254455e Compare May 31, 2026 22:02
Copy link
Copy Markdown
Contributor

@BhaveshHeliconia BhaveshHeliconia left a comment

Choose a reason for hiding this comment

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

Code and functional review LGTM!

{
"name": "Restricted",
"login": "restricted_user",
"group_ids": [(6, 0, groups.ids)],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
"group_ids": [(6, 0, groups.ids)],
"group_ids": [Commad.set(groups.ids)],

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the review! Good call on Command.set — much cleaner than the (6, 0, ...) tuple. Small heads-up: the suggestion as written has a typo (Commad.set), so I applied a corrected version manually: added from odoo import Command, switched this line to Command.set(groups.ids), and also converted the ir.rule groups line below to Command.set([]) for consistency. Pushed in the latest commit.

@cliffkujala cliffkujala force-pushed the 19.0-partner_email_check-access-aware-error branch from 254455e to debe00e Compare June 1, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:partner_email_check Module partner_email_check series:19.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants