Problem/Motivation

PaymentOptionsBuilder gets the order's customer and then, if the customer isAuthenticated() will show the stored options for that customer. Whilst in core, isAuthenticated() is a direct opposite of isAnonymous(), it's possible to override the user entity class and make modifications to that for other purposes (in our case we have a CRM, so we have users stored that are not anonymous, but also have no login credentials, so are not authenticated).

There are also a bunch of other places, such as payment gateways, profiles, receipts etc that do the same.

Proposed resolution

Switch to checking !isAnonymous() where we are trying to identify accounts that are not the anonymous user.

Comments

andrewbelcher created an issue. See original summary.

andrewbelcher’s picture

Status: Active » Needs review
StatusFileSize
new815 bytes

Here's a patch to make the switch.

andrewbelcher’s picture

Title: PaymentOptionsBuilder should allow stored payments for non anonymous, rather than authenticated » Use NOT isAnonymous rather than isAuthenticated for checking accounts are not the anonymous user
Issue summary: View changes
StatusFileSize
new6.45 KB

There are various other places which do the same, so here's a patch where I've gone through every call to User::isAuthenticated() and, where I think appropriate, switched it to !User::isAnonymous().

mrdalesmith’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new6.9 KB

Updated patch as it no longer applied to the latest version.

jsacksick’s picture

Status: Reviewed & tested by the community » Fixed

I think this makes the code a little bit less readable... But if this helps with your usecase... The thing is, if we follow your reasoning then what guarantees that the isAnonymous() method will always contain logic that work in our cases?

I'm guessing the problem is how core named its methods, isAuthenticated() makes it sound the user is actually authenticated while the check performed only ensures the $user->uid() > 0.

Since I committed an equivalent patch already previously, decided to also commit this one though we'll probably have to make sure to not forget about this when it comes to adding similar checks in the future.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.