~homeworkprod/byceps

52599523a50dce0e1c944f8c65d88174f34ffab2 — Jochen Kupperschmidt 1 year, 2 months ago c3ee3d1
Include initiator ID in news publication event
M byceps/blueprints/admin/news/views.py => byceps/blueprints/admin/news/views.py +1 -1
@@ 440,7 440,7 @@ def item_publish(item_id):
    """Publish a news item."""
    item = _get_item_or_404(item_id)

    event = news_item_service.publish_item(item.id)
    event = news_item_service.publish_item(item.id, initiator_id=g.current_user)

    signals.item_published.send(None, event=event)


M byceps/events/news.py => byceps/events/news.py +3 -0
@@ 7,12 7,15 @@ byceps.events.news
"""

from dataclasses import dataclass
from typing import Optional

from ..services.news.transfer.models import ItemID
from ..typing import UserID

from .base import _BaseEvent


@dataclass(frozen=True)
class NewsItemPublished(_BaseEvent):
    initiator_id: Optional[UserID]
    item_id: ItemID

M byceps/services/news/service.py => byceps/services/news/service.py +8 -2
@@ 94,14 94,20 @@ def _create_version(
    return version


def publish_item(item_id: ItemID) -> NewsItemPublished:
def publish_item(
    item_id: ItemID, *, initiator_id: Optional[UserID] = None
) -> NewsItemPublished:
    """Publish a news item."""
    item = _get_db_item(item_id)

    item.published_at = datetime.utcnow()
    db.session.commit()

    return NewsItemPublished(occurred_at=item.published_at, item_id=item.id)
    return NewsItemPublished(
        occurred_at=item.published_at,
        initiator_id=initiator_id,
        item_id=item.id,
    )


def delete_item(item_id: ItemID) -> None:

M tests/integration/announce/irc/test_news.py => tests/integration/announce/irc/test_news.py +4 -2
@@ 22,7 22,7 @@ from .helpers import (
)


def test_published_news_item_announced(app, item):
def test_published_news_item_announced(app, item, editor):
    expected_channels = [CHANNEL_ORGA_LOG, CHANNEL_PUBLIC]
    expected_text = (
        'ACME Entertainment Convention: '


@@ 31,7 31,9 @@ def test_published_news_item_announced(app, item):
    )

    with mocked_irc_bot() as mock:
        event = NewsItemPublished(occurred_at=now(), item_id=item.id)
        event = NewsItemPublished(
            occurred_at=now(), initiator_id=editor.id, item_id=item.id
        )
        news_signals.item_published.send(None, event=event)
        assert_submitted_data(mock, expected_channels, expected_text)