Skip to content

Commit 473e4db

Browse files
committed
user settings fixes
1 parent 8f00ede commit 473e4db

File tree

14 files changed

+364
-367
lines changed

14 files changed

+364
-367
lines changed

backend/app/domain/enums/events.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ class EventType(StringEnum):
3434

3535
# User settings events
3636
USER_SETTINGS_UPDATED = "user_settings_updated"
37-
USER_THEME_CHANGED = "user_theme_changed"
38-
USER_NOTIFICATION_SETTINGS_UPDATED = "user_notification_settings_updated"
39-
USER_EDITOR_SETTINGS_UPDATED = "user_editor_settings_updated"
4037

4138
# Notification events
4239
NOTIFICATION_CREATED = "notification_created"

backend/app/domain/enums/kafka.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ class KafkaTopic(StringEnum):
2727
USER_EVENTS = "user_events"
2828
USER_NOTIFICATIONS = "user_notifications"
2929
USER_SETTINGS_EVENTS = "user_settings_events"
30-
USER_SETTINGS_THEME_EVENTS = "user_settings_theme_events"
31-
USER_SETTINGS_NOTIFICATION_EVENTS = "user_settings_notification_events"
32-
USER_SETTINGS_EDITOR_EVENTS = "user_settings_editor_events"
3330

3431
# Script topics
3532
SCRIPT_EVENTS = "script_events"

backend/app/infrastructure/kafka/events/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,10 @@
5757
)
5858
from app.infrastructure.kafka.events.user import (
5959
UserDeletedEvent,
60-
UserEditorSettingsUpdatedEvent,
6160
UserLoggedInEvent,
6261
UserLoggedOutEvent,
63-
UserNotificationSettingsUpdatedEvent,
6462
UserRegisteredEvent,
6563
UserSettingsUpdatedEvent,
66-
UserThemeChangedEvent,
6764
UserUpdatedEvent,
6865
)
6966

@@ -96,9 +93,6 @@
9693
"UserUpdatedEvent",
9794
"UserDeletedEvent",
9895
"UserSettingsUpdatedEvent",
99-
"UserThemeChangedEvent",
100-
"UserNotificationSettingsUpdatedEvent",
101-
"UserEditorSettingsUpdatedEvent",
10296
# Notification
10397
"NotificationCreatedEvent",
10498
"NotificationSentEvent",

backend/app/infrastructure/kafka/events/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from uuid import uuid4
44

55
from pydantic import ConfigDict, Field, field_serializer
6-
from pydantic_avro import AvroBase # type: ignore[attr-defined]
6+
from pydantic_avro.to_avro.base import AvroBase
77

88
from app.domain.enums.events import EventType
99
from app.domain.enums.kafka import KafkaTopic

backend/app/infrastructure/kafka/events/user.py

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
11
from typing import ClassVar, Literal
22

3-
from app.domain.enums.auth import LoginMethod, SettingsType
3+
from pydantic_avro.to_avro.base import AvroBase
4+
5+
from app.domain.enums.auth import LoginMethod
46
from app.domain.enums.events import EventType
57
from app.domain.enums.kafka import KafkaTopic
68
from app.infrastructure.kafka.events.base import BaseEvent
79

810

11+
class NotificationSettingsPayload(AvroBase):
12+
"""Avro-compatible payload for notification settings changes."""
13+
14+
execution_completed: bool | None = None
15+
execution_failed: bool | None = None
16+
system_updates: bool | None = None
17+
security_alerts: bool | None = None
18+
channels: list[str] | None = None
19+
20+
21+
class EditorSettingsPayload(AvroBase):
22+
"""Avro-compatible payload for editor settings changes."""
23+
24+
theme: str | None = None
25+
font_size: int | None = None
26+
tab_size: int | None = None
27+
use_tabs: bool | None = None
28+
word_wrap: bool | None = None
29+
show_line_numbers: bool | None = None
30+
31+
932
class UserRegisteredEvent(BaseEvent):
1033
event_type: Literal[EventType.USER_REGISTERED] = EventType.USER_REGISTERED
1134
topic: ClassVar[KafkaTopic] = KafkaTopic.USER_EVENTS
@@ -47,31 +70,17 @@ class UserDeletedEvent(BaseEvent):
4770

4871

4972
class UserSettingsUpdatedEvent(BaseEvent):
73+
"""Unified event for all user settings changes with typed payloads."""
74+
5075
event_type: Literal[EventType.USER_SETTINGS_UPDATED] = EventType.USER_SETTINGS_UPDATED
5176
topic: ClassVar[KafkaTopic] = KafkaTopic.USER_SETTINGS_EVENTS
5277
user_id: str
53-
settings_type: SettingsType
54-
updated: dict[str, str]
55-
56-
57-
class UserThemeChangedEvent(BaseEvent):
58-
event_type: Literal[EventType.USER_THEME_CHANGED] = EventType.USER_THEME_CHANGED
59-
topic: ClassVar[KafkaTopic] = KafkaTopic.USER_SETTINGS_THEME_EVENTS
60-
user_id: str
61-
old_theme: str
62-
new_theme: str
63-
64-
65-
class UserNotificationSettingsUpdatedEvent(BaseEvent):
66-
event_type: Literal[EventType.USER_NOTIFICATION_SETTINGS_UPDATED] = EventType.USER_NOTIFICATION_SETTINGS_UPDATED
67-
topic: ClassVar[KafkaTopic] = KafkaTopic.USER_SETTINGS_NOTIFICATION_EVENTS
68-
user_id: str
69-
settings: dict[str, bool]
70-
channels: list[str] | None = None
71-
72-
73-
class UserEditorSettingsUpdatedEvent(BaseEvent):
74-
event_type: Literal[EventType.USER_EDITOR_SETTINGS_UPDATED] = EventType.USER_EDITOR_SETTINGS_UPDATED
75-
topic: ClassVar[KafkaTopic] = KafkaTopic.USER_SETTINGS_EDITOR_EVENTS
76-
user_id: str
77-
settings: dict[str, str | int | bool]
78+
changed_fields: list[str]
79+
# Typed fields for each settings category (Avro-compatible)
80+
theme: str | None = None
81+
timezone: str | None = None
82+
date_format: str | None = None
83+
time_format: str | None = None
84+
notifications: NotificationSettingsPayload | None = None
85+
editor: EditorSettingsPayload | None = None
86+
reason: str | None = None

backend/app/infrastructure/kafka/mappings.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,10 @@
6060
)
6161
from app.infrastructure.kafka.events.user import (
6262
UserDeletedEvent,
63-
UserEditorSettingsUpdatedEvent,
6463
UserLoggedInEvent,
6564
UserLoggedOutEvent,
66-
UserNotificationSettingsUpdatedEvent,
6765
UserRegisteredEvent,
6866
UserSettingsUpdatedEvent,
69-
UserThemeChangedEvent,
7067
UserUpdatedEvent,
7168
)
7269

@@ -99,9 +96,6 @@ def get_event_class_for_type(event_type: EventType) -> Type[BaseEvent] | None:
9996
EventType.USER_UPDATED: UserUpdatedEvent,
10097
EventType.USER_DELETED: UserDeletedEvent,
10198
EventType.USER_SETTINGS_UPDATED: UserSettingsUpdatedEvent,
102-
EventType.USER_THEME_CHANGED: UserThemeChangedEvent,
103-
EventType.USER_NOTIFICATION_SETTINGS_UPDATED: UserNotificationSettingsUpdatedEvent,
104-
EventType.USER_EDITOR_SETTINGS_UPDATED: UserEditorSettingsUpdatedEvent,
10599
# Notification events
106100
EventType.NOTIFICATION_CREATED: NotificationCreatedEvent,
107101
EventType.NOTIFICATION_SENT: NotificationSentEvent,

backend/app/infrastructure/kafka/topics.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -127,30 +127,6 @@ def get_topic_configs() -> dict[KafkaTopic, dict[str, Any]]:
127127
"compression.type": "gzip",
128128
},
129129
},
130-
KafkaTopic.USER_SETTINGS_THEME_EVENTS: {
131-
"num_partitions": 3,
132-
"replication_factor": 1,
133-
"config": {
134-
"retention.ms": "2592000000", # 30 days
135-
"compression.type": "gzip",
136-
},
137-
},
138-
KafkaTopic.USER_SETTINGS_NOTIFICATION_EVENTS: {
139-
"num_partitions": 3,
140-
"replication_factor": 1,
141-
"config": {
142-
"retention.ms": "2592000000", # 30 days
143-
"compression.type": "gzip",
144-
},
145-
},
146-
KafkaTopic.USER_SETTINGS_EDITOR_EVENTS: {
147-
"num_partitions": 3,
148-
"replication_factor": 1,
149-
"config": {
150-
"retention.ms": "2592000000", # 30 days
151-
"compression.type": "gzip",
152-
},
153-
},
154130
# Script topics
155131
KafkaTopic.SCRIPT_EVENTS: {
156132
"num_partitions": 3,

0 commit comments

Comments
 (0)