def do_get_user_invites(user_profile: UserProfile) -> List[Dict[(str, Any)]]:
    if user_profile.is_realm_admin:
        prereg_users = filter_to_valid_prereg_users(PreregistrationUser.objects.filter(referred_by__realm=user_profile.realm))
    else:
        prereg_users = filter_to_valid_prereg_users(PreregistrationUser.objects.filter(referred_by=user_profile))
    invites = []
    for invitee in prereg_users:
        invites.append(dict(email=invitee.email, invited_by_user_id=invitee.referred_by.id, invited=datetime_to_timestamp(invitee.invited_at), id=invitee.id, invited_as=invitee.invited_as, is_multiuse=False))
    if (not user_profile.is_realm_admin):
        return invites
    lowest_datetime = (timezone_now() - datetime.timedelta(days=settings.INVITATION_LINK_VALIDITY_DAYS))
    multiuse_confirmation_objs = Confirmation.objects.filter(realm=user_profile.realm, type=Confirmation.MULTIUSE_INVITE, date_sent__gte=lowest_datetime)
    for confirmation_obj in multiuse_confirmation_objs:
        invite = confirmation_obj.content_object
        invites.append(dict(invited_by_user_id=invite.referred_by.id, invited=datetime_to_timestamp(confirmation_obj.date_sent), id=invite.id, link_url=confirmation_url(confirmation_obj.confirmation_key, user_profile.realm, Confirmation.MULTIUSE_INVITE), invited_as=invite.invited_as, is_multiuse=True))
    return invites
def do_get_user_invites(user_profile: UserProfile) -> List[Dict[(str, Any)]]:
    if user_profile.is_realm_admin:
        prereg_users = filter_to_valid_prereg_users(PreregistrationUser.objects.filter(referred_by__realm=user_profile.realm))
    else:
        prereg_users = filter_to_valid_prereg_users(PreregistrationUser.objects.filter(referred_by=user_profile))
    invites = []
    for invitee in prereg_users:
        invites.append(dict(email=invitee.email, invited_by_user_id=invitee.referred_by.id, invited=datetime_to_timestamp(invitee.invited_at), id=invitee.id, invited_as=invitee.invited_as, is_multiuse=False))
    if (not user_profile.is_realm_admin):
        return invites
    lowest_datetime = (timezone_now() - datetime.timedelta(days=settings.INVITATION_LINK_VALIDITY_DAYS))
    multiuse_confirmation_objs = Confirmation.objects.filter(realm=user_profile.realm, type=Confirmation.MULTIUSE_INVITE, date_sent__gte=lowest_datetime)
    for confirmation_obj in multiuse_confirmation_objs:
        invite = confirmation_obj.content_object
        invites.append(dict(invited_by_user_id=invite.referred_by.id, invited=datetime_to_timestamp(confirmation_obj.date_sent), id=invite.id, link_url=confirmation_url(confirmation_obj.confirmation_key, user_profile.realm, Confirmation.MULTIUSE_INVITE), invited_as=invite.invited_as, is_multiuse=True))
    return invites