def grant_permission(user, permission_name):
roles = get_user_roles(user)<EOL>for role in roles:<EOL><INDENT>if permission_name in role.permission_names_list():<EOL><INDENT>permission = get_permission(permission_name)<EOL>user.user_permissions.add(permission)<EOL>return<EOL><DEDENT><DEDENT>raise RolePermissionScopeException(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL>
Grant a user a specified permission.

Permissions are only granted if they are in the scope any of the
user's roles. If the permission is out of scope,
a RolePermissionScopeException is raised.