@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix a Phortune bug where an invalid viewer could sometimes be selected for billing a subscription

Summary:
A live instance hit the scenario described in the comment, where an out-of-date user was being selected as the actor.

Since they were no longer an account member, they could not see the payment method and autopay was failing.

Instead, select a relatively arbitrary user who is a current, valid, non-disabled member.

Test Plan: Ran subscriptions with `bin/worker execute ...`, saw it select a valid actor.

Reviewers: chad

Reviewed By: chad

Differential Revision: https://secure.phabricator.com/D16757

+21 -6
+21 -6
src/applications/phortune/worker/PhortuneSubscriptionWorker.php
··· 36 36 ->setSubscription($subscription); 37 37 38 38 // TODO: This isn't really ideal. It would be better to use an application 39 - // actor than the original author of the subscription. In particular, if 40 - // someone initiates a subscription, adds some other account managers, and 41 - // later leaves the company, they'll continue "acting" here indefinitely. 39 + // actor than a fairly arbitrary account member. 40 + 42 41 // However, for now, some of the stuff later in the pipeline requires a 43 42 // valid actor with a real PHID. The subscription should eventually be 44 43 // able to create these invoices "as" the application it is acting on 45 44 // behalf of. 46 - $actor = id(new PhabricatorPeopleQuery()) 45 + 46 + $members = id(new PhabricatorPeopleQuery()) 47 47 ->setViewer($viewer) 48 - ->withPHIDs(array($subscription->getAuthorPHID())) 49 - ->executeOne(); 48 + ->withPHIDs($account->getMemberPHIDs()) 49 + ->execute(); 50 + $actor = null; 51 + foreach ($members as $member) { 52 + 53 + // Don't act as a disabled user. If all of the users on the account are 54 + // disabled this means we won't charge the subscription, but that's 55 + // probably correct since it means no one can cancel or pay it anyway. 56 + if ($member->getIsDisabled()) { 57 + continue; 58 + } 59 + 60 + // For now, just pick the first valid user we encounter as the actor. 61 + $actor = $member; 62 + break; 63 + } 64 + 50 65 if (!$actor) { 51 66 throw new Exception(pht('Failed to load actor to bill subscription!')); 52 67 }