~homeworkprod/byceps

84396457a4180271827fdc810c6bcca0bb72fb03 — Jochen Kupperschmidt 8 months ago e5d69bc
Do not pass current user to `calculate_posting_page_number`
M byceps/blueprints/site/board/service.py => byceps/blueprints/site/board/service.py +9 -2
@@ 27,6 27,7 @@ from ....services.user_badge import awarding_service as badge_awarding_service
from ....services.user_badge.transfer.models import Badge
from ....typing import BrandID, PartyID, UserID

from .authorization import BoardPermission
from .models import CategoryWithLastUpdateAndUnseenFlag, Creator, Ticket




@@ 140,12 141,13 @@ def _get_badges_for_users(
    return dict(generate_items())


def calculate_posting_page_number(posting: DbPosting, user: CurrentUser) -> int:
def calculate_posting_page_number(posting: DbPosting) -> int:
    """Calculate the number of postings to show per page."""
    include_hidden = may_current_user_view_hidden()
    postings_per_page = get_postings_per_page_value()

    return board_posting_query_service.calculate_posting_page_number(
        posting, user, postings_per_page
        posting, include_hidden, postings_per_page
    )




@@ 170,3 172,8 @@ def _get_site_setting_int_value(key, default_value) -> int:
        return default_value

    return int(value)


def may_current_user_view_hidden() -> bool:
    """Return `True' if the current user may view hidden items."""
    return g.user.has_permission(BoardPermission.view_hidden)

M byceps/blueprints/site/board/views_posting.py => byceps/blueprints/site/board/views_posting.py +5 -5
@@ 36,7 36,7 @@ def posting_view(posting_id):
    """
    posting = h.get_posting_or_404(posting_id)

    page = service.calculate_posting_page_number(posting, g.user)
    page = service.calculate_posting_page_number(posting)

    return redirect(
        h.build_url_for_posting_in_topic_view(posting, page, _external=True)


@@ 136,7 136,7 @@ def posting_update_form(posting_id, erroneous_form=None):
    """Show form to update a posting."""
    posting = h.get_posting_or_404(posting_id)

    page = service.calculate_posting_page_number(posting, g.user)
    page = service.calculate_posting_page_number(posting)
    url = h.build_url_for_posting_in_topic_view(posting, page)

    user_may_update = posting.may_be_updated_by_user(g.user)


@@ 173,7 173,7 @@ def posting_update(posting_id):
    """Update a posting."""
    posting = h.get_posting_or_404(posting_id)

    page = service.calculate_posting_page_number(posting, g.user)
    page = service.calculate_posting_page_number(posting)
    url = h.build_url_for_posting_in_topic_view(posting, page)

    user_may_update = posting.may_be_updated_by_user(g.user)


@@ 237,7 237,7 @@ def posting_hide(posting_id):

    event = board_posting_command_service.hide_posting(posting.id, moderator_id)

    page = service.calculate_posting_page_number(posting, g.user)
    page = service.calculate_posting_page_number(posting)

    flash_success(gettext('The posting has been hidden.'), icon='hidden')



@@ 261,7 261,7 @@ def posting_unhide(posting_id):
        posting.id, moderator_id
    )

    page = service.calculate_posting_page_number(posting, g.user)
    page = service.calculate_posting_page_number(posting)

    flash_success(
        gettext('The posting has been made visible again.'), icon='view'

M byceps/blueprints/site/board/views_topic.py => byceps/blueprints/site/board/views_topic.py +1 -1
@@ 91,7 91,7 @@ def topic_view(topic_id, page):
        if posting is None:
            page = 1
        else:
            page = service.calculate_posting_page_number(posting, g.user)
            page = service.calculate_posting_page_number(posting)
            # Jump to a specific posting. This requires a redirect.
            url = h.build_url_for_posting_in_topic_view(posting, page)
            return redirect(url, code=307)

M byceps/services/board/posting_query_service.py => byceps/services/board/posting_query_service.py +9 -7
@@ 82,14 82,16 @@ def _get_users_by_id(


def calculate_posting_page_number(
    posting: DbPosting, user: CurrentUser, postings_per_page: int
    posting: DbPosting, include_hidden: bool, postings_per_page: int
) -> int:
    """Return the number of the page the posting should appear on when
    viewed by the user.
    """
    topic_postings = DbPosting.query \
        .for_topic(posting.topic_id) \
        .only_visible_for_user(user) \
    """Return the number of the page the posting should appear on."""
    query = DbPosting.query \
        .for_topic(posting.topic_id)

    if not include_hidden:
        query = query.without_hidden()

    topic_postings = query \
        .earliest_to_latest() \
        .all()