def get_all_permission_grants_for_user(user_db, resource_uid=None, resource_types=None, permission_types=None):
 role_names = UserRoleAssignment.query(user=user_db.name).only('role').scalar('role')
 permission_grant_ids = Role.query(name__in=role_names).scalar('permission_grants')
 permission_grant_ids = sum(permission_grant_ids, [])
 permission_grants_filters = {}
 permission_grants_filters['id__in'] = permission_grant_ids
 if resource_uid:
  permission_grants_filters['resource_uid'] = resource_uid
 if resource_types:
  permission_grants_filters['resource_type__in'] = resource_types
 if permission_types:
  permission_grants_filters['permission_types__in'] = permission_types
 permission_grant_dbs = PermissionGrant.query(**permission_grants_filters)
 return permission_grant_dbs

def get_all_permission_grants_for_user ( user_db , resource_uid = None , resource_types = None , permission_types = None ) : role_names = UserRoleAssignment . query ( user = user_db . name ) . only ( 'role' ) . scalar ( 'role' ) permission_grant_ids = Role . query ( name__in = role_names ) . scalar ( 'permission_grants' ) permission_grant_ids = sum ( permission_grant_ids , [ ] ) permission_grants_filters = { } permission_grants_filters [ 'id__in' ] = permission_grant_ids if resource_uid : permission_grants_filters [ 'resource_uid' ] = resource_uid if resource_types : permission_grants_filters [ 'resource_type__in' ] = resource_types if permission_types : permission_grants_filters [ 'permission_types__in' ] = permission_types permission_grant_dbs = PermissionGrant . query ( ** permission_grants_filters ) return permission_grant_dbs
retrieve all the permission grants for a particular user optionally filtering on: - resource uid - resource types - permission types the result is a union of all the permission grants assigned to the roles which are assigned to the user .