Skip to content

Add single receipt platform tip setting - #11792

Open
znarf wants to merge 4 commits into
mainfrom
single-receipt-platform-tip
Open

Add single receipt platform tip setting#11792
znarf wants to merge 4 commits into
mainfrom
single-receipt-platform-tip

Conversation

@znarf

@znarf znarf commented May 28, 2026

Copy link
Copy Markdown
Member

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @znarf, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@znarf, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 6 minutes and 18 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8487d452-b4b1-4830-91c7-3df81e26602e

📥 Commits

Reviewing files that changed from the base of the PR and between f483725 and d7994b0.

📒 Files selected for processing (1)
  • server/lib/pdf.ts
📝 Walkthrough

Walkthrough

This PR updates getConsolidatedInvoicesData to fetch transaction kind and TransactionGroup, build a contribution-by-group lookup, and when iterating transactions skip PLATFORM_TIP entries if the related contribution’s host has settings.singleReceiptPlatformTip enabled. It also refactors invoice slug generation to read host.slug via a cached host lookup. Tests were added to create a platform-tip transaction and assert the contributor can download its receipt while the host admin cannot.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Suggested reviewers

  • Betree
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@znarf
znarf force-pushed the single-receipt-platform-tip branch 2 times, most recently from d90f889 to 64db4fb Compare May 29, 2026 08:22
… of a feature

Replace the SINGLE_RECEIPT_PLATFORM_TIP feature (allowed-features +
CollectiveFeatures GraphQL type) with a plain host setting,
settings.singleReceiptPlatformTip.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@znarf znarf changed the title Add single receipt platform tip feature Add single receipt platform tip setting Jun 10, 2026
@znarf
znarf marked this pull request as ready for review June 10, 2026 13:00

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 15bc718b36

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread test/server/graphql/common/transactions.test.js Outdated
Comment thread server/lib/pdf.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
server/lib/pdf.ts (1)

67-85: ⚡ Quick win

Batch-load contribution hosts instead of querying them one-by-one in the invoice loop.

Each PLATFORM_TIP entry does its own Collective.findByPk and awaits it serially. For accounts with many historical tips, this turns consolidated receipt generation into a linear sequence of extra DB round-trips. Preloading the unique relatedContribution.HostCollectiveId values alongside contributionByGroup (or extending the existing host cache to include settings) keeps the loop in-memory.

♻️ One way to preload the host settings once
   const platformTipGroups = transactions
     .filter(t => t.kind === TransactionKind.PLATFORM_TIP)
     .map(t => t.TransactionGroup);

   let contributionByGroup = {};
+  let contributionHostsById = {};
   if (platformTipGroups.length) {
     const contributions = await models.Transaction.findAll({
       attributes: ['HostCollectiveId', 'TransactionGroup'],
       where: {
         TransactionGroup: platformTipGroups,
         kind: TransactionKind.CONTRIBUTION,
         type: 'CREDIT',
       },
     });

     contributionByGroup = contributions.reduce((result, contribution) => {
       result[contribution.TransactionGroup] = contribution;
       return result;
     }, {});
+
+    const contributionHostIds = [...new Set(contributions.map(c => c.HostCollectiveId).filter(Boolean))];
+    const contributionHosts = await models.Collective.findAll({
+      attributes: ['id', 'settings'],
+      where: { id: contributionHostIds },
+    });
+    contributionHostsById = contributionHosts.reduce((result, host) => {
+      result[host.id] = host;
+      return result;
+    }, {});
   }

   for (const transaction of transactions) {
     if (transaction.kind === TransactionKind.PLATFORM_TIP) {
       const relatedContribution = contributionByGroup[transaction.TransactionGroup];
       if (relatedContribution?.HostCollectiveId) {
-        const contributionHost = await models.Collective.findByPk(relatedContribution.HostCollectiveId);
+        const contributionHost = contributionHostsById[relatedContribution.HostCollectiveId];
         if (contributionHost && get(contributionHost, 'settings.singleReceiptPlatformTip') === true) {
           continue;
         }
       }
     }

Also applies to: 100-107

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server/lib/pdf.ts` around lines 67 - 85, The code currently collects
PLATFORM_TIP TransactionGroup values into platformTipGroups and builds
contributionByGroup via models.Transaction.findAll, but later still calls
Collective.findByPk inside the invoice loop for each
relatedContribution.HostCollectiveId; change this to batch-load all unique
HostCollectiveId values after building contributionByGroup: extract unique
HostCollectiveId from the contributions (contribution.HostCollectiveId), call
models.Collective.findAll({ where: { id: hostIds }, attributes:
['id','settings', ...] }) once, build a map keyed by id (hostById) and use that
map in place of Collective.findByPk inside the loop so the invoice loop uses the
in-memory host objects (and their settings) instead of serial DB calls; ensure
you reference platformTipGroups, contributionByGroup,
models.Transaction.findAll, contribution.HostCollectiveId and replace
Collective.findByPk usages accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@server/lib/pdf.ts`:
- Around line 67-85: The code currently collects PLATFORM_TIP TransactionGroup
values into platformTipGroups and builds contributionByGroup via
models.Transaction.findAll, but later still calls Collective.findByPk inside the
invoice loop for each relatedContribution.HostCollectiveId; change this to
batch-load all unique HostCollectiveId values after building
contributionByGroup: extract unique HostCollectiveId from the contributions
(contribution.HostCollectiveId), call models.Collective.findAll({ where: { id:
hostIds }, attributes: ['id','settings', ...] }) once, build a map keyed by id
(hostById) and use that map in place of Collective.findByPk inside the loop so
the invoice loop uses the in-memory host objects (and their settings) instead of
serial DB calls; ensure you reference platformTipGroups, contributionByGroup,
models.Transaction.findAll, contribution.HostCollectiveId and replace
Collective.findByPk usages accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ca6179c3-bfde-49c7-b1af-3f1ffce0a8b6

📥 Commits

Reviewing files that changed from the base of the PR and between 3e507ca and 15bc718.

📒 Files selected for processing (2)
  • server/lib/pdf.ts
  • test/server/graphql/common/transactions.test.js

znarf and others added 2 commits June 10, 2026 15:10
…ount

Transaction.createPlatformTipTransactions sets a platform tip's CollectiveId
and HostCollectiveId to the platform account, not the contribution's host.
The fixture pointed them at the contributed collective and its host, so the
host-admin assertion passed for the wrong reason. Host the fixture on the
platform account and assert that a contribution-host admin cannot download
the standalone platform tip receipt (only the payer can).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant