feat: enhance contact access control; add tests for member viewing and updating foreign contacts
Test / test (push) Successful in 14s

This commit is contained in:
k1nq
2025-11-28 14:12:46 +05:00
parent 6db1e865f6
commit 472cb654d8
3 changed files with 143 additions and 11 deletions
-11
View File
@@ -60,7 +60,6 @@ class ContactRepository:
user_id: int,
) -> Contact | None:
stmt = select(Contact).where(Contact.id == contact_id, Contact.organization_id == organization_id)
stmt = self._apply_role_clause(stmt, role, user_id)
result = await self._session.scalars(stmt)
return result.first()
@@ -124,14 +123,4 @@ class ContactRepository:
if role == OrganizationRole.MEMBER:
raise ContactAccessError("Members cannot filter by owner")
stmt = stmt.where(Contact.owner_id == params.owner_id)
return self._apply_role_clause(stmt, role, user_id)
def _apply_role_clause(
self,
stmt: Select[tuple[Contact]],
role: OrganizationRole,
user_id: int,
) -> Select[tuple[Contact]]:
if role == OrganizationRole.MEMBER:
return stmt.where(Contact.owner_id == user_id)
return stmt