mirror of https://github.com/zulip/zulip.git
audit-log: Move user event types to AuditLogEventType enum.
Event types moved: USER_SOFT_ACTIVATED, USER_SOFT_DEACTIVATED USER_PASSWORD_CHANGED, USER_AVATAR_SOURCE_CHANGED, USER_FULL_NAME_CHANGED USER_EMAIL_CHANGED, USER_TERMS_OF_SERVICE_VERSION_CHANGED USER_API_KEY_CHANGED, USER_BOT_OWNER_CHANGED, USER_DEFAULT_SENDING_STREAM_CHANGED, USER_DEFAULT_REGISTER_STREAM_CHANGED USER_DEFAULT_ALL_PUBLIC_STREAMS_CHANGED, USER_SETTING_CHANGED USER_DIGEST_EMAIL_CREATED
This commit is contained in:
parent
e5daa3470f
commit
caeeaf3c3f
|
@ -1938,7 +1938,7 @@ class TestActiveUsersAudit(AnalyticsTestCase):
|
||||||
# doesn't go through do_create_user. Mainly just want to make sure that
|
# doesn't go through do_create_user. Mainly just want to make sure that
|
||||||
# that situation doesn't throw an error.
|
# that situation doesn't throw an error.
|
||||||
def test_empty_realm_or_user_with_no_relevant_activity(self) -> None:
|
def test_empty_realm_or_user_with_no_relevant_activity(self) -> None:
|
||||||
self.add_event(RealmAuditLog.USER_SOFT_ACTIVATED, 1)
|
self.add_event(AuditLogEventType.USER_SOFT_ACTIVATED, 1)
|
||||||
self.create_user(skip_auditlog=True) # also test a user with no RealmAuditLog entries
|
self.create_user(skip_auditlog=True) # also test a user with no RealmAuditLog entries
|
||||||
do_create_realm(string_id="moo", name="moo")
|
do_create_realm(string_id="moo", name="moo")
|
||||||
do_fill_count_stat_at_hour(self.stat, self.TIME_ZERO)
|
do_fill_count_stat_at_hour(self.stat, self.TIME_ZERO)
|
||||||
|
@ -1946,14 +1946,14 @@ class TestActiveUsersAudit(AnalyticsTestCase):
|
||||||
|
|
||||||
def test_max_audit_entry_is_unrelated(self) -> None:
|
def test_max_audit_entry_is_unrelated(self) -> None:
|
||||||
self.add_event(AuditLogEventType.USER_CREATED, 1)
|
self.add_event(AuditLogEventType.USER_CREATED, 1)
|
||||||
self.add_event(RealmAuditLog.USER_SOFT_ACTIVATED, 0.5)
|
self.add_event(AuditLogEventType.USER_SOFT_ACTIVATED, 0.5)
|
||||||
do_fill_count_stat_at_hour(self.stat, self.TIME_ZERO)
|
do_fill_count_stat_at_hour(self.stat, self.TIME_ZERO)
|
||||||
self.assertTableState(RealmCount, ["subgroup"], [["false"]])
|
self.assertTableState(RealmCount, ["subgroup"], [["false"]])
|
||||||
|
|
||||||
# Simultaneous related audit entries should not be allowed, and so not testing for that.
|
# Simultaneous related audit entries should not be allowed, and so not testing for that.
|
||||||
def test_simultaneous_unrelated_audit_entry(self) -> None:
|
def test_simultaneous_unrelated_audit_entry(self) -> None:
|
||||||
self.add_event(AuditLogEventType.USER_CREATED, 1)
|
self.add_event(AuditLogEventType.USER_CREATED, 1)
|
||||||
self.add_event(RealmAuditLog.USER_SOFT_ACTIVATED, 1)
|
self.add_event(AuditLogEventType.USER_SOFT_ACTIVATED, 1)
|
||||||
do_fill_count_stat_at_hour(self.stat, self.TIME_ZERO)
|
do_fill_count_stat_at_hour(self.stat, self.TIME_ZERO)
|
||||||
self.assertTableState(RealmCount, ["subgroup"], [["false"]])
|
self.assertTableState(RealmCount, ["subgroup"], [["false"]])
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ from zerver.actions.create_user import created_bot_event
|
||||||
from zerver.actions.streams import bulk_remove_subscriptions
|
from zerver.actions.streams import bulk_remove_subscriptions
|
||||||
from zerver.lib.streams import get_subscribed_private_streams_for_user
|
from zerver.lib.streams import get_subscribed_private_streams_for_user
|
||||||
from zerver.models import RealmAuditLog, Stream, UserProfile
|
from zerver.models import RealmAuditLog, Stream, UserProfile
|
||||||
|
from zerver.models.realm_audit_logs import AuditLogEventType
|
||||||
from zerver.models.users import active_user_ids, bot_owner_user_ids
|
from zerver.models.users import active_user_ids, bot_owner_user_ids
|
||||||
from zerver.tornado.django_api import send_event_on_commit
|
from zerver.tornado.django_api import send_event_on_commit
|
||||||
|
|
||||||
|
@ -110,7 +111,7 @@ def do_change_bot_owner(
|
||||||
realm=user_profile.realm,
|
realm=user_profile.realm,
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
modified_user=user_profile,
|
modified_user=user_profile,
|
||||||
event_type=RealmAuditLog.USER_BOT_OWNER_CHANGED,
|
event_type=AuditLogEventType.USER_BOT_OWNER_CHANGED,
|
||||||
event_time=event_time,
|
event_time=event_time,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -130,7 +131,7 @@ def do_change_default_sending_stream(
|
||||||
event_time = timezone_now()
|
event_time = timezone_now()
|
||||||
RealmAuditLog.objects.create(
|
RealmAuditLog.objects.create(
|
||||||
realm=user_profile.realm,
|
realm=user_profile.realm,
|
||||||
event_type=RealmAuditLog.USER_DEFAULT_SENDING_STREAM_CHANGED,
|
event_type=AuditLogEventType.USER_DEFAULT_SENDING_STREAM_CHANGED,
|
||||||
event_time=event_time,
|
event_time=event_time,
|
||||||
modified_user=user_profile,
|
modified_user=user_profile,
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
|
@ -171,7 +172,7 @@ def do_change_default_events_register_stream(
|
||||||
event_time = timezone_now()
|
event_time = timezone_now()
|
||||||
RealmAuditLog.objects.create(
|
RealmAuditLog.objects.create(
|
||||||
realm=user_profile.realm,
|
realm=user_profile.realm,
|
||||||
event_type=RealmAuditLog.USER_DEFAULT_REGISTER_STREAM_CHANGED,
|
event_type=AuditLogEventType.USER_DEFAULT_REGISTER_STREAM_CHANGED,
|
||||||
event_time=event_time,
|
event_time=event_time,
|
||||||
modified_user=user_profile,
|
modified_user=user_profile,
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
|
@ -213,7 +214,7 @@ def do_change_default_all_public_streams(
|
||||||
event_time = timezone_now()
|
event_time = timezone_now()
|
||||||
RealmAuditLog.objects.create(
|
RealmAuditLog.objects.create(
|
||||||
realm=user_profile.realm,
|
realm=user_profile.realm,
|
||||||
event_type=RealmAuditLog.USER_DEFAULT_ALL_PUBLIC_STREAMS_CHANGED,
|
event_type=AuditLogEventType.USER_DEFAULT_ALL_PUBLIC_STREAMS_CHANGED,
|
||||||
event_time=event_time,
|
event_time=event_time,
|
||||||
modified_user=user_profile,
|
modified_user=user_profile,
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
|
|
|
@ -706,7 +706,7 @@ def do_reactivate_user(user_profile: UserProfile, *, acting_user: UserProfile |
|
||||||
realm=user_profile.realm,
|
realm=user_profile.realm,
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
modified_user=user_profile,
|
modified_user=user_profile,
|
||||||
event_type=RealmAuditLog.USER_BOT_OWNER_CHANGED,
|
event_type=AuditLogEventType.USER_BOT_OWNER_CHANGED,
|
||||||
event_time=event_time,
|
event_time=event_time,
|
||||||
)
|
)
|
||||||
bot_owner_changed = True
|
bot_owner_changed = True
|
||||||
|
|
|
@ -41,6 +41,7 @@ from zerver.models import (
|
||||||
UserProfile,
|
UserProfile,
|
||||||
)
|
)
|
||||||
from zerver.models.clients import get_client
|
from zerver.models.clients import get_client
|
||||||
|
from zerver.models.realm_audit_logs import AuditLogEventType
|
||||||
from zerver.models.users import bot_owner_user_ids, get_user_profile_by_id
|
from zerver.models.users import bot_owner_user_ids, get_user_profile_by_id
|
||||||
from zerver.tornado.django_api import send_event_on_commit
|
from zerver.tornado.django_api import send_event_on_commit
|
||||||
|
|
||||||
|
@ -141,7 +142,7 @@ def do_change_user_delivery_email(user_profile: UserProfile, new_email: str) ->
|
||||||
realm=user_profile.realm,
|
realm=user_profile.realm,
|
||||||
acting_user=user_profile,
|
acting_user=user_profile,
|
||||||
modified_user=user_profile,
|
modified_user=user_profile,
|
||||||
event_type=RealmAuditLog.USER_EMAIL_CHANGED,
|
event_type=AuditLogEventType.USER_EMAIL_CHANGED,
|
||||||
event_time=event_time,
|
event_time=event_time,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -208,7 +209,7 @@ def do_change_password(user_profile: UserProfile, password: str, commit: bool =
|
||||||
realm=user_profile.realm,
|
realm=user_profile.realm,
|
||||||
acting_user=user_profile,
|
acting_user=user_profile,
|
||||||
modified_user=user_profile,
|
modified_user=user_profile,
|
||||||
event_type=RealmAuditLog.USER_PASSWORD_CHANGED,
|
event_type=AuditLogEventType.USER_PASSWORD_CHANGED,
|
||||||
event_time=event_time,
|
event_time=event_time,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -228,7 +229,7 @@ def do_change_full_name(
|
||||||
realm=user_profile.realm,
|
realm=user_profile.realm,
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
modified_user=user_profile,
|
modified_user=user_profile,
|
||||||
event_type=RealmAuditLog.USER_FULL_NAME_CHANGED,
|
event_type=AuditLogEventType.USER_FULL_NAME_CHANGED,
|
||||||
event_time=event_time,
|
event_time=event_time,
|
||||||
extra_data={RealmAuditLog.OLD_VALUE: old_name, RealmAuditLog.NEW_VALUE: full_name},
|
extra_data={RealmAuditLog.OLD_VALUE: old_name, RealmAuditLog.NEW_VALUE: full_name},
|
||||||
)
|
)
|
||||||
|
@ -290,7 +291,7 @@ def do_change_tos_version(user_profile: UserProfile, tos_version: str | None) ->
|
||||||
realm=user_profile.realm,
|
realm=user_profile.realm,
|
||||||
acting_user=user_profile,
|
acting_user=user_profile,
|
||||||
modified_user=user_profile,
|
modified_user=user_profile,
|
||||||
event_type=RealmAuditLog.USER_TERMS_OF_SERVICE_VERSION_CHANGED,
|
event_type=AuditLogEventType.USER_TERMS_OF_SERVICE_VERSION_CHANGED,
|
||||||
event_time=event_time,
|
event_time=event_time,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -312,7 +313,7 @@ def do_regenerate_api_key(user_profile: UserProfile, acting_user: UserProfile) -
|
||||||
realm=user_profile.realm,
|
realm=user_profile.realm,
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
modified_user=user_profile,
|
modified_user=user_profile,
|
||||||
event_type=RealmAuditLog.USER_API_KEY_CHANGED,
|
event_type=AuditLogEventType.USER_API_KEY_CHANGED,
|
||||||
event_time=event_time,
|
event_time=event_time,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -391,7 +392,7 @@ def do_change_avatar_fields(
|
||||||
RealmAuditLog.objects.create(
|
RealmAuditLog.objects.create(
|
||||||
realm=user_profile.realm,
|
realm=user_profile.realm,
|
||||||
modified_user=user_profile,
|
modified_user=user_profile,
|
||||||
event_type=RealmAuditLog.USER_AVATAR_SOURCE_CHANGED,
|
event_type=AuditLogEventType.USER_AVATAR_SOURCE_CHANGED,
|
||||||
extra_data={"avatar_source": avatar_source},
|
extra_data={"avatar_source": avatar_source},
|
||||||
event_time=event_time,
|
event_time=event_time,
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
|
@ -447,7 +448,7 @@ def do_change_user_setting(
|
||||||
|
|
||||||
RealmAuditLog.objects.create(
|
RealmAuditLog.objects.create(
|
||||||
realm=user_profile.realm,
|
realm=user_profile.realm,
|
||||||
event_type=RealmAuditLog.USER_SETTING_CHANGED,
|
event_type=AuditLogEventType.USER_SETTING_CHANGED,
|
||||||
event_time=event_time,
|
event_time=event_time,
|
||||||
acting_user=acting_user,
|
acting_user=acting_user,
|
||||||
modified_user=user_profile,
|
modified_user=user_profile,
|
||||||
|
|
|
@ -30,6 +30,7 @@ from zerver.models import (
|
||||||
UserActivityInterval,
|
UserActivityInterval,
|
||||||
UserProfile,
|
UserProfile,
|
||||||
)
|
)
|
||||||
|
from zerver.models.realm_audit_logs import AuditLogEventType
|
||||||
from zerver.models.streams import get_active_streams
|
from zerver.models.streams import get_active_streams
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -127,7 +128,7 @@ def _enqueue_emails_for_realm(realm: Realm, cutoff: datetime) -> None:
|
||||||
sent_recent_digest=Exists(
|
sent_recent_digest=Exists(
|
||||||
RealmAuditLog.objects.filter(
|
RealmAuditLog.objects.filter(
|
||||||
realm_id=realm.id,
|
realm_id=realm.id,
|
||||||
event_type=RealmAuditLog.USER_DIGEST_EMAIL_CREATED,
|
event_type=AuditLogEventType.USER_DIGEST_EMAIL_CREATED,
|
||||||
event_time__gt=twelve_hours_ago,
|
event_time__gt=twelve_hours_ago,
|
||||||
modified_user_id=OuterRef("id"),
|
modified_user_id=OuterRef("id"),
|
||||||
)
|
)
|
||||||
|
@ -434,7 +435,7 @@ def bulk_write_realm_audit_logs(users: list[UserProfile]) -> None:
|
||||||
modified_user_id=user.id,
|
modified_user_id=user.id,
|
||||||
event_last_message_id=last_message_id,
|
event_last_message_id=last_message_id,
|
||||||
event_time=now,
|
event_time=now,
|
||||||
event_type=RealmAuditLog.USER_DIGEST_EMAIL_CREATED,
|
event_type=AuditLogEventType.USER_DIGEST_EMAIL_CREATED,
|
||||||
)
|
)
|
||||||
for user in users
|
for user in users
|
||||||
]
|
]
|
||||||
|
|
|
@ -25,6 +25,7 @@ from zerver.models import (
|
||||||
UserMessage,
|
UserMessage,
|
||||||
UserProfile,
|
UserProfile,
|
||||||
)
|
)
|
||||||
|
from zerver.models.realm_audit_logs import AuditLogEventType
|
||||||
from zerver.models.scheduled_jobs import NotificationTriggers
|
from zerver.models.scheduled_jobs import NotificationTriggers
|
||||||
|
|
||||||
logger = logging.getLogger("zulip.soft_deactivation")
|
logger = logging.getLogger("zulip.soft_deactivation")
|
||||||
|
@ -284,7 +285,7 @@ def do_soft_deactivate_users(
|
||||||
log = RealmAuditLog(
|
log = RealmAuditLog(
|
||||||
realm=user.realm,
|
realm=user.realm,
|
||||||
modified_user=user,
|
modified_user=user,
|
||||||
event_type=RealmAuditLog.USER_SOFT_DEACTIVATED,
|
event_type=AuditLogEventType.USER_SOFT_DEACTIVATED,
|
||||||
event_time=event_time,
|
event_time=event_time,
|
||||||
)
|
)
|
||||||
realm_logs.append(log)
|
realm_logs.append(log)
|
||||||
|
@ -324,7 +325,7 @@ def reactivate_user_if_soft_deactivated(user_profile: UserProfile) -> UserProfil
|
||||||
RealmAuditLog.objects.create(
|
RealmAuditLog.objects.create(
|
||||||
realm=user_profile.realm,
|
realm=user_profile.realm,
|
||||||
modified_user=user_profile,
|
modified_user=user_profile,
|
||||||
event_type=RealmAuditLog.USER_SOFT_ACTIVATED,
|
event_type=AuditLogEventType.USER_SOFT_ACTIVATED,
|
||||||
event_time=timezone_now(),
|
event_time=timezone_now(),
|
||||||
)
|
)
|
||||||
logger.info("Soft reactivated user %s", user_profile.id)
|
logger.info("Soft reactivated user %s", user_profile.id)
|
||||||
|
|
|
@ -21,6 +21,21 @@ class AuditLogEventType(IntEnum):
|
||||||
USER_DELETED = 106
|
USER_DELETED = 106
|
||||||
USER_DELETED_PRESERVING_MESSAGES = 107
|
USER_DELETED_PRESERVING_MESSAGES = 107
|
||||||
|
|
||||||
|
USER_SOFT_ACTIVATED = 120
|
||||||
|
USER_SOFT_DEACTIVATED = 121
|
||||||
|
USER_PASSWORD_CHANGED = 122
|
||||||
|
USER_AVATAR_SOURCE_CHANGED = 123
|
||||||
|
USER_FULL_NAME_CHANGED = 124
|
||||||
|
USER_EMAIL_CHANGED = 125
|
||||||
|
USER_TERMS_OF_SERVICE_VERSION_CHANGED = 126
|
||||||
|
USER_API_KEY_CHANGED = 127
|
||||||
|
USER_BOT_OWNER_CHANGED = 128
|
||||||
|
USER_DEFAULT_SENDING_STREAM_CHANGED = 129
|
||||||
|
USER_DEFAULT_REGISTER_STREAM_CHANGED = 130
|
||||||
|
USER_DEFAULT_ALL_PUBLIC_STREAMS_CHANGED = 131
|
||||||
|
USER_SETTING_CHANGED = 132
|
||||||
|
USER_DIGEST_EMAIL_CREATED = 133
|
||||||
|
|
||||||
|
|
||||||
class AbstractRealmAuditLog(models.Model):
|
class AbstractRealmAuditLog(models.Model):
|
||||||
"""Defines fields common to RealmAuditLog and RemoteRealmAuditLog."""
|
"""Defines fields common to RealmAuditLog and RemoteRealmAuditLog."""
|
||||||
|
@ -41,21 +56,6 @@ class AbstractRealmAuditLog(models.Model):
|
||||||
extra_data = models.JSONField(default=dict, encoder=DjangoJSONEncoder)
|
extra_data = models.JSONField(default=dict, encoder=DjangoJSONEncoder)
|
||||||
|
|
||||||
# Event types
|
# Event types
|
||||||
USER_SOFT_ACTIVATED = 120
|
|
||||||
USER_SOFT_DEACTIVATED = 121
|
|
||||||
USER_PASSWORD_CHANGED = 122
|
|
||||||
USER_AVATAR_SOURCE_CHANGED = 123
|
|
||||||
USER_FULL_NAME_CHANGED = 124
|
|
||||||
USER_EMAIL_CHANGED = 125
|
|
||||||
USER_TERMS_OF_SERVICE_VERSION_CHANGED = 126
|
|
||||||
USER_API_KEY_CHANGED = 127
|
|
||||||
USER_BOT_OWNER_CHANGED = 128
|
|
||||||
USER_DEFAULT_SENDING_STREAM_CHANGED = 129
|
|
||||||
USER_DEFAULT_REGISTER_STREAM_CHANGED = 130
|
|
||||||
USER_DEFAULT_ALL_PUBLIC_STREAMS_CHANGED = 131
|
|
||||||
USER_SETTING_CHANGED = 132
|
|
||||||
USER_DIGEST_EMAIL_CREATED = 133
|
|
||||||
|
|
||||||
REALM_DEACTIVATED = 201
|
REALM_DEACTIVATED = 201
|
||||||
REALM_REACTIVATED = 202
|
REALM_REACTIVATED = 202
|
||||||
REALM_SCRUBBED = 203
|
REALM_SCRUBBED = 203
|
||||||
|
|
|
@ -266,7 +266,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
do_change_password(user, password)
|
do_change_password(user, password)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
RealmAuditLog.objects.filter(
|
RealmAuditLog.objects.filter(
|
||||||
event_type=RealmAuditLog.USER_PASSWORD_CHANGED, event_time__gte=now
|
event_type=AuditLogEventType.USER_PASSWORD_CHANGED, event_time__gte=now
|
||||||
).count(),
|
).count(),
|
||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
|
@ -280,7 +280,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
do_change_user_delivery_email(user, new_email)
|
do_change_user_delivery_email(user, new_email)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
RealmAuditLog.objects.filter(
|
RealmAuditLog.objects.filter(
|
||||||
event_type=RealmAuditLog.USER_EMAIL_CHANGED, event_time__gte=now
|
event_type=AuditLogEventType.USER_EMAIL_CHANGED, event_time__gte=now
|
||||||
).count(),
|
).count(),
|
||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
|
@ -288,11 +288,11 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
|
|
||||||
# Test the RealmAuditLog stringification
|
# Test the RealmAuditLog stringification
|
||||||
audit_entry = RealmAuditLog.objects.get(
|
audit_entry = RealmAuditLog.objects.get(
|
||||||
event_type=RealmAuditLog.USER_EMAIL_CHANGED, event_time__gte=now
|
event_type=AuditLogEventType.USER_EMAIL_CHANGED, event_time__gte=now
|
||||||
)
|
)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
repr(audit_entry).startswith(
|
repr(audit_entry).startswith(
|
||||||
f"<RealmAuditLog: <UserProfile: {user.email} {user.realm!r}> {RealmAuditLog.USER_EMAIL_CHANGED} "
|
f"<RealmAuditLog: <UserProfile: {user.email} {user.realm!r}> {AuditLogEventType.USER_EMAIL_CHANGED} "
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -303,7 +303,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
do_change_avatar_fields(user, avatar_source, acting_user=user)
|
do_change_avatar_fields(user, avatar_source, acting_user=user)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
RealmAuditLog.objects.filter(
|
RealmAuditLog.objects.filter(
|
||||||
event_type=RealmAuditLog.USER_AVATAR_SOURCE_CHANGED,
|
event_type=AuditLogEventType.USER_AVATAR_SOURCE_CHANGED,
|
||||||
modified_user=user,
|
modified_user=user,
|
||||||
acting_user=user,
|
acting_user=user,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
|
@ -320,7 +320,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
result = self.client_patch("/json/users/{}".format(self.example_user("hamlet").id), req)
|
result = self.client_patch("/json/users/{}".format(self.example_user("hamlet").id), req)
|
||||||
self.assertTrue(result.status_code == 200)
|
self.assertTrue(result.status_code == 200)
|
||||||
query = RealmAuditLog.objects.filter(
|
query = RealmAuditLog.objects.filter(
|
||||||
event_type=RealmAuditLog.USER_FULL_NAME_CHANGED, event_time__gte=start
|
event_type=AuditLogEventType.USER_FULL_NAME_CHANGED, event_time__gte=start
|
||||||
)
|
)
|
||||||
self.assertEqual(query.count(), 1)
|
self.assertEqual(query.count(), 1)
|
||||||
|
|
||||||
|
@ -331,7 +331,8 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
do_change_tos_version(user, tos_version)
|
do_change_tos_version(user, tos_version)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
RealmAuditLog.objects.filter(
|
RealmAuditLog.objects.filter(
|
||||||
event_type=RealmAuditLog.USER_TERMS_OF_SERVICE_VERSION_CHANGED, event_time__gte=now
|
event_type=AuditLogEventType.USER_TERMS_OF_SERVICE_VERSION_CHANGED,
|
||||||
|
event_time__gte=now,
|
||||||
).count(),
|
).count(),
|
||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
|
@ -345,7 +346,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
do_change_bot_owner(bot, bot_owner, admin)
|
do_change_bot_owner(bot, bot_owner, admin)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
RealmAuditLog.objects.filter(
|
RealmAuditLog.objects.filter(
|
||||||
event_type=RealmAuditLog.USER_BOT_OWNER_CHANGED, event_time__gte=now
|
event_type=AuditLogEventType.USER_BOT_OWNER_CHANGED, event_time__gte=now
|
||||||
).count(),
|
).count(),
|
||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
|
@ -357,7 +358,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
do_regenerate_api_key(user, user)
|
do_regenerate_api_key(user, user)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
RealmAuditLog.objects.filter(
|
RealmAuditLog.objects.filter(
|
||||||
event_type=RealmAuditLog.USER_API_KEY_CHANGED, event_time__gte=now
|
event_type=AuditLogEventType.USER_API_KEY_CHANGED, event_time__gte=now
|
||||||
).count(),
|
).count(),
|
||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
|
@ -706,7 +707,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
RealmAuditLog.objects.filter(
|
RealmAuditLog.objects.filter(
|
||||||
realm=user.realm,
|
realm=user.realm,
|
||||||
event_type=RealmAuditLog.USER_DEFAULT_SENDING_STREAM_CHANGED,
|
event_type=AuditLogEventType.USER_DEFAULT_SENDING_STREAM_CHANGED,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
acting_user=user,
|
acting_user=user,
|
||||||
extra_data={
|
extra_data={
|
||||||
|
@ -723,7 +724,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
RealmAuditLog.objects.filter(
|
RealmAuditLog.objects.filter(
|
||||||
realm=user.realm,
|
realm=user.realm,
|
||||||
event_type=RealmAuditLog.USER_DEFAULT_REGISTER_STREAM_CHANGED,
|
event_type=AuditLogEventType.USER_DEFAULT_REGISTER_STREAM_CHANGED,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
acting_user=user,
|
acting_user=user,
|
||||||
extra_data={
|
extra_data={
|
||||||
|
@ -740,7 +741,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
RealmAuditLog.objects.filter(
|
RealmAuditLog.objects.filter(
|
||||||
realm=user.realm,
|
realm=user.realm,
|
||||||
event_type=RealmAuditLog.USER_DEFAULT_ALL_PUBLIC_STREAMS_CHANGED,
|
event_type=AuditLogEventType.USER_DEFAULT_ALL_PUBLIC_STREAMS_CHANGED,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
acting_user=user,
|
acting_user=user,
|
||||||
extra_data={RealmAuditLog.OLD_VALUE: old_value, RealmAuditLog.NEW_VALUE: False},
|
extra_data={RealmAuditLog.OLD_VALUE: old_value, RealmAuditLog.NEW_VALUE: False},
|
||||||
|
@ -801,7 +802,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
RealmAuditLog.objects.filter(
|
RealmAuditLog.objects.filter(
|
||||||
realm=user.realm,
|
realm=user.realm,
|
||||||
event_type=RealmAuditLog.USER_SETTING_CHANGED,
|
event_type=AuditLogEventType.USER_SETTING_CHANGED,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
acting_user=user,
|
acting_user=user,
|
||||||
modified_user=user,
|
modified_user=user,
|
||||||
|
|
|
@ -26,6 +26,7 @@ from zerver.lib.message import get_last_message_id
|
||||||
from zerver.lib.streams import create_stream_if_needed
|
from zerver.lib.streams import create_stream_if_needed
|
||||||
from zerver.lib.test_classes import ZulipTestCase
|
from zerver.lib.test_classes import ZulipTestCase
|
||||||
from zerver.models import Message, Realm, RealmAuditLog, Stream, UserActivityInterval, UserProfile
|
from zerver.models import Message, Realm, RealmAuditLog, Stream, UserActivityInterval, UserProfile
|
||||||
|
from zerver.models.realm_audit_logs import AuditLogEventType
|
||||||
from zerver.models.realms import get_realm
|
from zerver.models.realms import get_realm
|
||||||
from zerver.models.streams import get_stream
|
from zerver.models.streams import get_stream
|
||||||
|
|
||||||
|
@ -266,7 +267,7 @@ class TestDigestEmailMessages(ZulipTestCase):
|
||||||
for digest_user in digest_users:
|
for digest_user in digest_users:
|
||||||
log_rows = RealmAuditLog.objects.filter(
|
log_rows = RealmAuditLog.objects.filter(
|
||||||
modified_user_id=digest_user.id,
|
modified_user_id=digest_user.id,
|
||||||
event_type=RealmAuditLog.USER_DIGEST_EMAIL_CREATED,
|
event_type=AuditLogEventType.USER_DIGEST_EMAIL_CREATED,
|
||||||
)
|
)
|
||||||
(log,) = log_rows
|
(log,) = log_rows
|
||||||
self.assertEqual(log.event_last_message_id, last_message_id)
|
self.assertEqual(log.event_last_message_id, last_message_id)
|
||||||
|
|
|
@ -248,6 +248,7 @@ from zerver.models import (
|
||||||
)
|
)
|
||||||
from zerver.models.clients import get_client
|
from zerver.models.clients import get_client
|
||||||
from zerver.models.groups import SystemGroups
|
from zerver.models.groups import SystemGroups
|
||||||
|
from zerver.models.realm_audit_logs import AuditLogEventType
|
||||||
from zerver.models.streams import get_stream
|
from zerver.models.streams import get_stream
|
||||||
from zerver.models.users import get_user_by_delivery_email
|
from zerver.models.users import get_user_by_delivery_email
|
||||||
from zerver.openapi.openapi import validate_against_openapi_schema
|
from zerver.openapi.openapi import validate_against_openapi_schema
|
||||||
|
@ -2088,7 +2089,7 @@ class NormalActionsTest(BaseAction):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
RealmAuditLog.objects.filter(
|
RealmAuditLog.objects.filter(
|
||||||
realm=self.user_profile.realm,
|
realm=self.user_profile.realm,
|
||||||
event_type=RealmAuditLog.USER_FULL_NAME_CHANGED,
|
event_type=AuditLogEventType.USER_FULL_NAME_CHANGED,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
acting_user=self.user_profile,
|
acting_user=self.user_profile,
|
||||||
).count(),
|
).count(),
|
||||||
|
@ -2101,7 +2102,7 @@ class NormalActionsTest(BaseAction):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
RealmAuditLog.objects.filter(
|
RealmAuditLog.objects.filter(
|
||||||
realm=self.user_profile.realm,
|
realm=self.user_profile.realm,
|
||||||
event_type=RealmAuditLog.USER_FULL_NAME_CHANGED,
|
event_type=AuditLogEventType.USER_FULL_NAME_CHANGED,
|
||||||
event_time__gte=now,
|
event_time__gte=now,
|
||||||
acting_user=self.user_profile,
|
acting_user=self.user_profile,
|
||||||
).count(),
|
).count(),
|
||||||
|
|
|
@ -29,6 +29,7 @@ from zerver.models import (
|
||||||
UserMessage,
|
UserMessage,
|
||||||
UserProfile,
|
UserProfile,
|
||||||
)
|
)
|
||||||
|
from zerver.models.realm_audit_logs import AuditLogEventType
|
||||||
from zerver.models.realms import get_realm
|
from zerver.models.realms import get_realm
|
||||||
from zerver.models.streams import get_stream
|
from zerver.models.streams import get_stream
|
||||||
|
|
||||||
|
@ -328,7 +329,7 @@ class SoftDeactivationMessageTest(ZulipTestCase):
|
||||||
reactivate_user_if_soft_deactivated(long_term_idle_user)
|
reactivate_user_if_soft_deactivated(long_term_idle_user)
|
||||||
self.assertFalse(long_term_idle_user.long_term_idle)
|
self.assertFalse(long_term_idle_user.long_term_idle)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
last_realm_audit_log_entry(RealmAuditLog.USER_SOFT_ACTIVATED).modified_user,
|
last_realm_audit_log_entry(AuditLogEventType.USER_SOFT_ACTIVATED).modified_user,
|
||||||
long_term_idle_user,
|
long_term_idle_user,
|
||||||
)
|
)
|
||||||
idle_user_msg_list = get_user_messages(long_term_idle_user)
|
idle_user_msg_list = get_user_messages(long_term_idle_user)
|
||||||
|
|
Loading…
Reference in New Issue