~homeworkprod/byceps

e185cafe10fcf762acc1fe8f36b33e85280c01e1 — Jochen Kupperschmidt 9 months ago d5688c9
Store potential site ID in account creation log event
M byceps/blueprints/admin/user/service.py => byceps/blueprints/admin/user/service.py +1 -1
@@ 336,7 336,7 @@ def _get_additional_data(
        }
        yield 'details', details

    if event.event_type == 'user-logged-in':
    if event.event_type in {'user-created', 'user-logged-in'}:
        site_id = event.data.get('site_id')
        if site_id:
            site = site_service.find_site(site_id)

M byceps/blueprints/admin/user/templates/admin/user/view_events.html => byceps/blueprints/admin/user/templates/admin/user/view_events.html +5 -1
@@ 49,7 49,11 @@
            {%- else %}
            Jemand
            {%- endif %}
            hat das Benutzerkonto <strong>angelegt</strong>.
            hat das Benutzerkonto
            {%- if event.site is defined %}
            auf Site &quot;{{ event.site.title }}&quot;
            {%- endif %}
            <strong>angelegt</strong>.
          {%- endset %}
        {%- elif event.event == 'user-initialized' %}
          {%- set icon_name = 'enabled' %}

M byceps/blueprints/admin/user/views.py => byceps/blueprints/admin/user/views.py +6 -5
@@ 170,12 170,12 @@ def create_account():
    last_name = form.last_name.data.strip()
    email_address = form.email_address.data.lower()
    password = form.password.data
    site_id = form.site_id.data
    site_id_for_email = form.site_id.data

    if site_id:
        site = site_service.get_site(site_id)
    if site_id_for_email:
        site_for_email = site_service.get_site(site_id_for_email)
    else:
        site = None
        site_for_email = None

    if user_service.is_screen_name_already_assigned(screen_name):
        flash_error(gettext('This username cannot be used.'))


@@ 195,6 195,7 @@ def create_account():
            first_names=first_names,
            last_name=last_name,
            creator_id=initiator_id,
            # Do not pass site ID here; the account is not created on a site.
        )
    except user_creation_service.UserCreationFailed:
        flash_error(


@@ 212,7 213,7 @@ def create_account():
        )
    )

    if site:
    if site_for_email:
        user_creation_service.request_email_address_confirmation(
            user, email_address, site_id
        )

M byceps/services/user/creation_service.py => byceps/services/user/creation_service.py +6 -0
@@ 50,6 50,7 @@ def create_user(
        password,
        first_names=first_names,
        last_name=last_name,
        site_id=site_id,
    )

    # consents


@@ 78,6 79,7 @@ def create_basic_user(
    first_names: Optional[str] = None,
    last_name: Optional[str] = None,
    creator_id: Optional[UserID] = None,
    site_id: Optional[SiteID] = None,
) -> Tuple[User, UserAccountCreated]:
    # user with details
    user, event = _create_user(


@@ 86,6 88,7 @@ def create_basic_user(
        first_names=first_names,
        last_name=last_name,
        creator_id=creator_id,
        site_id=site_id,
    )

    # password


@@ 101,6 104,7 @@ def _create_user(
    first_names: Optional[str] = None,
    last_name: Optional[str] = None,
    creator_id: Optional[UserID] = None,
    site_id: Optional[SiteID] = None,
) -> Tuple[User, UserAccountCreated]:
    if creator_id is not None:
        creator = user_service.get_user(creator_id)


@@ 127,6 131,8 @@ def _create_user(
    event_data = {}
    if creator is not None:
        event_data['initiator_id'] = str(creator.id)
    if site_id is not None:
        event_data['site_id'] = site_id
    event_service.create_event(
        'user-created', user.id, event_data, occurred_at=created_at
    )

M tests/integration/blueprints/site/user/test_views_create.py => tests/integration/blueprints/site/user/test_views_create.py +3 -3
@@ 151,7 151,7 @@ def test_create(
    assert not user.deleted

    # events
    assert_creation_event_created(user.id)
    assert_creation_event_created(user.id, site.id)

    # password
    assert_password_credentials_created(user.id)


@@ 259,13 259,13 @@ def is_subscribed_to_newsletter(user_id, brand_id):
    return newsletter_service.is_subscribed(user_id, brand_id)


def assert_creation_event_created(user_id):
def assert_creation_event_created(user_id, site_id):
    events = event_service.get_events_of_type_for_user(user_id, 'user-created')
    assert len(events) == 1

    first_event = events[0]
    assert first_event.event_type == 'user-created'
    assert first_event.data == {}
    assert first_event.data == {'site_id': site_id}


def assert_password_credentials_created(user_id):