actions: Remove log_event and its legacy settings.

Now that we've finally converted these to use RealmAuditLog, we can
remove this ultra-legacy bit of code.
This commit is contained in:
Tim Abbott
2020-07-24 12:06:50 -07:00
parent 0d79b55b2e
commit 29c66cf7c2
6 changed files with 1 additions and 74 deletions

View File

@@ -2,7 +2,6 @@ import datetime
import itertools import itertools
import logging import logging
import os import os
import platform
import time import time
from collections import defaultdict from collections import defaultdict
from operator import itemgetter from operator import itemgetter
@@ -73,7 +72,6 @@ from zerver.lib.cache import (
user_profile_by_api_key_cache_key, user_profile_by_api_key_cache_key,
user_profile_by_email_cache_key, user_profile_by_email_cache_key,
) )
from zerver.lib.context_managers import lockfile
from zerver.lib.create_user import create_user, get_display_email_address from zerver.lib.create_user import create_user, get_display_email_address
from zerver.lib.email_mirror_helpers import encode_email_address, encode_email_address_helper from zerver.lib.email_mirror_helpers import encode_email_address, encode_email_address_helper
from zerver.lib.email_notifications import enqueue_welcome_emails from zerver.lib.email_notifications import enqueue_welcome_emails
@@ -256,25 +254,6 @@ def subscriber_info(user_id: int) -> Dict[str, Any]:
'flags': ['read'] 'flags': ['read']
} }
# Store an event in the log for re-importing messages
def log_event(event: MutableMapping[str, Any]) -> None:
if settings.EVENT_LOG_DIR is None:
return
if "timestamp" not in event:
event["timestamp"] = time.time()
if not os.path.exists(settings.EVENT_LOG_DIR):
os.mkdir(settings.EVENT_LOG_DIR)
template = os.path.join(settings.EVENT_LOG_DIR,
'%s.' + platform.node() +
timezone_now().strftime('.%Y-%m-%d'))
with lockfile(template % ('lock',)):
with open(template % ('events',), 'a') as log:
log.write(ujson.dumps(event) + '\n')
def can_access_stream_user_ids(stream: Stream) -> Set[int]: def can_access_stream_user_ids(stream: Stream) -> Set[int]:
# return user ids of users who can access the attributes of # return user ids of users who can access the attributes of
# a stream, such as its name/description. # a stream, such as its name/description.
@@ -3726,11 +3705,6 @@ def do_create_realm(string_id: str, name: str,
if settings.BILLING_ENABLED: if settings.BILLING_ENABLED:
do_change_plan_type(realm, Realm.LIMITED) do_change_plan_type(realm, Realm.LIMITED)
# Log the event
log_event({"type": "realm_created",
"string_id": string_id,
"emails_restricted_to_domains": emails_restricted_to_domains})
sender = get_system_bot(settings.NOTIFICATION_BOT) sender = get_system_bot(settings.NOTIFICATION_BOT)
admin_realm = sender.realm admin_realm = sender.realm
# Send a notification to the admin realm # Send a notification to the admin realm

View File

@@ -1,5 +1,3 @@
import os
import shutil
import time import time
from typing import Any, Callable, Dict, List from typing import Any, Callable, Dict, List
from unittest import mock from unittest import mock
@@ -8,12 +6,7 @@ import ujson
from django.conf import settings from django.conf import settings
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from zerver.lib.actions import ( from zerver.lib.actions import check_send_message, do_change_user_role, do_set_realm_property
check_send_message,
do_change_user_role,
do_set_realm_property,
log_event,
)
from zerver.lib.events import fetch_initial_state_data, get_raw_user_data from zerver.lib.events import fetch_initial_state_data, get_raw_user_data
from zerver.lib.test_classes import ZulipTestCase from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.test_helpers import POSTRequestMock, queries_captured, stub_event_queue_user_events from zerver.lib.test_helpers import POSTRequestMock, queries_captured, stub_event_queue_user_events
@@ -38,27 +31,6 @@ from zerver.tornado.views import get_events
from zerver.views.events_register import _default_all_public_streams, _default_narrow from zerver.views.events_register import _default_all_public_streams, _default_narrow
class LogEventsTest(ZulipTestCase):
def test_with_missing_event_log_dir_setting(self) -> None:
with self.settings(EVENT_LOG_DIR=None):
log_event(dict())
def test_log_event_mkdir(self) -> None:
dir_name = os.path.join(settings.TEST_WORKER_DIR, "test-log-dir")
try:
shutil.rmtree(dir_name)
except OSError: # nocoverage
# assume it doesn't exist already
pass
self.assertFalse(os.path.exists(dir_name))
with self.settings(EVENT_LOG_DIR=dir_name):
event: Dict[str, int] = {}
log_event(event)
self.assertTrue(os.path.exists(dir_name))
class EventsEndpointTest(ZulipTestCase): class EventsEndpointTest(ZulipTestCase):
def test_events_register_endpoint(self) -> None: def test_events_register_endpoint(self) -> None:

View File

@@ -31,7 +31,6 @@ from .configured_settings import (
EMAIL_BACKEND, EMAIL_BACKEND,
EMAIL_HOST, EMAIL_HOST,
ERROR_REPORTING, ERROR_REPORTING,
EVENT_LOGS_ENABLED,
EXTERNAL_HOST, EXTERNAL_HOST,
EXTERNAL_HOST_WITHOUT_PORT, EXTERNAL_HOST_WITHOUT_PORT,
EXTERNAL_URI_SCHEME, EXTERNAL_URI_SCHEME,
@@ -688,15 +687,6 @@ SCHEDULED_MESSAGE_DELIVERER_LOG_PATH = zulip_path("/var/log/zulip/scheduled_mess
RETENTION_LOG_PATH = zulip_path("/var/log/zulip/message_retention.log") RETENTION_LOG_PATH = zulip_path("/var/log/zulip/message_retention.log")
AUTH_LOG_PATH = zulip_path("/var/log/zulip/auth.log") AUTH_LOG_PATH = zulip_path("/var/log/zulip/auth.log")
# The EVENT_LOGS feature is an ultra-legacy piece of code, which
# originally logged all significant database changes for debugging.
# We plan to replace it with RealmAuditLog, stored in the database,
# everywhere that code mentioning it appears.
if EVENT_LOGS_ENABLED:
EVENT_LOG_DIR: Optional[str] = zulip_path("/home/zulip/logs/event_log")
else:
EVENT_LOG_DIR = None
ZULIP_WORKER_TEST_FILE = '/tmp/zulip-worker-test-file' ZULIP_WORKER_TEST_FILE = '/tmp/zulip-worker-test-file'

View File

@@ -223,11 +223,6 @@ EXTRA_INSTALLED_APPS = ['analytics']
# Default GOOGLE_CLIENT_ID to the value needed for Android auth to work # Default GOOGLE_CLIENT_ID to the value needed for Android auth to work
GOOGLE_CLIENT_ID = '835904834568-77mtr5mtmpgspj9b051del9i9r5t4g4n.apps.googleusercontent.com' GOOGLE_CLIENT_ID = '835904834568-77mtr5mtmpgspj9b051del9i9r5t4g4n.apps.googleusercontent.com'
# Legacy event logs configuration. Our plans include removing
# log_event entirely in favor of RealmAuditLog, at which point we
# can remove this setting.
EVENT_LOGS_ENABLED = False
# Used to construct URLs to point to the Zulip server. Since we # Used to construct URLs to point to the Zulip server. Since we
# only support HTTPS in production, this is just for development. # only support HTTPS in production, this is just for development.
EXTERNAL_URI_SCHEME = "https://" EXTERNAL_URI_SCHEME = "https://"

View File

@@ -73,7 +73,6 @@ INVITES_MIN_USER_AGE_DAYS = 0
EMBEDDED_BOTS_ENABLED = True EMBEDDED_BOTS_ENABLED = True
SAVE_FRONTEND_STACKTRACES = True SAVE_FRONTEND_STACKTRACES = True
EVENT_LOGS_ENABLED = True
STAGING_ERROR_NOTIFICATIONS = True STAGING_ERROR_NOTIFICATIONS = True
SYSTEM_ONLY_REALMS: Set[str] = set() SYSTEM_ONLY_REALMS: Set[str] = set()

View File

@@ -60,9 +60,6 @@ if "GENERATE_STRIPE_FIXTURES" in os.environ:
# This allows CasperJS to proceed quickly to the next test step. # This allows CasperJS to proceed quickly to the next test step.
POLL_TIMEOUT = 1000 POLL_TIMEOUT = 1000
# Don't use the real message log for tests
EVENT_LOG_DIR = '/tmp/zulip-test-event-log'
# Stores the messages in `django.core.mail.outbox` rather than sending them. # Stores the messages in `django.core.mail.outbox` rather than sending them.
EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend' EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'