diff --git a/.gitignore b/.gitignore index 3c2dd46..ebd5341 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,7 @@ media /delme.py /log/accounts.log /log/errors.log -__pycache__ +**/__pycache__ +**/*.pyc +**/*.pyo .claude \ No newline at end of file diff --git a/apps/chat/__pycache__/__init__.cpython-313.pyc b/apps/chat/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index 9c11b90..0000000 Binary files a/apps/chat/__pycache__/__init__.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/__pycache__/admin.cpython-313.pyc b/apps/chat/__pycache__/admin.cpython-313.pyc deleted file mode 100644 index 01007d7..0000000 Binary files a/apps/chat/__pycache__/admin.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/__pycache__/apps.cpython-313.pyc b/apps/chat/__pycache__/apps.cpython-313.pyc deleted file mode 100644 index f270aaf..0000000 Binary files a/apps/chat/__pycache__/apps.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/__pycache__/urls.cpython-313.pyc b/apps/chat/__pycache__/urls.cpython-313.pyc deleted file mode 100644 index dee0d90..0000000 Binary files a/apps/chat/__pycache__/urls.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/events/__pycache__/__init__.cpython-313.pyc b/apps/chat/events/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index fb5fe1e..0000000 Binary files a/apps/chat/events/__pycache__/__init__.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/events/__pycache__/event.cpython-313.pyc b/apps/chat/events/__pycache__/event.cpython-313.pyc deleted file mode 100644 index 720cc71..0000000 Binary files a/apps/chat/events/__pycache__/event.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/events/publishers/__pycache__/__init__.cpython-313.pyc b/apps/chat/events/publishers/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index f2aa4a8..0000000 Binary files a/apps/chat/events/publishers/__pycache__/__init__.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/events/publishers/__pycache__/longpoll.cpython-313.pyc b/apps/chat/events/publishers/__pycache__/longpoll.cpython-313.pyc deleted file mode 100644 index 7c86df2..0000000 Binary files a/apps/chat/events/publishers/__pycache__/longpoll.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/events/publishers/__pycache__/push.cpython-313.pyc b/apps/chat/events/publishers/__pycache__/push.cpython-313.pyc deleted file mode 100644 index 759cca1..0000000 Binary files a/apps/chat/events/publishers/__pycache__/push.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/events/publishers/__pycache__/websocket.cpython-313.pyc b/apps/chat/events/publishers/__pycache__/websocket.cpython-313.pyc deleted file mode 100644 index 89ddeee..0000000 Binary files a/apps/chat/events/publishers/__pycache__/websocket.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/integrations/__pycache__/__init__.cpython-313.pyc b/apps/chat/integrations/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index 067b0fd..0000000 Binary files a/apps/chat/integrations/__pycache__/__init__.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/integrations/mattermost/__pycache__/__init__.cpython-313.pyc b/apps/chat/integrations/mattermost/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index 70fc240..0000000 Binary files a/apps/chat/integrations/mattermost/__pycache__/__init__.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/integrations/mattermost/__pycache__/client.cpython-313.pyc b/apps/chat/integrations/mattermost/__pycache__/client.cpython-313.pyc deleted file mode 100644 index 7b0176a..0000000 Binary files a/apps/chat/integrations/mattermost/__pycache__/client.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/integrations/mattermost/__pycache__/exceptions.cpython-313.pyc b/apps/chat/integrations/mattermost/__pycache__/exceptions.cpython-313.pyc deleted file mode 100644 index efcff15..0000000 Binary files a/apps/chat/integrations/mattermost/__pycache__/exceptions.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/integrations/mattermost/client.py b/apps/chat/integrations/mattermost/client.py index b006ff9..659a5ed 100644 --- a/apps/chat/integrations/mattermost/client.py +++ b/apps/chat/integrations/mattermost/client.py @@ -46,6 +46,7 @@ class MattermostClient: "debug": False, } ) + self._driver.login() # ------------------------------------------------------------------ # Internal helpers — username and email are deterministic from UUID @@ -68,6 +69,16 @@ class MattermostClient: # with identifying fields surfaced beyond this layer. # ------------------------------------------------------------------ + def _ensure_team_member(self, mm_user_id: str) -> None: + if not self._team_id: + return + try: + self._driver.teams.add_user_to_team( + self._team_id, options={"team_id": self._team_id, "user_id": mm_user_id} + ) + except Exception: + pass # already a member or team not configured — not fatal + def get_or_create_user(self, user_id: UUID) -> str: """ Ensure a Mattermost account exists for the given external UUID. @@ -77,7 +88,9 @@ class MattermostClient: try: user = self._driver.users.get_user_by_username(username) - return user["id"] + mm_user_id = user["id"] + self._ensure_team_member(mm_user_id) + return mm_user_id except ResourceNotFound: pass except Exception as exc: @@ -91,13 +104,17 @@ class MattermostClient: "password": self._random_password(), } ) - return user["id"] + mm_user_id = user["id"] + self._ensure_team_member(mm_user_id) + return mm_user_id except Exception as exc: # Guard against a concurrent request having created the account # between our lookup and our create attempt. try: user = self._driver.users.get_user_by_username(username) - return user["id"] + mm_user_id = user["id"] + self._ensure_team_member(mm_user_id) + return mm_user_id except Exception: pass raise MattermostError(f"User creation failed: {exc}") from exc diff --git a/apps/chat/migrations/__pycache__/__init__.cpython-313.pyc b/apps/chat/migrations/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index 3d079a8..0000000 Binary files a/apps/chat/migrations/__pycache__/__init__.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/models/__pycache__/__init__.cpython-313.pyc b/apps/chat/models/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index 6c62aef..0000000 Binary files a/apps/chat/models/__pycache__/__init__.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/models/__pycache__/conversation.cpython-313.pyc b/apps/chat/models/__pycache__/conversation.cpython-313.pyc deleted file mode 100644 index 09d1e62..0000000 Binary files a/apps/chat/models/__pycache__/conversation.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/models/__pycache__/mapping.cpython-313.pyc b/apps/chat/models/__pycache__/mapping.cpython-313.pyc deleted file mode 100644 index 5f50251..0000000 Binary files a/apps/chat/models/__pycache__/mapping.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/models/__pycache__/participant.cpython-313.pyc b/apps/chat/models/__pycache__/participant.cpython-313.pyc deleted file mode 100644 index b462e3c..0000000 Binary files a/apps/chat/models/__pycache__/participant.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/models/__pycache__/read_state.cpython-313.pyc b/apps/chat/models/__pycache__/read_state.cpython-313.pyc deleted file mode 100644 index ae8558f..0000000 Binary files a/apps/chat/models/__pycache__/read_state.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/serializers/__pycache__/__init__.cpython-313.pyc b/apps/chat/serializers/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index 830c432..0000000 Binary files a/apps/chat/serializers/__pycache__/__init__.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/serializers/__pycache__/conversations.cpython-313.pyc b/apps/chat/serializers/__pycache__/conversations.cpython-313.pyc deleted file mode 100644 index c3704c9..0000000 Binary files a/apps/chat/serializers/__pycache__/conversations.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/serializers/__pycache__/messages.cpython-313.pyc b/apps/chat/serializers/__pycache__/messages.cpython-313.pyc deleted file mode 100644 index 5a92a57..0000000 Binary files a/apps/chat/serializers/__pycache__/messages.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/serializers/__pycache__/read_state.cpython-313.pyc b/apps/chat/serializers/__pycache__/read_state.cpython-313.pyc deleted file mode 100644 index 411c7f1..0000000 Binary files a/apps/chat/serializers/__pycache__/read_state.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/services/__pycache__/__init__.cpython-313.pyc b/apps/chat/services/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index d2d6c02..0000000 Binary files a/apps/chat/services/__pycache__/__init__.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/services/__pycache__/account.cpython-313.pyc b/apps/chat/services/__pycache__/account.cpython-313.pyc deleted file mode 100644 index d1830d0..0000000 Binary files a/apps/chat/services/__pycache__/account.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/services/__pycache__/conversation.cpython-313.pyc b/apps/chat/services/__pycache__/conversation.cpython-313.pyc deleted file mode 100644 index bb0f29d..0000000 Binary files a/apps/chat/services/__pycache__/conversation.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/services/__pycache__/message.cpython-313.pyc b/apps/chat/services/__pycache__/message.cpython-313.pyc deleted file mode 100644 index 834ec21..0000000 Binary files a/apps/chat/services/__pycache__/message.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/services/__pycache__/read_state.cpython-313.pyc b/apps/chat/services/__pycache__/read_state.cpython-313.pyc deleted file mode 100644 index 8d142d8..0000000 Binary files a/apps/chat/services/__pycache__/read_state.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/services/__pycache__/storage.cpython-313.pyc b/apps/chat/services/__pycache__/storage.cpython-313.pyc deleted file mode 100644 index 1cde293..0000000 Binary files a/apps/chat/services/__pycache__/storage.cpython-313.pyc and /dev/null differ diff --git a/apps/chat/services/message.py b/apps/chat/services/message.py index e62fce2..947c477 100644 --- a/apps/chat/services/message.py +++ b/apps/chat/services/message.py @@ -20,7 +20,7 @@ class MessageService: publishers: list | None = None, ): self._account = account_service or AccountService() - self._storage = storage_service or StorageService() + self._storage_override = storage_service # lazy: only instantiate when needed self._mm = mattermost_client or MattermostClient() self._publishers = ( publishers @@ -28,6 +28,12 @@ class MessageService: else [WebSocketPublisher(), PushPublisher(), LongPollPublisher()] ) + @property + def _storage(self) -> StorageService: + if self._storage_override is None: + self._storage_override = StorageService() + return self._storage_override + def send( self, conversation_id, diff --git a/apps/core/__pycache__/__init__.cpython-313.pyc b/apps/core/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index 461e6fe..0000000 Binary files a/apps/core/__pycache__/__init__.cpython-313.pyc and /dev/null differ diff --git a/apps/core/__pycache__/admin.cpython-313.pyc b/apps/core/__pycache__/admin.cpython-313.pyc deleted file mode 100644 index a0add47..0000000 Binary files a/apps/core/__pycache__/admin.cpython-313.pyc and /dev/null differ diff --git a/apps/core/__pycache__/apps.cpython-313.pyc b/apps/core/__pycache__/apps.cpython-313.pyc deleted file mode 100644 index fbf0a81..0000000 Binary files a/apps/core/__pycache__/apps.cpython-313.pyc and /dev/null differ diff --git a/apps/core/__pycache__/models.cpython-313.pyc b/apps/core/__pycache__/models.cpython-313.pyc deleted file mode 100644 index b367e7a..0000000 Binary files a/apps/core/__pycache__/models.cpython-313.pyc and /dev/null differ diff --git a/apps/core/migrations/__pycache__/0001_initial.cpython-313.pyc b/apps/core/migrations/__pycache__/0001_initial.cpython-313.pyc deleted file mode 100644 index 6b44a36..0000000 Binary files a/apps/core/migrations/__pycache__/0001_initial.cpython-313.pyc and /dev/null differ diff --git a/apps/core/migrations/__pycache__/__init__.cpython-313.pyc b/apps/core/migrations/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index d0d40d2..0000000 Binary files a/apps/core/migrations/__pycache__/__init__.cpython-313.pyc and /dev/null differ diff --git a/apps/gooyal_oauth2/__pycache__/__init__.cpython-313.pyc b/apps/gooyal_oauth2/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index 09157ec..0000000 Binary files a/apps/gooyal_oauth2/__pycache__/__init__.cpython-313.pyc and /dev/null differ diff --git a/apps/gooyal_oauth2/__pycache__/admin.cpython-313.pyc b/apps/gooyal_oauth2/__pycache__/admin.cpython-313.pyc deleted file mode 100644 index be781c9..0000000 Binary files a/apps/gooyal_oauth2/__pycache__/admin.cpython-313.pyc and /dev/null differ diff --git a/apps/gooyal_oauth2/__pycache__/apps.cpython-313.pyc b/apps/gooyal_oauth2/__pycache__/apps.cpython-313.pyc deleted file mode 100644 index 12ea8e5..0000000 Binary files a/apps/gooyal_oauth2/__pycache__/apps.cpython-313.pyc and /dev/null differ diff --git a/apps/gooyal_oauth2/__pycache__/models.cpython-313.pyc b/apps/gooyal_oauth2/__pycache__/models.cpython-313.pyc deleted file mode 100644 index 14076dd..0000000 Binary files a/apps/gooyal_oauth2/__pycache__/models.cpython-313.pyc and /dev/null differ diff --git a/apps/gooyal_oauth2/migrations/__pycache__/0001_initial.cpython-313.pyc b/apps/gooyal_oauth2/migrations/__pycache__/0001_initial.cpython-313.pyc deleted file mode 100644 index 35bb56f..0000000 Binary files a/apps/gooyal_oauth2/migrations/__pycache__/0001_initial.cpython-313.pyc and /dev/null differ diff --git a/apps/gooyal_oauth2/migrations/__pycache__/0002_initial.cpython-313.pyc b/apps/gooyal_oauth2/migrations/__pycache__/0002_initial.cpython-313.pyc deleted file mode 100644 index cedc8f4..0000000 Binary files a/apps/gooyal_oauth2/migrations/__pycache__/0002_initial.cpython-313.pyc and /dev/null differ diff --git a/apps/gooyal_oauth2/migrations/__pycache__/0003_alter_application_authorization_grant_type.cpython-313.pyc b/apps/gooyal_oauth2/migrations/__pycache__/0003_alter_application_authorization_grant_type.cpython-313.pyc deleted file mode 100644 index ae77f92..0000000 Binary files a/apps/gooyal_oauth2/migrations/__pycache__/0003_alter_application_authorization_grant_type.cpython-313.pyc and /dev/null differ diff --git a/apps/gooyal_oauth2/migrations/__pycache__/__init__.cpython-313.pyc b/apps/gooyal_oauth2/migrations/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index 2cf833f..0000000 Binary files a/apps/gooyal_oauth2/migrations/__pycache__/__init__.cpython-313.pyc and /dev/null differ diff --git a/apps/users/__pycache__/__init__.cpython-313.pyc b/apps/users/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index a353a97..0000000 Binary files a/apps/users/__pycache__/__init__.cpython-313.pyc and /dev/null differ diff --git a/apps/users/__pycache__/admin.cpython-313.pyc b/apps/users/__pycache__/admin.cpython-313.pyc deleted file mode 100644 index ad9d3ce..0000000 Binary files a/apps/users/__pycache__/admin.cpython-313.pyc and /dev/null differ diff --git a/apps/users/__pycache__/apps.cpython-313.pyc b/apps/users/__pycache__/apps.cpython-313.pyc deleted file mode 100644 index 0070092..0000000 Binary files a/apps/users/__pycache__/apps.cpython-313.pyc and /dev/null differ diff --git a/apps/users/__pycache__/models.cpython-313.pyc b/apps/users/__pycache__/models.cpython-313.pyc deleted file mode 100644 index 1616f7f..0000000 Binary files a/apps/users/__pycache__/models.cpython-313.pyc and /dev/null differ diff --git a/apps/users/migrations/__pycache__/0001_initial.cpython-313.pyc b/apps/users/migrations/__pycache__/0001_initial.cpython-313.pyc deleted file mode 100644 index b1eb08b..0000000 Binary files a/apps/users/migrations/__pycache__/0001_initial.cpython-313.pyc and /dev/null differ diff --git a/apps/users/migrations/__pycache__/__init__.cpython-313.pyc b/apps/users/migrations/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index d0cbd8b..0000000 Binary files a/apps/users/migrations/__pycache__/__init__.cpython-313.pyc and /dev/null differ diff --git a/main/__pycache__/__init__.cpython-313.pyc b/main/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index fbaf534..0000000 Binary files a/main/__pycache__/__init__.cpython-313.pyc and /dev/null differ diff --git a/main/__pycache__/settings.cpython-313.pyc b/main/__pycache__/settings.cpython-313.pyc deleted file mode 100644 index 0f64b4f..0000000 Binary files a/main/__pycache__/settings.cpython-313.pyc and /dev/null differ diff --git a/main/__pycache__/urls.cpython-313.pyc b/main/__pycache__/urls.cpython-313.pyc deleted file mode 100644 index d983bd6..0000000 Binary files a/main/__pycache__/urls.cpython-313.pyc and /dev/null differ diff --git a/main/other_settings/__pycache__/__init__.cpython-313.pyc b/main/other_settings/__pycache__/__init__.cpython-313.pyc deleted file mode 100644 index b79ae16..0000000 Binary files a/main/other_settings/__pycache__/__init__.cpython-313.pyc and /dev/null differ diff --git a/main/other_settings/__pycache__/logging.cpython-313.pyc b/main/other_settings/__pycache__/logging.cpython-313.pyc deleted file mode 100644 index a67518b..0000000 Binary files a/main/other_settings/__pycache__/logging.cpython-313.pyc and /dev/null differ diff --git a/utils/__pycache__/exceptions.cpython-313.pyc b/utils/__pycache__/exceptions.cpython-313.pyc deleted file mode 100644 index 6a7b16a..0000000 Binary files a/utils/__pycache__/exceptions.cpython-313.pyc and /dev/null differ