processwire-issues icon indicating copy to clipboard operation
processwire-issues copied to clipboard

User guest role inconsistencies

Open adrianbj opened this issue 4 years ago • 3 comments

Short description of the issue

I've brought this up somewhere else before but can't find it at the moment. The issue is that if you create users via the API, the guest role is not automatically applied to them. What is weird though is that there is a lot of inconsistency is the admin GUI and the API around whether the user actually has the guest role or not. If you edit their user page, it shows that guest is checked, but if you view all users via Access > Users, then the guest role is not listed in the Lister table view for that user and if you filter by users with the guest role, that user also won't show up in the results.

Now if you try these calls:

This does find the user without the guest role

$users->find('roles!=guest');

But this includes that same user:

$users->find('roles=guest');

Surprisingly, it's also possible to do:

$user->removeRole('guest');

and it will actually remove the guest role.

Expected behavior

guest role is automatically added when creating a new user via the API and it is impossible to remove that role.

adrianbj avatar Jan 24 '21 19:01 adrianbj

Actually, I wonder if semantically it would be nicer if the guest role was not needed for all users (or at least not shown when a user has other roles). Think about the isGuest() method - if all users have the guest role, then surely we would expect them to all return true for isGuest(). Of course, isGuest() is referring to the user and not the role, but this is inconsistent with the isSuperuser() check which is referring to the superuser role, rather than a user named "superuser".

Maybe I am being pedantic, but I have had issues with the guest role several times in the past.

adrianbj avatar Jan 24 '21 19:01 adrianbj

I agree and think it would be good if there was a general review of how the guest role is treated in PW. Particularly, each time "guest" appears in the admin review if the appearance is actually useful or is more likely adding inconvenience or confusion or visual noise.

Example: https://github.com/processwire/processwire-requests/issues/200

And seeing "guest" in the Roles column for every user in the Users lister isn't a useful thing - it would be clearer if only the functional roles were visible.

I'm not even sure why "guest" is a role at all and couldn't be defined as the absence of all other roles.

Here's the original issue from @adrianbj: https://github.com/ryancramerdesign/ProcessWire/issues/588

@ryancramerdesign responded:

Guest role probably shouldn't be displayed anywhere, except in the Roles editor and in the Template Access tab. Anywhere else, it means absolutely nothing and is a waste of screen real estate. Guest role is assumed for all users regardless of whether it's assigned or not. There is no reason to ever do a hasRole("guest"). So I'd prefer to move towards storing and showing less useless data rather than more useless data. :) Guest was not always a default assumption like it is now, and that's the only reason you see it anywhere... but we should move towards elimination of guest in 2.6.

It would be great to have that implemented.

Toutouwai avatar Jan 24 '21 20:01 Toutouwai

Thanks for finding that old issue and pointing to the request @Toutouwai

adrianbj avatar Jan 24 '21 20:01 adrianbj