Checking whether a user has global super-user permissions by comparing their user ID with 1 is not bad; it works.

However, there are cases where you, as a developer, want to know what functions check for super-user access, or even redefine it (I can't picture a use case for the latter right now, though).

To accomodate this and make the permission checks more readable and easier to find, I would suggest either of two options:

1.) Define USER_ROOT_UID as 1 and compare the uid to that constant
2.) Move the $user->uid check to a function user_is_root() (following the convention of user_is_anonymous() etc.) and call that.

(It would be possible to do both)

Comments

Anonymous’s picture

Version: 7.x-dev » 8.x-dev

This makes sense to me. I think option 1) is preferable.

steamx’s picture

Issue summary: View changes
Status: Active » Closed (works as designed)

Doesn't make sense for either 7 or 8 as superuser rights can be defined by user roles or permissions. So check for those. UID 0 and 1 are reserved so user 1 will always be "root" on purpose. No need for some minor overhead function.