def METHOD_NAME(
    self,
    user: AbstractUser,
    element: ElementForUpdate,
    before: Optional[Element] = None,
) -> Element:
    """
    Moves an element in the page before another element. If the `before` element is
    omitted the element is moved at the end of the page.
    :param user: The user who move the element.
    :param element: The element we want to move.
    :param before: The element before which we want to move the given element.
    :return: The element with an updated order.
    """
    CoreHandler().check_permissions(
        user,
        UpdateElementOperationType.type,
        workspace=element.page.builder.workspace,
        context=element,
    )
    # Check we are on the same page.
    if before and element.page_id != before.page_id:
        raise ElementNotInSamePage()
    try:
        element = self.handler.METHOD_NAME(element, before=before)
    except CannotCalculateIntermediateOrder:
        # If it's failing, we need to recalculate all orders then move again.
        self.recalculate_full_orders(user, element.page)
        # Refresh the before element as the order might have changed.
        before.refresh_from_db()
        element = self.handler.METHOD_NAME(element, before=before)
    element_moved.send(self, element=element, before=before, user=user)
    return element