tools.alter_privileges module

User privilege management with 64-bit bitmask system.

Each user has a 64-bit integer stored in Redis whose individual bits represent specific privileges. Admins (config.admin_user_ids) implicitly have all 64 bits set.

Other tool modules can import the helpers to check privileges:

from tools.alter_privileges import has_privilege, PRIVILEGES
async tools.alter_privileges.get_user_privileges(redis, user_id, config=None)[source]

Return the privilege bitmask for user_id.

Admins get all 64 bits. Returns 0 when the user has no stored privileges and is not an admin.

Return type:

int

Parameters:
async tools.alter_privileges.has_privilege(redis, user_id, bit, config=None)[source]

Check whether user_id has a single privilege bit enabled.

Return type:

bool

Parameters: