feature/refactor_uuid #1
59 changed files with 30 additions and 5 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -5,5 +5,7 @@ media
|
|||
/delme.py
|
||||
/log/accounts.log
|
||||
/log/errors.log
|
||||
__pycache__
|
||||
**/__pycache__
|
||||
**/*.pyc
|
||||
**/*.pyo
|
||||
.claude
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -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
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -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,
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Add table
Reference in a new issue