Skip to content

T3574 unverified sponsorship isolation - #433

Open
danpa32 wants to merge 7 commits into
18.0from
T3574-unverified-sponsorship-isolation
Open

danpa32 wants to merge 7 commits into
18.0from
T3574-unverified-sponsorship-isolation

Conversation

@danpa32

@danpa32 danpa32 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

[T3574] my_compassion: separate unverified sponsorships from existing donors and billing

Related PR

CompassionCH/compassion-switzerland#1867

Problem

A public sponsorship (visitor not logged in) went through res.partner.match whenever a name was posted: name + email, or name + postcode. The fast checkout normally asks for no name before payment, but adding firstname/lastname to the posted form was enough. The matched donor was then used as the sponsor:

Fix

  • finish_sponsorship(): a public visitor always gets a new partner with an unverified email (my2_email_unverified), with whatever they typed. This is the same rule as the public fund donation ([IMP] my_compassion: give to a fund without an account #420). Its collection group is therefore new too, with no saved card. A saved card can only belong to the group's own partner (existing constraint _check_payment_token).
  • Logged-in sponsors are unchanged: they keep their own partner and their existing group.
  • The ownership checks of the signup pages (session, details token, Swiss opt-in) now only ever reach that new partner, so no controller change was needed.
  • Possible duplicates: when the email is the one of a known (verified) partner, the new partner gets an internal note linking to that partner. The visitor is told nothing and nothing is merged. If the new website setting "Possible Duplicates Reviewer" (Website form, "MyCompassion" tab) is set, that person also gets a to-do "Possible duplicate contact", so staff check and merge the contacts.

Consequence

A returning donor who sponsors without logging in becomes a second contact with their own collection group, to be merged by staff. This is what the ticket asks for: reuse only with authenticated ownership. An automatic merge after the donor confirms through their own mailbox (a link sent to the known email) could be a follow-up.

Deploy

-u my_compassion (new field on website). Then set "Possible Duplicates Reviewer" on each MyCompassion website: any internal user can be chosen per website. The to-dos are handled by the SDS team.

A public sponsorship matched an existing partner on the name and email or
postcode the visitor typed (also in the fast checkout, by adding the name
to the posted form). The contract then joined that donor's collection
group, so the charge cron took its invoices on the donor's saved card, and
the browser owning the new signup saw the donor's name and could write
their preferences.

A visitor now always gets a new partner with an unverified email, as the
public fund donation already does. A known donor is only reused when they
are logged in.

When the email is the one of a known partner, a note on the new partner
links to them and the reviewer set on the website gets a to-do, so staff
check and merge the contacts. The visitor is told nothing.
@greptile-apps

greptile-apps Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[High impact] The changes affect public sponsorship identity and billing across MyCompassion sites.

Update the Swiss opt-in test fixtures before merging this session-format change.

Findings

  1. P1 Swiss opt-in tests fail ▶

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Start sponsorship] --> B{Logged in?}
  B -->|No| C[Create separate unverified contact]
  B -->|Yes| D[Use signed-in contact]
  C --> E[Find or create that contact's collection group]
  D --> E
  E --> F[Create sponsorship]
  F --> G[Store contract and partner IDs in session]
  F --> H[Signup confirmed and real name known]
  H --> I[Send portal invitation]
  H --> J{Known contact uses this email?}
  J -->|Yes| K[Leave internal note and optional reviewer task]
Loading

Reviews (2) · Last reviewed commit: "Merge remote-tracking branch 'origin/18...." · Reviewed by Greptile

@NoeBerdoz NoeBerdoz left a comment

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.

Levels: Must fix (money or security) · Before go-live (before real donors use it) · Should fix · Suggestion

Pair review (Claude and Codex), then tested locally:

  • the new tests and the related suites, on 18.0 and then on this branch;
  • the upgrade (-u my_compassion,my_compassion_switzerland): clean, no errors;
  • an end-to-end run in a browser, on a copy of the migrated database, with Odoo's demo payment provider and test contacts only.

What works, and was checked. A visitor who is not logged in always gets a new contact and a new collection group. That holds when the visitor types only the donor's email, and also when they add the donor's name and postcode to the posted form. With the demo provider, the charge cron created four transactions. Each invoice was paid with the card of its own group, and no visitor invoice was charged to the donor's card. A logged-in donor still lands in their own group and is offered their saved card. Five tests fail on 18.0 and pass here, and no test that passes on 18.0 fails here. The fix is small and it sits in the right place. Thank you.

What is left is mostly about what happens after the to-do: the merge, and when the to-do is created. Inline comments below. Three more points concern lines outside the diff:

  1. Should fix: two comments now give a reason that is no longer true. controllers/my2_sponsorships.py:873 and :946 justify the saved-card guard with "the public wizard matches partners by email". The guard is still right, but for another reason now: a visitor's contact is always new, and the guard keeps stored cards behind a login even if that ever changes. The docstring of test_transaction_route_refuses_a_saved_card_to_the_public (tests/test_fast_checkout_routes.py:326) says the same thing. A comment with an old reason invites the next person to delete the guard, "since we don't match any more".

  2. Should fix: translations. The PR adds four strings (the field label and its help, the note, the to-do summary) without .po entries. In the test, a reviewer whose language is fr_CH got the note in English. The recent PRs on this module ship fr_CH, de_DE and it_IT entries with the code.

  3. Suggestion: the new setting is only explained in the PR description. readme/CONFIGURE.md is where the next person will look for "who gets these to-dos?".

Assisted-by: claude-opus-5-5, xhigh, claude-code
Assisted-by: gpt-6.1-sol, high, codex

Comment thread my_compassion/models/res_partner.py Resolved
Comment thread my_compassion/models/res_partner.py Resolved
…p to the donor

A merge keeps the kept partner's own unverified-email, placeholder-name and duplicate flags. The session keeps the contract and its partner for each signup it owns, so moving a visitor's contract onto a donor ends this browser's access to it. The saved-card guard comments give the current reason.
…onfirmed

The note and to-do wait for the signup to be confirmed with a real name, like the portal invitation, and are posted once per partner, as the superuser, inside a savepoint so a failure never breaks the payment or the validation. The reviewer comes from the company's websites. The note tells staff to move the sponsorship onto the donor instead of merging.
Comment on lines +729 to 730
owns_signup = own_signup_session_entry(sponsorship) in (
request.session.get(OWN_SIGNUPS_SESSION_KEY) or []

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.

P1 Swiss opt-in tests fail

The Swiss _own_signup_session() helper still stores [self.signup.id]. This check now expects [[signup_id, partner_id]], so that helper no longer grants ownership. The thank-you test receives 404, and the opt-in tests receive {"success": False} instead of saving the choice.

Update the companion tests to use own_signup_session_entry() before merging. Accepting bare contract IDs again would weaken the new ownership check.

@danpa32

danpa32 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review. All points are addressed in e63d453, 9d27e72, 065e611 and 174ba5f, and the latest 18.0 is merged in. Replies are under each inline comment. The three points outside the diff:

  1. The comments of the saved-card guard (_get_sponsorship_payment_values and the transaction route) and the docstring of test_transaction_route_refuses_a_saved_card_to_the_public now give the current reason: a visitor's partner is always new, and stored cards stay behind a login whatever the checkout does.
  2. fr_CH, de_DE and it_IT entries were added for the new strings (field labels and helps, the note, the to-do summary, the "MyCompassion" tab).
  3. The setting is explained in readme/CONFIGURE.md (and the generated README).

@danpa32
danpa32 requested a review from NoeBerdoz November 3, 2026 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants