~homeworkprod/byceps

4e95e590e725922047822aef3b5b4682dd5c75d2 — Jochen Kupperschmidt a month ago f223e20
Explicitly cast values to type aliases
M byceps/services/authentication/session/service.py => byceps/services/authentication/session/service.py +1 -1
@@ 165,7 165,7 @@ def _record_recent_login(user_id: UserID, occurred_at: datetime) -> None:
    upsert(table, identifier, replacement)


ANONYMOUS_USER_ID = UUID('00000000-0000-0000-0000-000000000000')
ANONYMOUS_USER_ID = UserID(UUID('00000000-0000-0000-0000-000000000000'))


def get_anonymous_current_user(*, locale: Optional[str] = None) -> CurrentUser:

M byceps/services/authorization/impex_service.py => byceps/services/authorization/impex_service.py +8 -4
@@ 17,6 17,7 @@ import rtoml
from ...database import db

from .dbmodels import Permission as DbPermission, Role as DbRole
from .transfer.models import PermissionID, RoleID
from . import service




@@ 39,16 40,19 @@ def import_from_file(path: Path) -> tuple[int, int]:

def _create_permissions(permissions: list[dict[str, str]]) -> None:
    for permission in permissions:
        service.create_permission(permission['id'], permission['title'])
        permission_id = PermissionID(permission['id'])
        service.create_permission(permission_id, permission['title'])


def _create_roles(roles: list[dict[str, Union[str, list[str]]]]) -> None:
    for role in roles:
        role_id = role['id']
        role_id = RoleID(str(role['id']))
        role_title = str(role['title'])

        service.create_role(role_id, role['title'])
        service.create_role(role_id, role_title)

        for permission_id in role['assigned_permissions']:
        for permission_id_str in role['assigned_permissions']:
            permission_id = PermissionID(permission_id_str)
            service.assign_permission_to_role(permission_id, role_id)



M byceps/services/shop/order/email/example_service.py => byceps/services/shop/order/email/example_service.py +6 -4
@@ 15,7 15,7 @@ from flask_babel import gettext

from .....config import ConfigurationError
from .....database import generate_uuid
from .....typing import BrandID
from .....typing import BrandID, UserID

from ....email.transfer.models import Message



@@ 26,7 26,9 @@ from ..email.service import OrderEmailData
from ..transfer.models import (
    Address,
    Order,
    OrderID,
    OrderItem,
    OrderNumber,
    PaymentMethod,
    PaymentState,
)


@@ 108,11 110,11 @@ def _build_order(
    is_paid: bool = False,
    cancelation_reason: Optional[str] = None,
) -> Order:
    order_id = generate_uuid()
    order_number = 'AWSM-ORDR-9247'
    order_id = OrderID(generate_uuid())
    order_number = OrderNumber('AWSM-ORDR-9247')

    created_at = datetime.utcnow()
    placed_by_id = generate_uuid()
    placed_by_id = UserID(generate_uuid())

    first_names = 'Bella-Bernadine'
    last_name = 'Ballerwurm'

M byceps/util/user_session.py => byceps/util/user_session.py +7 -4
@@ 9,6 9,7 @@ byceps.util.user_session
from __future__ import annotations
from enum import Enum
from typing import Optional
from uuid import UUID

from flask import session



@@ 68,14 69,14 @@ def get_current_user(

def get_user(*, party_id: Optional[PartyID] = None) -> Optional[User]:
    """Return the current user if authenticated, `None` if not."""
    user_id = session.get(KEY_USER_ID)
    user_id_str = session.get(KEY_USER_ID)
    auth_token = session.get(KEY_USER_AUTH_TOKEN)

    return _load_user(user_id, auth_token, party_id=party_id)
    return _load_user(user_id_str, auth_token, party_id=party_id)


def _load_user(
    user_id: Optional[str],
    user_id_str: Optional[str],
    auth_token: Optional[str],
    *,
    party_id: Optional[PartyID] = None,


@@ 87,9 88,11 @@ def _load_user(
    - the account is not enabled.
    - the auth token is invalid.
    """
    if user_id is None:
    if user_id_str is None:
        return None

    user_id = UserID(UUID(user_id_str))

    user = user_service.find_active_user(
        user_id, include_avatar=True, include_orga_flag_for_party_id=party_id
    )