UUID refactoring: remove slug from JWT, mentions stored as IDs, WS filtering by member_id only
Some checks failed
Deploy Tracker / deploy (push) Failing after 4s
Some checks failed
Deploy Tracker / deploy (push) Failing after 4s
This commit is contained in:
parent
5030c06d76
commit
f7622e13d5
@ -34,10 +34,9 @@ def verify_password(password: str, hashed: str) -> bool:
|
|||||||
return hashlib.sha256(password.encode()).hexdigest() == hashed
|
return hashlib.sha256(password.encode()).hexdigest() == hashed
|
||||||
|
|
||||||
|
|
||||||
def create_jwt(member_id: str, slug: str, role: str) -> str:
|
def create_jwt(member_id: str, role: str) -> str:
|
||||||
payload = {
|
payload = {
|
||||||
"sub": str(member_id),
|
"sub": str(member_id),
|
||||||
"slug": slug,
|
|
||||||
"role": role,
|
"role": role,
|
||||||
"exp": datetime.now(timezone.utc) + timedelta(hours=JWT_EXPIRE_HOURS),
|
"exp": datetime.now(timezone.utc) + timedelta(hours=JWT_EXPIRE_HOURS),
|
||||||
}
|
}
|
||||||
@ -111,7 +110,7 @@ async def login(req: LoginRequest, db: AsyncSession = Depends(get_db)):
|
|||||||
member.password_hash = hash_password(req.password)
|
member.password_hash = hash_password(req.password)
|
||||||
await db.commit()
|
await db.commit()
|
||||||
|
|
||||||
token = create_jwt(str(member.id), member.slug, member.role)
|
token = create_jwt(str(member.id), member.role)
|
||||||
return LoginResponse(
|
return LoginResponse(
|
||||||
token=token,
|
token=token,
|
||||||
member_id=str(member.id),
|
member_id=str(member.id),
|
||||||
|
|||||||
@ -109,8 +109,8 @@ async def _system_message(
|
|||||||
actor_slug = actor.slug if actor else "system"
|
actor_slug = actor.slug if actor else "system"
|
||||||
actor_brief = MemberBrief(id=str(actor.id), slug=actor.slug, name=actor.name) if actor else None
|
actor_brief = MemberBrief(id=str(actor.id), slug=actor.slug, name=actor.name) if actor else None
|
||||||
|
|
||||||
# Mentioned members as slugs (DB storage) and briefs (broadcast)
|
# Mentioned members as IDs (DB storage) and briefs (broadcast)
|
||||||
mention_slugs = [m.slug for m in (mentioned_members or [])]
|
mention_ids = [str(m.id) for m in (mentioned_members or [])]
|
||||||
mention_briefs = [MemberBrief(id=str(m.id), slug=m.slug, name=m.name) for m in (mentioned_members or [])]
|
mention_briefs = [MemberBrief(id=str(m.id), slug=m.slug, name=m.name) for m in (mentioned_members or [])]
|
||||||
|
|
||||||
chat_id = await _get_project_chat_id(db, task.project_id)
|
chat_id = await _get_project_chat_id(db, task.project_id)
|
||||||
@ -122,7 +122,7 @@ async def _system_message(
|
|||||||
author_id=None,
|
author_id=None,
|
||||||
actor_id=actor.id if actor else None,
|
actor_id=actor.id if actor else None,
|
||||||
content=task_text,
|
content=task_text,
|
||||||
mentions=mention_slugs, # still stored as slugs in DB for compat
|
mentions=mention_ids, # still stored as slugs in DB for compat
|
||||||
)
|
)
|
||||||
db.add(task_msg)
|
db.add(task_msg)
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ async def _system_message(
|
|||||||
author_id=None,
|
author_id=None,
|
||||||
actor_id=actor.id if actor else None,
|
actor_id=actor.id if actor else None,
|
||||||
content=chat_text,
|
content=chat_text,
|
||||||
mentions=mention_slugs,
|
mentions=mention_ids,
|
||||||
)
|
)
|
||||||
db.add(chat_msg)
|
db.add(chat_msg)
|
||||||
|
|
||||||
|
|||||||
@ -31,7 +31,8 @@ def _to_member_brief(member: Member) -> MemberBrief:
|
|||||||
|
|
||||||
|
|
||||||
def _to_message_out(msg: Message, author: Member | None = None) -> MessageOut:
|
def _to_message_out(msg: Message, author: Member | None = None) -> MessageOut:
|
||||||
mention_briefs = [MemberBrief(id="", slug=s, name=s) for s in (msg.mentions or [])]
|
# mentions stored as member IDs in DB
|
||||||
|
mention_briefs = [MemberBrief(id=mid, slug="", name="") for mid in (msg.mentions or [])]
|
||||||
return MessageOut(
|
return MessageOut(
|
||||||
id=str(msg.id),
|
id=str(msg.id),
|
||||||
chat_id=str(msg.chat_id) if msg.chat_id else None,
|
chat_id=str(msg.chat_id) if msg.chat_id else None,
|
||||||
|
|||||||
@ -97,19 +97,13 @@ class ConnectionManager:
|
|||||||
message["project_id"] = project_id
|
message["project_id"] = project_id
|
||||||
|
|
||||||
raw_mentions = message.get("mentions", [])
|
raw_mentions = message.get("mentions", [])
|
||||||
# Extract member IDs from mentions (objects or strings)
|
# Extract member IDs from mentions
|
||||||
mention_ids: set[str] = set()
|
mention_ids: set[str] = set()
|
||||||
mention_slugs: set[str] = set()
|
|
||||||
for m in raw_mentions:
|
for m in raw_mentions:
|
||||||
if isinstance(m, dict):
|
if isinstance(m, dict):
|
||||||
if m.get("id"):
|
if m.get("id"):
|
||||||
mention_ids.add(m["id"])
|
mention_ids.add(m["id"])
|
||||||
if m.get("slug"):
|
|
||||||
mention_slugs.add(m["slug"])
|
|
||||||
elif isinstance(m, str):
|
|
||||||
mention_slugs.add(m)
|
|
||||||
|
|
||||||
content = message.get("content", "")
|
|
||||||
author_type = message.get("author_type", "")
|
author_type = message.get("author_type", "")
|
||||||
payload = {"type": event_type or WSEventType.MESSAGE_NEW, "data": message}
|
payload = {"type": event_type or WSEventType.MESSAGE_NEW, "data": message}
|
||||||
|
|
||||||
@ -132,21 +126,16 @@ class ConnectionManager:
|
|||||||
if client.chat_listen == ListenMode.NONE:
|
if client.chat_listen == ListenMode.NONE:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# System messages: only if agent is mentioned (by ID or slug for compat)
|
# System messages: only if agent is mentioned (by ID)
|
||||||
if author_type == AuthorType.SYSTEM:
|
if author_type == AuthorType.SYSTEM:
|
||||||
mentioned = (
|
if client.member_id not in mention_ids:
|
||||||
client.member_id in mention_ids or
|
|
||||||
client.member_slug in mention_slugs or
|
|
||||||
f"@{client.member_slug}" in content # text fallback for compat
|
|
||||||
)
|
|
||||||
if not mentioned:
|
|
||||||
continue
|
continue
|
||||||
await self.send_to_session(session_id, payload)
|
await self.send_to_session(session_id, payload)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Regular messages: chat_listen filter
|
# Regular messages: chat_listen filter
|
||||||
if client.chat_listen in (ListenMode.MENTIONS, ListenMode.ASSIGNED):
|
if client.chat_listen in (ListenMode.MENTIONS, ListenMode.ASSIGNED):
|
||||||
if client.member_id not in mention_ids and client.member_slug not in mention_slugs:
|
if client.member_id not in mention_ids:
|
||||||
continue
|
continue
|
||||||
await self.send_to_session(session_id, payload)
|
await self.send_to_session(session_id, payload)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user