コード例 #1
0
def do_change_stream_message_retention_days(
        stream: Stream,
        acting_user: UserProfile,
        message_retention_days: Optional[int] = None) -> None:
    old_message_retention_days_value = stream.message_retention_days

    with transaction.atomic():
        stream.message_retention_days = message_retention_days
        stream.save(update_fields=["message_retention_days"])
        RealmAuditLog.objects.create(
            realm=stream.realm,
            acting_user=acting_user,
            modified_stream=stream,
            event_type=RealmAuditLog.STREAM_MESSAGE_RETENTION_DAYS_CHANGED,
            event_time=timezone_now(),
            extra_data=orjson.dumps({
                RealmAuditLog.OLD_VALUE:
                old_message_retention_days_value,
                RealmAuditLog.NEW_VALUE:
                message_retention_days,
            }).decode(),
        )

    event = dict(
        op="update",
        type="stream",
        property="message_retention_days",
        value=message_retention_days,
        stream_id=stream.id,
        name=stream.name,
    )
    send_event(stream.realm, event, can_access_stream_user_ids(stream))
    send_change_stream_message_retention_days_notification(
        user_profile=acting_user,
        stream=stream,
        old_value=old_message_retention_days_value,
        new_value=message_retention_days,
    )
コード例 #2
0
 def _set_stream_message_retention_value(
         self, stream: Stream, retention_period: Optional[int]) -> None:
     stream.message_retention_days = retention_period
     stream.save()