~homeworkprod/byceps

07761e715bf19496d75d7f4f69c494a80d57b8fd — Jochen Kupperschmidt 9 months ago ac29a0c
Make permission, locale arguments to current user factories optional
M byceps/services/authentication/session/service.py => byceps/services/authentication/session/service.py +5 -2
@@ 167,7 167,7 @@ def _record_recent_login(user_id: UserID, occurred_at: datetime) -> None:
ANONYMOUS_USER_ID = UUID('00000000-0000-0000-0000-000000000000')


def get_anonymous_current_user(locale: Optional[str]) -> CurrentUser:
def get_anonymous_current_user(*, locale: Optional[str] = None) -> CurrentUser:
    """Return an anonymous current user object."""
    return CurrentUser(
        id=ANONYMOUS_USER_ID,


@@ 183,9 183,12 @@ def get_anonymous_current_user(locale: Optional[str]) -> CurrentUser:


def get_authenticated_current_user(
    user: User, permissions: Set[Enum], locale: Optional[str]
    user: User, *, permissions: Set[Enum] = None, locale: Optional[str] = None
) -> CurrentUser:
    """Return an authenticated current user object."""
    if permissions is None:
        permissions = set()

    return CurrentUser(
        id=user.id,
        screen_name=user.screen_name,

M byceps/util/user_session.py => byceps/util/user_session.py +3 -3
@@ 51,15 51,15 @@ def get_current_user(
    user = get_user(party_id=party_id)

    if user is None:
        return session_service.get_anonymous_current_user(locale)
        return session_service.get_anonymous_current_user(locale=locale)

    permissions = get_permissions_for_user(user.id)

    if not required_permissions.issubset(permissions):
        return session_service.get_anonymous_current_user(locale)
        return session_service.get_anonymous_current_user(locale=locale)

    return session_service.get_authenticated_current_user(
        user, permissions, locale
        user, permissions=permissions, locale=locale
    )



M tests/integration/services/authentication/test_current_user.py => tests/integration/services/authentication/test_current_user.py +2 -2
@@ 12,7 12,7 @@ from byceps.util.authorization import create_permission_enum
def test_get_anonymous_current_user():
    locale = 'en'

    current_user = session_service.get_anonymous_current_user(locale)
    current_user = session_service.get_anonymous_current_user(locale=locale)

    assert current_user.id == UUID('00000000-0000-0000-0000-000000000000')
    assert current_user.screen_name is None


@@ 34,7 34,7 @@ def test_get_authenticated_current_user(user):
    locale = 'de'

    current_user = session_service.get_authenticated_current_user(
        user, permissions, locale
        user, permissions=permissions, locale=locale
    )

    assert current_user.id == user.id

M tests/integration/services/shop/order/email/helpers.py => tests/integration/services/shop/order/email/helpers.py +1 -6
@@ 14,12 14,7 @@ from tests.integration.services.shop.helpers import create_orderer


def get_current_user_for_user(user) -> CurrentUser:
    permissions = set()
    locale = None

    return session_service.get_authenticated_current_user(
        user, permissions, locale
    )
    return session_service.get_authenticated_current_user(user)


def place_order_with_items(