Complete the code to check if a user is authenticated.
if user.[1](): print("Access granted")
The method is_authenticated() returns True if the user is logged in.
Complete the code to authorize a user based on their role.
if user.role == '[1]': allow_access()
The role 'admin' typically has full access rights in a system.
Fix the error in the code that checks user permissions.
if user.has_permission('[1]'): perform_action()
Permission names should be simple strings without spaces or special characters, like 'read_data'.
Fill both blanks to create a dictionary of users with their roles, filtering only admins.
admins = {user: [1] for user, [2] in users.items() if role == 'admin'}The dictionary comprehension uses 'role' as the variable for the user's role, matching the filter condition.
Fill all three blanks to create a dictionary of usernames in uppercase with their permissions filtered by 'write' access.
filtered = [1]([2].upper(): perms for [3], perms in user_permissions.items() if 'write' in perms)
We use dict to create a dictionary, user as the variable for usernames, and convert usernames to uppercase.