Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
actions: Remove log_event and its legacy settings.
Tim Abbott29c66cf7c2c1
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.pyindex 075a0f784d7..114de6b0456 100644--- a/zerver/lib/actions.py+++ b/zerver/lib/actions.py@@ -2,7 +2,6 @@ import datetimeimport itertoolsimport loggingimport os-import platformimport timefrom collections import defaultdictfrom operator import itemgetter@@ -73,7 +72,6 @@ from zerver.lib.cache import (user_profile_by_api_key_cache_key,user_profile_by_email_cache_key,)-from zerver.lib.context_managers import lockfilefrom zerver.lib.create_user import create_user, get_display_email_addressfrom zerver.lib.email_mirror_helpers import encode_email_address, encode_email_address_helperfrom zerver.lib.email_notifications import enqueue_welcome_emails@@ -256,25 +254,6 @@ def subscriber_info(user_id: int) -> Dict[str, Any]:'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]:# return user ids of users who can access the attributes of# a stream, such as its name/description.@@ -3726,11 +3705,6 @@ def do_create_realm(string_id: str, name: str,if settings.BILLING_ENABLED: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)admin_realm = sender.realm# Send a notification to the admin realmdiff --git a/zerver/tests/test_event_system.py b/zerver/tests/test_event_system.pyindex e42bbc643a1..9c31e63182d 100644--- a/zerver/tests/test_event_system.py+++ b/zerver/tests/test_event_system.py@@ -1,5 +1,3 @@-import os-import shutilimport timefrom typing import Any, Callable, Dict, Listfrom unittest import mock@@ -8,12 +6,7 @@ import ujsonfrom django.conf import settingsfrom django.http import HttpRequest, HttpResponse-from zerver.lib.actions import (- check_send_message,- do_change_user_role,- do_set_realm_property,- log_event,-)+from zerver.lib.actions import check_send_message, do_change_user_role, do_set_realm_propertyfrom zerver.lib.events import fetch_initial_state_data, get_raw_user_datafrom zerver.lib.test_classes import ZulipTestCasefrom zerver.lib.test_helpers import POSTRequestMock, queries_captured, stub_event_queue_user_events@@ -38,27 +31,6 @@ from zerver.tornado.views import get_eventsfrom 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):def test_events_register_endpoint(self) -> None:diff --git a/zproject/computed_settings.py b/zproject/computed_settings.pyindex 017fd1af445..01d1a45e207 100644--- a/zproject/computed_settings.py+++ b/zproject/computed_settings.py@@ -31,7 +31,6 @@ from .configured_settings import (EMAIL_BACKEND,EMAIL_HOST,ERROR_REPORTING,- EVENT_LOGS_ENABLED,EXTERNAL_HOST,EXTERNAL_HOST_WITHOUT_PORT,EXTERNAL_URI_SCHEME,@@ -688,15 +687,6 @@ SCHEDULED_MESSAGE_DELIVERER_LOG_PATH = zulip_path("/var/log/zulip/scheduled_messRETENTION_LOG_PATH = zulip_path("/var/log/zulip/message_retention.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'diff --git a/zproject/default_settings.py b/zproject/default_settings.pyindex 43adbe1ec57..2d3272ee422 100644--- a/zproject/default_settings.py+++ b/zproject/default_settings.py@@ -223,11 +223,6 @@ EXTRA_INSTALLED_APPS = ['analytics']# Default GOOGLE_CLIENT_ID to the value needed for Android auth to workGOOGLE_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# only support HTTPS in production, this is just for development.EXTERNAL_URI_SCHEME = "https://"diff --git a/zproject/dev_settings.py b/zproject/dev_settings.pyindex 6100ddb61ef..65e777dc767 100644--- a/zproject/dev_settings.py+++ b/zproject/dev_settings.py@@ -73,7 +73,6 @@ INVITES_MIN_USER_AGE_DAYS = 0EMBEDDED_BOTS_ENABLED = TrueSAVE_FRONTEND_STACKTRACES = True-EVENT_LOGS_ENABLED = TrueSTAGING_ERROR_NOTIFICATIONS = TrueSYSTEM_ONLY_REALMS: Set[str] = set()diff --git a/zproject/test_extra_settings.py b/zproject/test_extra_settings.pyindex cda3b7958d1..9572e674dcd 100644--- a/zproject/test_extra_settings.py+++ b/zproject/test_extra_settings.py@@ -60,9 +60,6 @@ if "GENERATE_STRIPE_FIXTURES" in os.environ:# This allows CasperJS to proceed quickly to the next test step.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.EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'